added option "writeall" to write the whole buff to DB - needed for SINQ
This commit is contained in:
14
drvS7plcFW.c
14
drvS7plcFW.c
@ -136,6 +136,8 @@ struct s7plcFWStation {
|
||||
char *fetchBuffer, *writeBuffer;
|
||||
int swapBytes;
|
||||
float recvTimeout, recvDelay, outIOintDelay;
|
||||
|
||||
int writeAll; // flag, when != 0 then always write the whole buffer to DB (needed for SINQ)
|
||||
};
|
||||
|
||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||
@ -171,8 +173,8 @@ STATIC long s7plcFWIoReport(int level)
|
||||
printf(" NOT CONNECTED\n");
|
||||
}
|
||||
|
||||
printf(" WRITE: Port=%5d Org=%3d Db=%3d Offs=%5d Size=%5d buffer@%p (%5d bytes)",
|
||||
station->writePort, station->writeOrg, station->writeDb, station->writeOffs, station->writeSize, station->writeBuffer, station->writeSize);
|
||||
printf(" WRITE: Port=%5d Org=%3d Db=%3d Offs=%5d Size=%5d buffer@%p (%5d bytes) %s",
|
||||
station->writePort, station->writeOrg, station->writeDb, station->writeOffs, station->writeSize, station->writeBuffer, station->writeSize, (station->writeAll ? "" : "writeAll"));
|
||||
if (station->writeConnStatus) {
|
||||
printf(" CONNECTED (fd=%d)\n", station->writeSocket);
|
||||
}
|
||||
@ -248,6 +250,7 @@ int s7plcFWConfigure(char *name, char* IPaddr, char *fetchInfo, char *writeInfo,
|
||||
unsigned char fetchDb, writeDb;
|
||||
unsigned int fetchOffs, writeOffs;
|
||||
unsigned int fetchSize, writeSize;
|
||||
int writeAll;
|
||||
|
||||
if (!name) {
|
||||
errlogSevPrintf(errlogFatal, "s7plcFWConfigure: missing name\n");
|
||||
@ -268,6 +271,7 @@ int s7plcFWConfigure(char *name, char* IPaddr, char *fetchInfo, char *writeInfo,
|
||||
|
||||
extractPGDOS(fetchInfo, &fetchPort, &fetchOrg, &fetchDb, &fetchOffs, &fetchSize);
|
||||
extractPGDOS(writeInfo, &writePort, &writeOrg, &writeDb, &writeOffs, &writeSize);
|
||||
writeAll = 0; if (strstr(writeInfo, "writeall") != NULL) writeAll = 1; // write the whole buffer to DB
|
||||
|
||||
if ((fetchPort == 0) || (fetchOrg == 0) || (fetchDb == 0) || ((fetchOffs%2) != 0) || (fetchSize == 0) || ((fetchSize%2) != 0)) { /* size & offs: only even numbers */
|
||||
fetchPort = fetchOrg = fetchDb = fetchOffs = fetchSize = 0;
|
||||
@ -309,6 +313,7 @@ int s7plcFWConfigure(char *name, char* IPaddr, char *fetchInfo, char *writeInfo,
|
||||
station->writeOffs = writeOffs;
|
||||
station->fetchSize = fetchSize;
|
||||
station->writeSize = writeSize;
|
||||
station->writeAll = writeAll;
|
||||
|
||||
if (fetchSize > 0)
|
||||
station->fetchBuffer = callocMustSucceed(1, fetchSize, "s7plcFWConfigure");
|
||||
@ -810,7 +815,12 @@ int s7plcFWWriteMaskedArray(s7plcFWStation *station, unsigned int offset, unsign
|
||||
/* warning: we allways have to write even number of bytes - so it can happen that we have to write 1 or 2 bytes more than requested */
|
||||
woffs = offset & 0xFFFFFFFE; /* we need even byte offset */
|
||||
wlen = 0; if (woffs != offset) wlen += 1; wlen += nelem*dlen; if ((wlen % 2) != 0) wlen += 1;
|
||||
if (station->writeAll == 0) {
|
||||
wstatus = s7plcFWdoWrite(station, &station->writeBuffer[woffs], woffs, wlen);
|
||||
}
|
||||
else {
|
||||
wstatus = s7plcFWdoWrite(station, &station->writeBuffer[0], 0, station->writeSize);
|
||||
}
|
||||
if (wstatus != 0) {
|
||||
s7plcFWDebugLog(0, "s7plcFWWriteMaskedArray %s: s7plcFWdoWrite(%d, ...) failed\n", station->name, station->writeSocket);
|
||||
s7plcFWCloseConnection(station, FOR_WRITE);
|
||||
|
@ -123,6 +123,9 @@ containing the
|
||||
and
|
||||
<code>"writePort,writeOrg,writeDb,writeOffsetInDb,writeSizeOfDb"</code>.
|
||||
<br>
|
||||
For <code><i>writeInfo</i></code> you can add at the end of string an <code><i>writeall</i></code> option,
|
||||
to allways write the whole buffer to DB. This is needed for PLCs as used in SINQ.
|
||||
<br>
|
||||
fetchPort and writePort come in pairs. Usualy starting at 2000,2001.
|
||||
<br>
|
||||
Offsets and Sizes are in bytes and must be <code>even numbers</code>. Offset will usualy be zero, but one does not neccessarilly have to start at the beginning of Db. The size is number of bytes to fetch or write starting from given offset - it does not have to go to the end of Db and it should never exceed the size of Db.
|
||||
|
Reference in New Issue
Block a user