Modbus serial with Node-RED

This provides a simple example of using the Rio to read Modbus data using serial Modbus RTU.

OVERVIEW

The Modbus device is connected to the Rio USB port through a RS232 to USB Adapter. A small NodeRed flow reads the Modbus registers.
image

USB

The RS232 to USB Adapter is a Belkin Model: F5U409.

The Rio is good at recognizing various USB adapters, so this specific model is probably not necessary. Here are a few others: RS232 and RS485 SERIAL ADAPTERS FOR RIO
Gearmo Model: GM-FTDI-A12
Sabrent USB to Serial converter
Aluratek Model: AUS100

Verify the adapter is recognized by the Rio using groovManage: System, then Serial Devices.

You should show a serial device similar to below. The device name displayed, /dev/ttySer0 , will be entered into Nodered as a serial device.
image
NODERED

Using Nodered Manage Palette, install the node-red-contrib-serial-modbus node.

Place a modbusSerialIN node and a debug node of the flow and connect them.
image

Double click the Modbus node, and click the pencil icon next to the Port setting, to add a serial device.

Enter the properties for the serial device and click Update.
image

Enter the Modbus register settings into the Modbus node. This example reads the first 3 holding registers. Click Done.
image

Click Deploy to send the flow to the Rio. Click the Debug Messages Icon to see the output of the Modbus node, which shows the holding register values.
image

Here is the NodeRed Flow.

[{"id":"a11d31ab.f68ac","type":"tab","label":"Modbus Serial","disabled":false,"info":""},{"id":"f509d4a.9024528","type":"modbusSerial in","z":"a11d31ab.f68ac","port":"3e468e22.842a02","slaves":"1","start":"1","count":"3","dtype":"holding","period":"10","topic":"","name":"Read Holding Regs 1-3","x":200,"y":200,"wires":[["aeb3845a.ae6e38"]]},{"id":"aeb3845a.ae6e38","type":"debug","z":"a11d31ab.f68ac","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":410,"y":200,"wires":[]},{"id":"3e468e22.842a02","type":"modbusSerialConfig","z":"","port":"/dev/ttySer0","baud":"19200","data":"8","parity":"none","stop":"1","name":""}]

MODBUS SLAVE SIMULATOR

I cheated a bit since I did not have a real Modbus Serial RTU device available.

A utility called Simply Modbus Slave was used on the PC to simulate the Modbus device.
image

MODBUS SERIAL ON RIO WITH NODERED.zip (180.3 KB)

4 Likes

Nice Post! Thanks for all the good info.

Great information on getting the Modbus data into Node-Red. In my case, when I used a Modbus scanner like CAS Modbus Scanner, I got the following:


which correctly showed the value I was after (1143).
However, when I read the same data in Node-RED using the method outlined above, I got the following:

I have since learned that (for my particular device, which is an atmosphere controller) Node-Red is outputting as 16 bit registers, but the debug is showing each byte as decimal. So the first number has ms byte 4 and ls byte 119, which is 4*256 + 119 = 1143 which is exactly what was expected. This node will help do the conversion.

1 Like