简体   繁体   English

Qt C++:使用 Modbus RTU 类 (RS485) 从多个从站读取数据

[英]Qt C++ : read data from multiple slaves using Modbus RTU class (RS485)

I tried reading values from 1 temperature sensor using Qt modbus class in the following way :我尝试通过以下方式使用 Qt modbus 类从 1 个温度传感器读取值:

QModbusDataUnit(QModbusDataUnit::InputRegisters, /*startAddress*/ 1000, /*numberOfEntries*/ 1 );

Now what I want is reading values from different slaves ( different device ID's same port).现在我想要的是从不同的从站(不同设备 ID 的相同端口)读取值。

I tried pymodbus as its functions has device id argument (example : unit=0x03) :我尝试了 pymodbus,因为它的函数有设备 ID 参数(例如:unit=0x03):

result = client.read_input_registers(0x03E8 ,1, unit=0x03)

But I can't figure out how to do the same using Qt.但我不知道如何使用 Qt 做同样的事情。

Any kind of help is appreciated.任何形式的帮助表示赞赏。

That's not so straightforward as you might think and QtModbus is not very well documented but I think you need to do it in the query using serverAddress as your slave ID:这并不像您想象的那么简单,而且 QtModbus 没有很好的文档记录,但我认为您需要在查询中使用serverAddress作为您的从站 ID 来执行此操作:

QModbusReply *QModbusClient::sendReadRequest(const QModbusDataUnit &read, int serverAddress)

See here for some (not much) more detail.有关一些(不多)的详细信息,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM