QModbusTcpClient 数据大小的限制
Limitation in QModbusTcpClient's data size
背后的故事:使用一个QModbusTcpClient
I am trying to read the content from a device connected to a Modbus/TCP
network. For that purpose I have written a Windows program (tested on 7 and 10) in Qt C++ (Qt version 5.7.0) which essentially calls QModbusClient::sendReadRequest
with QModbusDataUnit::QModbusDataUnit(RegisterType type, int address, quint16 size)
作为参数,其中类型是HoldingRegisters
,address 等于 1000
(可以是另一个地址,对于这个特定问题并不重要)并且 size 是所需的长度要从设备读取的数据。
问题: 当 size
小于或等于 63
寄存器时一切正常。每次尝试超出此值都会导致错误,这取决于我测试程序所用的设备,但通常会说请求无效。
测试:
- 我已经用几个真实的设备和
Modbus/TCP
测试过这个
simulator 获得相同的结果,即 size
<= 63
-> okay; size
>
63
-> 错误
Modpoll
从另一侧允许我从相同的设备和模拟器读取数据块 size
大于 63
寄存器
一些研究: Here据说确实有限制,但是是256字节,相当于128个16位寄存器,在换句话说 - 远远超出了我的阅读尝试限制。
我的怀疑: 似乎 QModbusTcpClient
不允许读取超过 63
个寄存器。
问题:有没有人在使用 QModbusTcpClient
时遇到过这样的问题,除了分两次读取数据之外,有没有办法克服这个限制?
好吧,在我的案例中有效的解决方案是把事情掌握在我手中并编写我自己的 class 来与 Modbus 设备通信。 class 继承自 QObject
,因此信号槽系统仍然可用,但实际功能基于 winsock2.h
。 Here is a sample program, which does the job for what I need. Another useful sources I have stumbled upon are this book, the example program from the winsocket 2 reference and of course the Modbus specification。事实证明,这并没有那么困难,并且在我提到的资源的一点帮助下,我能够解决我遇到的问题。
背后的故事:使用一个QModbusTcpClient
I am trying to read the content from a device connected to a Modbus/TCP
network. For that purpose I have written a Windows program (tested on 7 and 10) in Qt C++ (Qt version 5.7.0) which essentially calls QModbusClient::sendReadRequest
with QModbusDataUnit::QModbusDataUnit(RegisterType type, int address, quint16 size)
作为参数,其中类型是HoldingRegisters
,address 等于 1000
(可以是另一个地址,对于这个特定问题并不重要)并且 size 是所需的长度要从设备读取的数据。
问题: 当 size
小于或等于 63
寄存器时一切正常。每次尝试超出此值都会导致错误,这取决于我测试程序所用的设备,但通常会说请求无效。
测试:
- 我已经用几个真实的设备和
Modbus/TCP
测试过这个 simulator 获得相同的结果,即size
<=63
-> okay;size
>63
-> 错误 Modpoll
从另一侧允许我从相同的设备和模拟器读取数据块size
大于63
寄存器
一些研究: Here据说确实有限制,但是是256字节,相当于128个16位寄存器,在换句话说 - 远远超出了我的阅读尝试限制。
我的怀疑: 似乎 QModbusTcpClient
不允许读取超过 63
个寄存器。
问题:有没有人在使用 QModbusTcpClient
时遇到过这样的问题,除了分两次读取数据之外,有没有办法克服这个限制?
好吧,在我的案例中有效的解决方案是把事情掌握在我手中并编写我自己的 class 来与 Modbus 设备通信。 class 继承自 QObject
,因此信号槽系统仍然可用,但实际功能基于 winsock2.h
。 Here is a sample program, which does the job for what I need. Another useful sources I have stumbled upon are this book, the example program from the winsocket 2 reference and of course the Modbus specification。事实证明,这并没有那么困难,并且在我提到的资源的一点帮助下,我能够解决我遇到的问题。