daveWriteBytes
Write a sequence of bytes from a buffer to PLC memory.
int daveWriteBytes(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.
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 daveWriteBytes() 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 daveWriteBytes() 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 write as much as possible in a single call. Example:
daveWriteBytes(dc, daveDB, 5, 68, 14, appBuffer);
writes DBD68 and DBD78 and everything in between from the range appBuffer+4 to appBuffer+9 with 6 unwanted bytes, but it is much faster than:
daveWriteBytes(dc, daveDB, 5, 68, 4, appBuffer);
daveWriteBytes(dc, daveDB, 5, 78, 4, appBuffer+4);