node-modbus-serial icon indicating copy to clipboard operation
node-modbus-serial copied to clipboard

modicon strict sizing make IEEE supporting variants fail

Open greggwon opened this issue 5 years ago • 1 comments

in index,js around line 350 are the following two blocks of code which I have altered as shown. In some devices with floating point numbers, rather than doubling the number of registers requested to get 32-bit floating point values, the devices actually return double the number of registers requested. The code below tries really hard to make it necessary for the number of bytes in data returned to always be 2x the number of registers requested. To support devices which use a variant of modbus to support IEEE register values, can we just change the if to require at least 2x as coded here?

           /* check message length
             * if we do not expect this data
             * raise an error
             */
            if (!transaction.lengthUnknown && data.length < transaction.nextLength) {
                error = "Data length error, expected " +
                    transaction.nextLength + " got " + data.length;
                if (transaction.next)
                    transaction.next(new Error(error));
                return;
            }

Additionally, the APIs accept string valued addresses and such without demanding type equality. So, can we just change the !== in this if() use to != so that types are not demanded to be equal, since the other APIs are not making it necessary?

            /* check message address and code
             * if we do not expect this message
             * raise an error
             */
            if (address != transaction.nextAddress || code != transaction.nextCode) {
                error = "Unexpected data error, expected address " +
                    transaction.nextAddress + " got " + address +", code "+
                    transaction.nextCode + " got " + code;
                if (transaction.next)
                    transaction.next(new Error(error));
                return;
            }

greggwon avatar Aug 18 '20 18:08 greggwon

Thanks !

Can you make a pull request with the changes ?

yaacov avatar Aug 19 '20 04:08 yaacov