# daveReadBytes

Reads a sequence of bytes from PLC memory.

        int daveReadBytes(daveConnection * dc, int area, int DB, int start, int len, void * buffer);

### Parameters:

- dc: A pointer to a daveConnection structure representing an established connection.
- area: A constant that specifies a memory area in the PLC.
- DB: The number of a data block. Only meaningful if area is daveDB. Use 0 oterwise.
- start: The address of the first byte in the block.
- len: The number of bytes to read.
- buffer: A pointer to some memory space where you want the result to be copied too.

### Result:

The function returns 0 on success. Nonzero return codes may be passed to daveStrerror() to get a textual explanation of what happened. Generally, positive error codes represent errors reported by the PLC, while negative ones represent errors detected by LIBNODAVE, e.g. no response from the PLC.

### Hints:

#### len:

Note that timer, counters and the analog input/output words of the 200 family are allways words (2 bytes). To read n of them, you have to specify 2xn bytes as len.

#### buffer:

You may call daveReadBytes() without a buffer specifying NULL (C) or nil (Pascal). There is, however, an internal buffer that is part of the daveConnection structure. This internal buffer allways holds the result from the last read operation.

#### Maximum length:

The maximum size of a block in S7-Communication is limited by the size of a message structure calledPDU. Each call to daveReadBytes causes a the exchange of a request and a response PDU. The result data must fit into the "payload" area of a response PDU. This means a maximum block length is PDU size -18 bytes for read. A typical PDU size is 240 Byte, limiting read calls to 222 byte result length. If you need more data, you need to use multiple calls to daveReadBytes().

#### Efficiency:

Each call to daveReadBytes() causes a the exchange of a request and a response PDU together with prefixes, ackknowledges and what else the transport layer requires. Therefore you should try to read as much as possible in a single call. Example:

        daveReadBytes(dc, daveDB, 5, 68, 14, appBuffer);

reads DBD68 and DBD78 and everything in between and fills the range appBuffer+4 to appBuffer+9 with 6 unwanted bytes, but it is much faster than:

        daveReadBytes(dc, daveDB, 5, 68, 4, appBuffer);
        daveReadBytes(dc, daveDB, 5, 78, 4, appBuffer+4);