added option "writeall" to write the whole buff to DB - needed for SINQ

This commit is contained in:
2020-02-12 08:53:12 +01:00
parent 644c824604
commit 54e258db1a
2 changed files with 16 additions and 3 deletions

View File

@ -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);