reads current string length from SPS register

This commit is contained in:
2025-04-17 11:02:47 +02:00
parent 7d4f57750b
commit b3480aa858

View File

@ -2033,7 +2033,11 @@ STATIC long s7plcFWInitRecordStringin(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;
epicsUInt8 uval8;
S7memPrivate_t *priv = (S7memPrivate_t *)record->dpvt;
if (!priv)
@ -2044,11 +2048,18 @@ STATIC long s7plcFWReadStringin(stringinRecord *record)
return -1;
}
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);
status = s7plcFWReadArray(priv->station, priv->offs,
1, priv->dlen, record->val);
status = s7plcFWReadArray(priv->station, priv->offs+2,
1, uval8, record->val);
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))
{
/* truncate oversize string */