From 54e258db1ad11484372ddc1cf9c2cdd7e6ee667d Mon Sep 17 00:00:00 2001 From: Damir Anicic Date: Wed, 12 Feb 2020 08:53:12 +0100 Subject: [PATCH] added option "writeall" to write the whole buff to DB - needed for SINQ --- drvS7plcFW.c | 16 +++++++++++++--- s7plcFW.html | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/drvS7plcFW.c b/drvS7plcFW.c index e7a0c9c..16b52c2 100644 --- a/drvS7plcFW.c +++ b/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; - wstatus = s7plcFWdoWrite(station, &station->writeBuffer[woffs], woffs, wlen); + 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); diff --git a/s7plcFW.html b/s7plcFW.html index 83db703..1b0b470 100644 --- a/s7plcFW.html +++ b/s7plcFW.html @@ -123,6 +123,9 @@ containing the and "writePort,writeOrg,writeDb,writeOffsetInDb,writeSizeOfDb".
+For writeInfo you can add at the end of string an writeall option, +to allways write the whole buffer to DB. This is needed for PLCs as used in SINQ. +
fetchPort and writePort come in pairs. Usualy starting at 2000,2001.
Offsets and Sizes are in bytes and must be even numbers. 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.