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.75k stars 845 forks source link

[HELP] How to connect multiple slave devices under the modbus-serial (rtu) connector #825

Closed Lanruo555 closed 2 years ago

Lanruo555 commented 2 years ago

Describe the issue Create description about your issue, and your actions to solve it. I created a gateway device and two subdevices on the things board platform and set their association as: the gateway device contains two subdevices.Their attribute values, telemetry values, and shared attribute values are also configured in the profile modbus_new.json.When I configure any other device in the modbus_new.json that always works fine, but when I configure both devices simultaneously, I get the error.

Configuration (Attach your configuration file) Notate: Remove Access token from file if you want to attach a tb_gateway.yaml { "master": { "slaves": [ { "unitId": 1, "deviceName": "test1", "attributesPollPeriod": 5000, "timeseriesPollPeriod": 5000, "sendDataOnlyOnChange": false, "attributes": [ { "byteOrder": "BIG", "tag": "temperature", "type": "bytes", "functionCode": 3, "registerCount": 1, "address": 1 } ], "timeseries": [ { "tag": "distance", "type": "bytes", "functionCode": 3, "objectsCount": 1, "address": 2 } ], "attributeUpdates": [ { "tag": "shared_value_1", "type": "32uint", "functionCode": 6, "objectsCount": 2, "address": 3 }, { "tag": "shared_value_2", "type": "32uint", "functionCode": 6, "objectsCount": 2, "address": 4 } ], "rpc": [ { "tag": "bearing_bpfo", "type": "32uint", "functionCode": 6, "objectsCount": 2, "address": 5 } ], "host": null, "port": "/dev/ttyUSB0", "type": "serial", "method": "rtu", "timeout": 35, "byteOrder": "BIG", "wordOrder": "BIG", "retries": null, "retryOnEmpty": null, "retryOnInvalid": null, "baudrate": 9600, "pollPeriod": 5000, "connectAttemptCount":1 }, { "unitId":2, "deviceName":"Test2", "attributesPollPeriod":5000, "timeseriesPollPeriod":5000, "sendDataOnlyOnChange":false, "attributes":[ { "byteOrder":"BIG", "tag":"temperature", "type":"bytes", "functionCode":3, "registerCount":1, "address":10 } ], "timeseries":[ { "tag":"distance", "type":"bytes", "functionCode":3, "objectsCount":1, "address":11 } ], "attributeUpdates":[ { "tag":"shared_value_1", "type":"32uint", "functionCode":6, "objectsCount":2, "address":12 } ], "host":null, "port":"/dev/ttyUSB0", "type":"serial", "method":"rtu", "timeout":35, "byteOrder":"BIG", "wordOrder":"BIG", "retries":null, "retryOnEmpty":null, "retryOnInvalid":null, "baudrate":9600, "pollPeriod":5000, "connectAttemptCount":5 } ] },

"slave": null }

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

Error traceback (If it was raised):

""2022-05-11 15:28:10" - |DEBUG| - [bytes_modbus_uplink_converter.py] - bytes_modbus_uplink_converter - convert - 87 - datatype: telemetry   key: distance   value: None"
""2022-05-11 15:28:10" - |DEBUG| - [bytes_modbus_uplink_converter.py] - bytes_modbus_uplink_converter - convert - 92 - {'deviceName': 'testUpdate', 'deviceType': 'default', 'telemetry': [], 'attributes': []}"
""2022-05-11 15:28:10" - |ERROR| - [bytes_modbus_uplink_converter.py] - bytes_modbus_uplink_converter - convert - 83 - Modbus Error: [Input/Output] device reports readiness to read but returned no data (device disconnected or multiple access on port?)"
NoneType: None
""2022-05-11 15:28:10" - |DEBUG| - [bytes_modbus_uplink_converter.py] - bytes_modbus_uplink_converter - convert - 87 - datatype: telemetry   key: distance   value: None"
""2022-05-11 15:28:10" - |DEBUG| - [bytes_modbus_uplink_converter.py] - bytes_modbus_uplink_converter - convert - 92 - {'deviceName': 'RpcTest', 'deviceType': 'default', 'telemetry': [], 'attributes': []}"
""2022-05-11 15:28:10" - |ERROR| - [bytes_modbus_uplink_converter.py] - bytes_modbus_uplink_converter - convert - 83 - Modbus Error: [Input/Output] device reports readiness to read but returned no data (device disconnected or multiple access on port?)"
NoneType: None

Versions (please complete the following information):

Lanruo555 commented 2 years ago

@imbeacon @samson0v Can you take up some time to help me solve this problem? Thanks a lot !

TheSamabo commented 2 years ago

Hi device disconnected or multiple access on port? Could mean that multiple processes are trying to read serial port at the same time. Do you have any other process/program that is attached to that exact serial port?

Another thing that could cause this is that you are setting "host": none on each slave. Try deleting that line its not necessary. you can checkout docs https://thingsboard.io/docs/iot-gateway/config/modbus/?modbusConnection=serial for setting up serial modbus communication Sam

Lanruo555 commented 2 years ago

I have already solved this problem.