node-red-contrib-modbus-serial

1,790 views
Skip to first unread message

Leif Neland

unread,
Mar 31, 2017, 6:50:21 PM3/31/17
to Node-RED
I want to read 4 bytes at register 0x011e on device 0x0 on a usb->rs485 half duplex.

How do I set modbus-serial to do that?

The raw bytes to send is 0A 03 01 1E 00 02 A4 8A

dmesg:
[31228.140700] usb 1-1.2.2.3: new full-speed USB device number 16 using dwc_otg
[31228.245330] usb 1-1.2.2.3: New USB device found, idVendor=1a86, idProduct=7523
[31228.245372] usb 1-1.2.2.3: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[31228.245398] usb 1-1.2.2.3: Product: USB2.0-Serial
[31228.261504] ch341 1-1.2.2.3:1.0: ch341-uart converter detected
[31228.286254] usb 1-1.2.2.3: ch341-uart converter now attached to ttyUSB1



Leif Neland

unread,
Apr 1, 2017, 6:38:25 AM4/1/17
to Node-RED
I attatched a 2nd rs485 adapter to my pc, and saw that I could send data with the serial-out node. But I really wanted to use the modbus serial, so I didn't have to re-invent the wheel.

But modbus-serial-in does not send commands to the bus to poll for data at all!
How do I start debugging?
Do I add code to the js to write to log or console?

Mark Setrem

unread,
Apr 1, 2017, 7:02:24 AM4/1/17
to Node-RED
If you are having problems with a node-red-contrib- node , you might be better raising an issue on the nodes GitHub page, as the author won't necessarily be active in the group.

Leif Neland

unread,
Apr 1, 2017, 1:28:29 PM4/1/17
to Node-RED
Problem is that serial data is sent with parity:none although parity:even is specified in setup.

Leif Neland

unread,
Apr 2, 2017, 8:43:02 PM4/2/17
to Node-RED
Bugger. I used several hours of CPU-timeto download,patch, build and install what I thought was the latest kernel source 4.9.19, only to later be toldthat the patch was already in 4.10.x

Csongor Varga

unread,
Apr 9, 2017, 5:01:28 PM4/9/17
to Node-RED
I just started using node-red-contrib-modbus as well. I also want to read a power meter. I added a Modbus Read to get voltage from the meter. It seem to have worked, and I started playing around to see what Getter and Flex getter does. Now I put the original read back, and when I deploy the code the status of the Modbus read box is waiting and nothing happens.

Is this something with my serial port? Is it not released or something? I even restarted node-red, but with no affect.

Any advice will be appreciated.
Csongor

Leif Neland

unread,
Apr 12, 2017, 1:12:25 PM4/12/17
to Node-RED
I got the modbus serial node to work, and didn't bother to try the newer and more complex modbus node.

I bought an extra rs485-usb adapter (actually I bought 3, the postage was almost more than the adapter), so I could connect my laptop to the bus to monitor the traffic. Without I'd never discover that the driver was not respecting the even parity settings.

If you do the same, it will be easier to debug what's actually happening on the bus.

Joseph Martine

