4 Commits

4 changed files with 25 additions and 17 deletions

View File

@ -5,7 +5,3 @@ BUILDCLASSES+=Linux
DBDS += s7plcFWBase.dbd
DBDS_3.14 += s7plcFWCalcout.dbd
DBDS_3.14 += s7plcFWReg.dbd
EPICS_VERSIONS =
EPICS_VERSIONS += 3.14.8
EPICS_VERSIONS += 3.14.12

View File

@ -34,15 +34,14 @@
#include <stringoutRecord.h>
#include <waveformRecord.h>
#if ((EPICS_VERSION==3 && EPICS_REVISION>=14) || EPICS_VERSION>3)
/* R3.14 */
#ifdef BASE_VERSION
#define EPICS_3_13
#include "compat3_13.h"
#else
#include <postfix.h>
#include <calcoutRecord.h>
#include <cantProceed.h>
#include <epicsExport.h>
#else
/* R3.13 */
#include "compat3_13.h"
#endif
/* suppress compiler warning concerning long long with __extension__ */
@ -361,7 +360,7 @@ struct devsup s7plcFWWaveform =
epicsExportAddress(dset, s7plcFWWaveform);
/* calcout **********************************************************/
#if ((EPICS_VERSION==3 && EPICS_REVISION>=14) || EPICS_VERSION>3)
#ifndef EPICS_3_13
STATIC long s7plcFWInitRecordCalcout(calcoutRecord *);
STATIC long s7plcFWWriteCalcout(calcoutRecord *);
@ -1761,7 +1760,7 @@ STATIC long s7plcFWReadAi(aiRecord *record)
case epicsFloat64T:
status = s7plcFWRead(priv->station, priv->offs,
8, &val64);
__extension__ s7plcFWDebugLog(3, "ai %s: read 64bit %08Lx = %g\n",
__extension__ s7plcFWDebugLog(3, "ai %s: read 64bit " CONV64 " = %g\n",
record->name, val64.i, val64.f);
floatval = TRUE;
break;
@ -2025,7 +2024,7 @@ STATIC long s7plcFWInitRecordStringin(stringinRecord *record)
{
errlogSevPrintf(errlogMinor,
"%s: string size reduced from %d to %d\n",
record->name, priv->dlen, sizeof(record->val));
record->name, priv->dlen, (int)sizeof(record->val));
priv->dlen = sizeof(record->val);
}
record->dpvt = priv;
@ -2105,7 +2104,7 @@ STATIC long s7plcFWInitRecordStringout(stringoutRecord *record)
{
errlogSevPrintf(errlogMinor,
"%s: string size reduced from %d to %d\n",
record->name, priv->dlen, sizeof(record->val));
record->name, priv->dlen, (int)sizeof(record->val));
priv->dlen = sizeof(record->val);
}
record->dpvt = priv;
@ -2368,8 +2367,8 @@ STATIC long s7plcFWReadWaveform(waveformRecord *record)
return status;
}
#if (EPICS_REVISION>=14)
/* calcout **********************************************************/
#ifndef EPICS_3_13
STATIC long s7plcFWInitRecordCalcout(calcoutRecord *record)
{

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

View File

@ -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.