Compare commits
8 Commits
S7PLCFW_1_
...
2.0.8
Author | SHA1 | Date | |
---|---|---|---|
8ae2aa7ecd | |||
7d4f57750b | |||
54e258db1a | |||
644c824604 | |||
a470205454 | |||
59511616ae | |||
46bf87c99c | |||
9ea778a101 |
9
Makefile
9
Makefile
@ -1,11 +1,12 @@
|
|||||||
include /ioc/tools/driver.makefile
|
include /ioc/tools/driver.makefile
|
||||||
|
|
||||||
BUILDCLASSES+=Linux
|
MODULE=sinqS7plcFW
|
||||||
|
BUILDCLASSES=Linux
|
||||||
|
EPICS_VERSIONS=7.0.7
|
||||||
|
ARCH_FILTER=RHEL%
|
||||||
|
|
||||||
DBDS += s7plcFWBase.dbd
|
DBDS += s7plcFWBase.dbd
|
||||||
DBDS_3.14 += s7plcFWCalcout.dbd
|
DBDS_3.14 += s7plcFWCalcout.dbd
|
||||||
DBDS_3.14 += s7plcFWReg.dbd
|
DBDS_3.14 += s7plcFWReg.dbd
|
||||||
|
|
||||||
EPICS_VERSIONS =
|
USR_CFLAGS += -Wall -Wextra -Wunused-result
|
||||||
EPICS_VERSIONS += 3.14.8
|
|
||||||
EPICS_VERSIONS += 3.14.12
|
|
||||||
|
13
README.md
Normal file
13
README.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# SinqS7PLCFW
|
||||||
|
|
||||||
|
This is a fork of Dirk Zimoch's [epics\_driver\_modules/s7plcFW](https://git.psi.ch/epics_driver_modules/s7plcFW), with the following adjustments:
|
||||||
|
|
||||||
|
* The String offset, now takes the two prefix bytes (max string length, current
|
||||||
|
string length) into account, so you don't have to add 2 to each offset in
|
||||||
|
order for the driver to read the correct string
|
||||||
|
* The length of a String read from the SPS and written to the Val field of a
|
||||||
|
stringin record is no longer static, but instead read from the SPS directly,
|
||||||
|
to avoid having bytes leftover in the buffer from a previous string.
|
||||||
|
* The Makefile has been slightly adjusted, limiting the build targets.
|
||||||
|
|
||||||
|
The default driver behaviour is documented in the file [s7plcFW.html](./s7plcFW.html).
|
36
devS7plcFW.c
36
devS7plcFW.c
@ -34,15 +34,14 @@
|
|||||||
#include <stringoutRecord.h>
|
#include <stringoutRecord.h>
|
||||||
#include <waveformRecord.h>
|
#include <waveformRecord.h>
|
||||||
|
|
||||||
#if ((EPICS_VERSION==3 && EPICS_REVISION>=14) || EPICS_VERSION>3)
|
#ifdef BASE_VERSION
|
||||||
/* R3.14 */
|
#define EPICS_3_13
|
||||||
|
#include "compat3_13.h"
|
||||||
|
#else
|
||||||
#include <postfix.h>
|
#include <postfix.h>
|
||||||
#include <calcoutRecord.h>
|
#include <calcoutRecord.h>
|
||||||
#include <cantProceed.h>
|
#include <cantProceed.h>
|
||||||
#include <epicsExport.h>
|
#include <epicsExport.h>
|
||||||
#else
|
|
||||||
/* R3.13 */
|
|
||||||
#include "compat3_13.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* suppress compiler warning concerning long long with __extension__ */
|
/* suppress compiler warning concerning long long with __extension__ */
|
||||||
@ -361,7 +360,7 @@ struct devsup s7plcFWWaveform =
|
|||||||
epicsExportAddress(dset, s7plcFWWaveform);
|
epicsExportAddress(dset, s7plcFWWaveform);
|
||||||
|
|
||||||
/* calcout **********************************************************/
|
/* calcout **********************************************************/
|
||||||
#if ((EPICS_VERSION==3 && EPICS_REVISION>=14) || EPICS_VERSION>3)
|
#ifndef EPICS_3_13
|
||||||
|
|
||||||
STATIC long s7plcFWInitRecordCalcout(calcoutRecord *);
|
STATIC long s7plcFWInitRecordCalcout(calcoutRecord *);
|
||||||
STATIC long s7plcFWWriteCalcout(calcoutRecord *);
|
STATIC long s7plcFWWriteCalcout(calcoutRecord *);
|
||||||
@ -1761,7 +1760,7 @@ STATIC long s7plcFWReadAi(aiRecord *record)
|
|||||||
case epicsFloat64T:
|
case epicsFloat64T:
|
||||||
status = s7plcFWRead(priv->station, priv->offs,
|
status = s7plcFWRead(priv->station, priv->offs,
|
||||||
8, &val64);
|
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);
|
record->name, val64.i, val64.f);
|
||||||
floatval = TRUE;
|
floatval = TRUE;
|
||||||
break;
|
break;
|
||||||
@ -2025,7 +2024,7 @@ STATIC long s7plcFWInitRecordStringin(stringinRecord *record)
|
|||||||
{
|
{
|
||||||
errlogSevPrintf(errlogMinor,
|
errlogSevPrintf(errlogMinor,
|
||||||
"%s: string size reduced from %d to %d\n",
|
"%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);
|
priv->dlen = sizeof(record->val);
|
||||||
}
|
}
|
||||||
record->dpvt = priv;
|
record->dpvt = priv;
|
||||||
@ -2034,7 +2033,11 @@ STATIC long s7plcFWInitRecordStringin(stringinRecord *record)
|
|||||||
|
|
||||||
STATIC long s7plcFWReadStringin(stringinRecord *record)
|
STATIC long s7plcFWReadStringin(stringinRecord *record)
|
||||||
{
|
{
|
||||||
|
// The SPS includes the max length of the string and the length of the
|
||||||
|
// current string, as the first two bytes in the register.
|
||||||
|
|
||||||
int status;
|
int status;
|
||||||
|
epicsUInt8 uval8;
|
||||||
S7memPrivate_t *priv = (S7memPrivate_t *)record->dpvt;
|
S7memPrivate_t *priv = (S7memPrivate_t *)record->dpvt;
|
||||||
|
|
||||||
if (!priv)
|
if (!priv)
|
||||||
@ -2045,11 +2048,18 @@ STATIC long s7plcFWReadStringin(stringinRecord *record)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
assert(priv->station);
|
assert(priv->station);
|
||||||
|
|
||||||
|
status = s7plcFWRead(priv->station, priv->offs+1,
|
||||||
|
1, &uval8);
|
||||||
|
s7plcFWDebugLog(3, "stringin %s: read 8bit %02x\n",
|
||||||
|
record->name, uval8);
|
||||||
|
uval8 = uval8 <= priv->dlen ? uval8 : priv->dlen;
|
||||||
|
|
||||||
memset(record->val, 0, priv->dlen);
|
memset(record->val, 0, priv->dlen);
|
||||||
status = s7plcFWReadArray(priv->station, priv->offs,
|
status = s7plcFWReadArray(priv->station, priv->offs+2,
|
||||||
1, priv->dlen, record->val);
|
1, uval8, record->val);
|
||||||
s7plcFWDebugLog(3, "stringin %s: read array of %d 8bit values\n",
|
s7plcFWDebugLog(3, "stringin %s: read array of %d 8bit values\n",
|
||||||
record->name, priv->dlen);
|
record->name, uval8);
|
||||||
if (record->val[priv->dlen] && !memchr(record->val, 0, priv->dlen))
|
if (record->val[priv->dlen] && !memchr(record->val, 0, priv->dlen))
|
||||||
{
|
{
|
||||||
/* truncate oversize string */
|
/* truncate oversize string */
|
||||||
@ -2105,7 +2115,7 @@ STATIC long s7plcFWInitRecordStringout(stringoutRecord *record)
|
|||||||
{
|
{
|
||||||
errlogSevPrintf(errlogMinor,
|
errlogSevPrintf(errlogMinor,
|
||||||
"%s: string size reduced from %d to %d\n",
|
"%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);
|
priv->dlen = sizeof(record->val);
|
||||||
}
|
}
|
||||||
record->dpvt = priv;
|
record->dpvt = priv;
|
||||||
@ -2368,8 +2378,8 @@ STATIC long s7plcFWReadWaveform(waveformRecord *record)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (EPICS_REVISION>=14)
|
|
||||||
/* calcout **********************************************************/
|
/* calcout **********************************************************/
|
||||||
|
#ifndef EPICS_3_13
|
||||||
|
|
||||||
STATIC long s7plcFWInitRecordCalcout(calcoutRecord *record)
|
STATIC long s7plcFWInitRecordCalcout(calcoutRecord *record)
|
||||||
{
|
{
|
||||||
|
33
drvS7plcFW.c
33
drvS7plcFW.c
@ -1,7 +1,7 @@
|
|||||||
/* $Date: 2012/12/05 08:49:08 $ */
|
/* $Date: 2013/07/11 12:43:21 $ */
|
||||||
/* $Id: drvS7plcFW.c,v 1.4 2012/12/05 08:49:08 anicic Exp $ */
|
/* $Id: drvS7plcFW.c,v 1.6 2013/07/11 12:43:21 anicic Exp $ */
|
||||||
/* $Name: $ */
|
/* $Name: $ */
|
||||||
/* $Revision: 1.4 $ */
|
/* $Revision: 1.6 $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE: s7plcFWwriteThread -is not used for writting (we write direct),
|
* NOTE: s7plcFWwriteThread -is not used for writting (we write direct),
|
||||||
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
#include "drvS7plcFW.h"
|
#include "drvS7plcFW.h"
|
||||||
|
|
||||||
#if ((EPICS_VERSION==3 && EPICS_REVISION>=14) || EPICS_VERSION>3)
|
#ifndef BASE_VERSION
|
||||||
/* R3.14 */
|
/* R3.14 */
|
||||||
#include <dbAccess.h>
|
#include <dbAccess.h>
|
||||||
#include <iocsh.h>
|
#include <iocsh.h>
|
||||||
@ -52,6 +52,7 @@
|
|||||||
#include <epicsExport.h>
|
#include <epicsExport.h>
|
||||||
#else
|
#else
|
||||||
/* R3.13 */
|
/* R3.13 */
|
||||||
|
#define EPICS_3_13
|
||||||
#include "compat3_13.h"
|
#include "compat3_13.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -69,7 +70,7 @@
|
|||||||
#define RECONNECT_DELAY 10.0 /* delay before reconnect [s] */
|
#define RECONNECT_DELAY 10.0 /* delay before reconnect [s] */
|
||||||
|
|
||||||
static char cvsid[] __attribute__((unused)) =
|
static char cvsid[] __attribute__((unused)) =
|
||||||
"$Id: drvS7plcFW.c,v 1.4 2012/12/05 08:49:08 anicic Exp $";
|
"$Id: drvS7plcFW.c,v 1.6 2013/07/11 12:43:21 anicic Exp $";
|
||||||
|
|
||||||
STATIC long s7plcFWIoReport(int level);
|
STATIC long s7plcFWIoReport(int level);
|
||||||
STATIC long s7plcFWInit();
|
STATIC long s7plcFWInit();
|
||||||
@ -136,6 +137,8 @@ struct s7plcFWStation {
|
|||||||
char *fetchBuffer, *writeBuffer;
|
char *fetchBuffer, *writeBuffer;
|
||||||
int swapBytes;
|
int swapBytes;
|
||||||
float recvTimeout, recvDelay, outIOintDelay;
|
float recvTimeout, recvDelay, outIOintDelay;
|
||||||
|
|
||||||
|
int writeAll; // flag, when != 0 then always write the whole buffer to DB (needed for SINQ)
|
||||||
};
|
};
|
||||||
|
|
||||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||||
@ -171,8 +174,8 @@ STATIC long s7plcFWIoReport(int level)
|
|||||||
printf(" NOT CONNECTED\n");
|
printf(" NOT CONNECTED\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(" WRITE: Port=%5d Org=%3d Db=%3d Offs=%5d Size=%5d buffer@%p (%5d bytes)",
|
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->writePort, station->writeOrg, station->writeDb, station->writeOffs, station->writeSize, station->writeBuffer, station->writeSize, (station->writeAll ? "" : "writeAll"));
|
||||||
if (station->writeConnStatus) {
|
if (station->writeConnStatus) {
|
||||||
printf(" CONNECTED (fd=%d)\n", station->writeSocket);
|
printf(" CONNECTED (fd=%d)\n", station->writeSocket);
|
||||||
}
|
}
|
||||||
@ -248,6 +251,7 @@ int s7plcFWConfigure(char *name, char* IPaddr, char *fetchInfo, char *writeInfo,
|
|||||||
unsigned char fetchDb, writeDb;
|
unsigned char fetchDb, writeDb;
|
||||||
unsigned int fetchOffs, writeOffs;
|
unsigned int fetchOffs, writeOffs;
|
||||||
unsigned int fetchSize, writeSize;
|
unsigned int fetchSize, writeSize;
|
||||||
|
int writeAll;
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
errlogSevPrintf(errlogFatal, "s7plcFWConfigure: missing name\n");
|
errlogSevPrintf(errlogFatal, "s7plcFWConfigure: missing name\n");
|
||||||
@ -268,6 +272,7 @@ int s7plcFWConfigure(char *name, char* IPaddr, char *fetchInfo, char *writeInfo,
|
|||||||
|
|
||||||
extractPGDOS(fetchInfo, &fetchPort, &fetchOrg, &fetchDb, &fetchOffs, &fetchSize);
|
extractPGDOS(fetchInfo, &fetchPort, &fetchOrg, &fetchDb, &fetchOffs, &fetchSize);
|
||||||
extractPGDOS(writeInfo, &writePort, &writeOrg, &writeDb, &writeOffs, &writeSize);
|
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 */
|
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;
|
fetchPort = fetchOrg = fetchDb = fetchOffs = fetchSize = 0;
|
||||||
@ -309,6 +314,7 @@ int s7plcFWConfigure(char *name, char* IPaddr, char *fetchInfo, char *writeInfo,
|
|||||||
station->writeOffs = writeOffs;
|
station->writeOffs = writeOffs;
|
||||||
station->fetchSize = fetchSize;
|
station->fetchSize = fetchSize;
|
||||||
station->writeSize = writeSize;
|
station->writeSize = writeSize;
|
||||||
|
station->writeAll = writeAll;
|
||||||
|
|
||||||
if (fetchSize > 0)
|
if (fetchSize > 0)
|
||||||
station->fetchBuffer = callocMustSucceed(1, fetchSize, "s7plcFWConfigure");
|
station->fetchBuffer = callocMustSucceed(1, fetchSize, "s7plcFWConfigure");
|
||||||
@ -365,7 +371,7 @@ int s7plcFWConfigure(char *name, char* IPaddr, char *fetchInfo, char *writeInfo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
||||||
#if (EPICS_REVISION>=14)
|
#ifndef EPICS_3_13
|
||||||
static const iocshArg s7plcFWConfigureArg0 = { "name", iocshArgString };
|
static const iocshArg s7plcFWConfigureArg0 = { "name", iocshArgString };
|
||||||
static const iocshArg s7plcFWConfigureArg1 = { "IPaddr", iocshArgString };
|
static const iocshArg s7plcFWConfigureArg1 = { "IPaddr", iocshArgString };
|
||||||
static const iocshArg s7plcFWConfigureArg2 = { "fetchInfo", iocshArgString };
|
static const iocshArg s7plcFWConfigureArg2 = { "fetchInfo", iocshArgString };
|
||||||
@ -389,11 +395,9 @@ static const iocshArg * const s7plcFWConfigureArgs[] = {
|
|||||||
static const iocshFuncDef s7plcFWConfigureDef = { "s7plcFWConfigure", 8, s7plcFWConfigureArgs };
|
static const iocshFuncDef s7plcFWConfigureDef = { "s7plcFWConfigure", 8, s7plcFWConfigureArgs };
|
||||||
static void s7plcFWConfigureFunc (const iocshArgBuf *args)
|
static void s7plcFWConfigureFunc (const iocshArgBuf *args)
|
||||||
{
|
{
|
||||||
int status = s7plcFWConfigure(
|
(void) s7plcFWConfigure(
|
||||||
args[0].sval, args[1].sval, args[2].sval, args[3].sval,
|
args[0].sval, args[1].sval, args[2].sval, args[3].sval,
|
||||||
args[4].ival, args[5].ival, args[6].ival, args[7].ival);
|
args[4].ival, args[5].ival, args[6].ival, args[7].ival);
|
||||||
|
|
||||||
if (status) exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void s7plcFWRegister ()
|
static void s7plcFWRegister ()
|
||||||
@ -812,7 +816,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 */
|
/* 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 */
|
woffs = offset & 0xFFFFFFFE; /* we need even byte offset */
|
||||||
wlen = 0; if (woffs != offset) wlen += 1; wlen += nelem*dlen; if ((wlen % 2) != 0) wlen += 1;
|
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) {
|
if (wstatus != 0) {
|
||||||
s7plcFWDebugLog(0, "s7plcFWWriteMaskedArray %s: s7plcFWdoWrite(%d, ...) failed\n", station->name, station->writeSocket);
|
s7plcFWDebugLog(0, "s7plcFWWriteMaskedArray %s: s7plcFWdoWrite(%d, ...) failed\n", station->name, station->writeSocket);
|
||||||
s7plcFWCloseConnection(station, FOR_WRITE);
|
s7plcFWCloseConnection(station, FOR_WRITE);
|
||||||
|
@ -123,6 +123,9 @@ containing the
|
|||||||
and
|
and
|
||||||
<code>"writePort,writeOrg,writeDb,writeOffsetInDb,writeSizeOfDb"</code>.
|
<code>"writePort,writeOrg,writeDb,writeOffsetInDb,writeSizeOfDb"</code>.
|
||||||
<br>
|
<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.
|
fetchPort and writePort come in pairs. Usualy starting at 2000,2001.
|
||||||
<br>
|
<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.
|
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