How to read from the scratchpad from Node-RED using Modbus

I was looking for a good simple way to read the scratchpad of a RIO through Node-RED. Searching the forums I found the following post:

Well the RIO doesn’t have a control engine, so I ended up using good old trusty Modbus with the node-red-contrib-modbus nodes. This would work with a PAC as well over the network, but you would need to use PAC Manager to lookup the Unit ID and address to use (or calculate it yourself).

Here is how I read a float value from the scratchpad using Node-RED:

In groov manage look up the Modbus Unit ID and Address for the 0th float element:

image

Unit ID is 110, address is 4096.

In Node-RED I dropped a Modbus-Read node on the flow and configured it as follows (Floats are 4 bytes so we need to read 2 16 bit registers):

image

The “Server” configuration node is setup as localhost and using the default port on the RIO for modbus which is 8502 (A PAC would be just 502 and the host would be the hostname or IP address of the PAC):

image

I left the other settings at the defaults.

Then using the 2nd output of the Modbus Read node which gives us access to the raw data, I linked to a function node with the following javascript:

const buf = Buffer.from(msg.payload.buffer);

msg.payload.float = buf.readFloatBE();

return msg;

Now msg.payload.float will have the value from the first float scratchpad element.

1 Like

…and yes, after doing this I realized that the groov IO nodes can read and write to generic mmp addresses - but still useful if you want to get data from a PAC scratchpad.