From b3480aa85869160aa5fe2eccc8a326b632831fe6 Mon Sep 17 00:00:00 2001 From: Edward Wall Date: Thu, 17 Apr 2025 11:02:47 +0200 Subject: [PATCH] reads current string length from SPS register --- devS7plcFW.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/devS7plcFW.c b/devS7plcFW.c index 6096460..d3060f0 100644 --- a/devS7plcFW.c +++ b/devS7plcFW.c @@ -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 */