article

Dirk-Jan Faber (Victron Energy) avatar image
Dirk-Jan Faber (Victron Energy) posted

Node-RED: Setting up Modbus communication to an external device

Yesterday my colleague Lucian asked me if I could help him out with controlling a frequency converter via Node-RED. It was a BDI50 that could talk Modbus over an USB to serial cable. Lucian already managed to talk to the device when connecting it to his windows pc. So we were sure that the setup ought to work.
Getting this to work from a Cerbo GX running Node-RED proved a bit more difficult then expected. And describing where we bumped into and how we managed to solve the issues might help others. Hence this article.

bdi50-200.jpgFor too long time we overlooked the fact that any serial device that gets plugged into a GX device gets claimed by the serial-starter process. Normally Venus OS wants to talk to any devices that get plugged into it, so first and most important task was to make sure that the device was not claimed. How to do that is described on https://github.com/victronenergy/venus/wiki/howto-add-a-driver-to-Venus#howto-make-serial-starter-ignore-certain-usb-types.

After reading those instructions, it turned out that the cable is just another ftdi cable and therefor cannot be easily uniquely identified. This was solved by using the FTProg utility that allows changing the product description. When that was done, the device model became FreqencyConverter, which is definitely unique because of the typo. :)
image.pngThen the following line could to be added to /etc/udev/rules.d/serial-starter.rules:

ACTION==“add”, ENV{ID_BUS}==“usb”, ENV{ID_MODEL}==“FreqencyConverter”, ENV{VE_SERVICE}=“ignore”

Note that adjusting the file does require ssh access to the device, which is described here: https://www.victronenergy.com/live/ccgx:root_access.
After that had been done, reading and writing to the device from Node-RED was not that hard anymore. From the palette manager, the node-red-contrib-modbus nodes needed to be installed.

Then the Modbus client connection needed to be configured. It is important to get all of these settings correct. In this case they could be configured on the BDI50 device. In other cases the settings should be in the manual of the device.
pasted-graphic.pngReading the correct register could then be done with the Modbus read node:

pasted-graphic-1.pngResulting in the following flow:

pasted-graphic-2.pngThe filter is just there to pass through only changed values.


4 files

Modbus TCPNode-REDserialftdi
image.png (54.9 KiB)
pasted-graphic.png (176.0 KiB)
pasted-graphic-1.png (121.8 KiB)
bdi50-200.jpg (19.8 KiB)
1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

hominidae avatar image hominidae commented ·

this "problem" with (too many or conflicting) serial connections is the reason, I deploy RS485_to_modbus-tcp converters mostly (only the GX itsself is not enabled enough to use these interfaces in a flexible way, but luckily Node-Red is).


0 Likes 0 ·

Article

Contributors

dfaber contributed to this article