thingsboard / thingsboard-gateway

Open-source IoT Gateway - integrates devices connected to legacy and third-party systems with ThingsBoard IoT Platform using Modbus, CAN bus, BACnet, BLE, OPC-UA, MQTT, ODBC and REST protocols
https://thingsboard.io/docs/iot-gateway/what-is-iot-gateway/
Apache License 2.0
1.72k stars 829 forks source link

[HELP]using code 5 to write modbus single coil is always on #484

Closed minivv closed 3 years ago

minivv commented 3 years ago

Describe the issue To write a Modbus single coil, how do you configure modbus.json and what is the data format of the RPC node? Hope to get your guidance.

I can successfully write single hold register with RPC node and modbus.json

Configuration (Attach your configuration file) Here is the configuration for successfully writing a single hold register RPC script conversion node and modbus.json

var request = {};
request.method = "writeSingleRegister";
request.params = 10;
return {msg: request, metadata: metadata, msgType: msgType};
"rpc": [
          {
            "tag": "writeSingleRegister",
            "type": "16int",
            "functionCode": 6,
            "objectsCount": 1,
            "address": 0
          }
        ]

The following are the conversion node scripts and modbus.json configurations that cannot be written to a single coil

var request = {};
request.method = "writeSingleCoil";
request.params = [0];
return {msg: request, metadata: metadata, msgType: msgType};
"rpc": [
          {
            "tag": "writeSingleCoil",
            "type": "bits",
            "functionCode": 5,
            "objectsCount": 1,
            "address": 3
          }
        ]

Modbus slave Communication Traffic Tabs received the following:

Rx:031524-00 0A 00 00 00 06 01 05 00 03 FF 00
Tx:031525-00 0A 00 00 00 06 01 05 00 03 FF 00

No matter what message I send, it receives FF instead of 00.

I've also tried the following

var request = {};
request.method = "writeSingleCoil";
request.params = 0;
return {msg: request, metadata: metadata, msgType: msgType};
"rpc": [
          {
            "tag": "writeSingleCoil",
            "type": "16uint",
            "functionCode": 5,
            "objectsCount": 1,
            "address": 3
          }
        ]
"rpc": [
          {
            "tag": "writeSingleCoil",
            "type": "16int",
            "functionCode": 5,
            "objectsCount": 1,
            "address": 3
          }
        ]

Connector name (If you need help with some connector/converter): Modbus Connector

Error traceback (If it was raised):

Versions (please complete the following information):

imbeacon commented 3 years ago

Hi @minivv ,

Thank you for your interest in ThingsBoard IoT gateway. Please try to use the version from the master branch. If it isn't working please open the new issue.