unread,
Apr 20, 2017, 6:09:16 PM4/20/17
to Node-RED
@Leif Neland 
Mind sharing the the write and server nodes in a flow?  I have been beating my head against this same issue for weeks now.  I have the TCP working like a champ, but cannot get Flex Write to be happy  This is what I have going on for the serial part.  I have a USB to RS485 gongle ( https://www.amazon.com/gp/product/B01LCFRR3E/ref=oh_aui_detailpage_o05_s00?ie=UTF8&psc=1 ) and I am getting a ping onthe TX light on the dongle every second from the temperature value that is inbound over the link input.  One other thing is I am only using ModBus to make the temperature value available to MODBUS RS485  NR is not getting any inbound traffic for writes or anything.  Last thing where did you see the parity mis-match?  And are you using anything like MODBUS Master?  I have found it to be quite useful.

[
    {
        "id": "469823bb.8dbd9c",
        "type": "modbus-flex-write",
        "z": "950e1863.7ddc98",
        "name": "",
        "showStatusActivities": true,
        "showErrors": true,
        "server": "7142743e.1c9bec",
        "x": 715,
        "y": 362,
        "wires": [
            [
                "ed464d4f.a0814"
            ],
            [
                "48970aa.d58c9f4"
            ]
        ]
    },
    {
        "id": "48970aa.d58c9f4",
        "type": "modbus-response",
        "z": "950e1863.7ddc98",
        "name": "",
        "registerShowMax": 20,
        "x": 1052,
        "y": 379,
        "wires": []
    },
    {
        "id": "ae964da3.297a8",
        "type": "function",
        "z": "950e1863.7ddc98",
        "name": "Write 10 on Unit 1 FC6",
        "func": "msg.payload = { value: msg.payload, 'fc': 6, 'unitid': 5, 'address': 1 , 'quantity': 2};\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 442,
        "y": 397,
        "wires": [
            [
                "469823bb.8dbd9c",
                "6b7c6a30.5324c4"
            ]
        ]
    },
    {
        "id": "3610f6a2.1fd60a",
        "type": "inject",
        "z": "950e1863.7ddc98",
        "name": "Write single!",
        "topic": "",
        "payload": "2345",
        "payloadType": "num",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 150,
        "y": 351,
        "wires": [
            [
                "ae964da3.297a8"
            ]
        ]
    },
    {
        "id": "ed464d4f.a0814",
        "type": "debug",
        "z": "950e1863.7ddc98",
        "name": "",
        "active": true,
        "console": "true",
        "complete": "payload",
        "x": 1042,
        "y": 339,
        "wires": []
    },
    {
        "id": "83938b43.4e1998",
        "type": "function",
        "z": "950e1863.7ddc98",
        "name": "reset Write on HighHigh",
        "func": "if(\"high high level reached\" === msg.state && \n    msg.unitid === 1 &&\n    msg.error.source.name === \"Write Queue\") {\n    msg.resetQueue = true;\n    return msg;\n}\n",
        "outputs": 1,
        "noerr": 0,
        "x": 450,
        "y": 300,
        "wires": [
            [
                "e6261b83.c46558"
            ]
        ]
    },
    {
        "id": "bc40e553.775cd8",
        "type": "link in",
        "z": "950e1863.7ddc98",
        "name": "MODBUS",
        "links": [
            "d77f8cbe.9b68a"
        ],
        "x": 176,
        "y": 410,
        "wires": [
            [
                "ae964da3.297a8"
            ]
        ]
    },
    {
        "id": "6b7c6a30.5324c4",
        "type": "modbus-flex-write",
        "z": "950e1863.7ddc98",
        "name": "TCP Flex Write",
        "showStatusActivities": true,
        "showErrors": true,
        "server": "6e35ce16.4be38",
        "x": 706,
        "y": 440,
        "wires": [
            [],
            [
                "bcd54f1a.a4a23"
            ]
        ]
    },
    {
        "id": "bcd54f1a.a4a23",
        "type": "modbus-response",
        "z": "950e1863.7ddc98",
        "name": "",
        "registerShowMax": 20,
        "x": 1016,
        "y": 450,
        "wires": []
    },
    {
        "id": "7142743e.1c9bec",
        "type": "modbus-client",
        "z": "",
        "name": "Serial RTU",
        "clienttype": "serial",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "tcpHost": "127.0.0.1",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB0",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "7",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "unit_id": "5",
        "commandDelay": "1",
        "clientTimeout": "1000",
        "reconnectTimeout": "2000"
    },
    {
        "id": "6e35ce16.4be38",
        "type": "modbus-client",
        "z": "",
        "name": "Local Write VServer",
        "clienttype": "tcp",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "tcpHost": "127.0.0.1",
        "tcpPort": "10502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB",
        "serialType": "RTU-BUFFERD",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "none",
        "serialConnectionDelay": "100",
        "unit_id": 1,
        "commandDelay": 1,
        "clientTimeout": 1000,
        "reconnectTimeout": 2000
    }
]


Csongor Varga

unread,
Apr 22, 2017, 4:45:17 AM4/22/17
to Node-RED
Hi Joseph,

I always make stupid mistakes, but in your first function node in the left you put the object names in quotes:
msg.payload = { value: msg.payload, 'fc': 6, 'unitid': 5, 'address': 1 , 'quantity': 2};
That should be
msg.payload = { value: msg.payload, fc: 6, unitid: 5, address: 1 , quantity: 2};
Right?

Did you have any issues with the serial port itself? I am trying to read data an SDM120 single phase energy meter and my Modbus read is just showing waiting state all the time.

Regards,
Csongor
Reply all
Reply to author
Forward
0 new messages