简体   繁体   English

如何检索大于Qt Modbus InputRegisters的数据大小?

[英]How to retrieve data size larger than Qt Modbus InputRegisters?

From what I understand, the range of QModbusDataUnit::InputRegisters is range 0-65535 which is unsigned short . 据我了解, QModbusDataUnit::InputRegisters的范围是0-65535,这是unsigned short

The method to read 1 unit of inputregisters is as follows: 读取1个单位的inputregisters的方法如下:

QModbusDataUnit readUnit(QModbusDataUnit::InputRegisters, 40006, 1);

The value of that will be in the reply, ie : int value = result.value(0); 该值将在回复中,即: int value = result.value(0);

My question is that what if I have to read a value of unsigned int which is much larger of the range of 0 to 4,294,967,295 . 我的问题是,如果我必须读取unsigned int的值,该值比0 to 4,294,967,295的范围大得多,该怎么办?

How can I retrieve that value? 如何获取该值?

As you stated, Modbus input registers are 16 bit unsigned integers. 如您所述,Modbus输入寄存器是16位无符号整数。 So without some type of conversion they are limited to the range: 0 - 65535. For 32-bit unsigned values it is typical (in Modbus) to combine two registers. 因此,没有某种类型的转换,它们的范围就被限制在0到65535之间。对于32位无符号值,通常(在Modbus中)将两个寄存器组合在一起。

For example, the high 16-bits could be stored at 40006 and the low 16-bits at 40007. 例如,高16位可以存储在40006,低16位可以存储在40007。

So, if you were reading the value ‭2271560481‬ (0x87654321 hex), you would read ‭34661‬ (0x8765) from address 40006 and 17185 (0x4321 hex) from location 40007. You would then combine them to give you the actual value. 因此,如果您正在读取值‭2271560481‬(十六进制的0x87654321),则会从地址40006读取‭34661‬(0x8765),而从位置40007读取17185(十六进制的0x4321)。然后,将它们合并以得到实际值。

I don't know the Qt Modbus code, but expanding on your example code you can probably read both values at the same time by doing something like this: 我不知道Qt Modbus代码,但是在您的示例代码上扩展,您可以通过执行以下操作来同时读取两个值:

readUnit(QModbusDataUnit::InputRegisters, 40006, 2);

and combine them 并结合起来

quint32 value = result.value(0);
value = (value << 16) | result.value(1);

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

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