device-modbus: Trying to read Float32 value from a 2 register combination #42
-
Hi everyone, As the title suggests, I am trying to read a Float32 value by reading the binary data from 2 registers. Just wondering what valueType and rawType I need to use in my device profile. Reading through the EdgeX documentation (https://docs.edgexfoundry.org/2.3/examples/Ch-ExamplesAddingModbusDevice), I noticed that only raw types of Int16 and Uint16 are allowed in the device profile. However, there is also mention of Byte Swap and Word Swap for Int32, Uint32 and Float32 which I assumed it meant that would allow EdgeX to handle 32-bit values stored in the holding registers. Additionally, value type “decides how many registers will be read” and a corresponding value type for a raw type of Int16 is Float32. With these in mind, we have a TCP Modbus device which holds the following values: Here, registers 9072 and 9073 hold the Float32 values of a variable and form 0x4C130226 or 3.85374e+07 in decimal. Based on the instructions in the documentation, this would require the following device profile attributes and properties:
It only reads one of the registers and returns that value as a “Float32” but really it’s just 0x4C13 or 19475 in hexadecimal rather than the full 0x4C130226. What should my device profiles look like instead to read both registers? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @willborghei The number of registers read by the device-modbus service depends on valueType. And the device-modbus service transforms the raw data according to valueType and rawType. Note that the device-modbus driver uses valueType as rawType by default. https://github.com/edgexfoundry/device-modbus-go/blob/main/internal/driver/deviceclient.go#L58 Specify rawType=Int16 or rawType=Uint16 in attributes for a float32 or float64 resource only if the raw data is of type Int16 or Uint16. @weichou1229 @cloudxxx8 Please correct me if I am wrong. |
Beta Was this translation helpful? Give feedback.
Hi @willborghei
The number of registers read by the device-modbus service depends on valueType.
https://github.com/edgexfoundry/device-modbus-go/blob/bb2f4bd64c3941eb86d6cd8a035d25878e21dc53/internal/driver/deviceclient.go#L105-L115
For example, if valueType is float32, 2 registers will be read.
And the device-modbus service transforms the raw data according to valueType and rawType.
https://github.com/edgexfoundry/device-modbus-go/blob/bb2f4bd64c3941eb86d6cd8a035d25878e21dc53/internal/driver/deviceclient.go#L136-L149
Note that the device-modbus driver uses valueType as rawType by default. https://github.com/edgexfoundry/device-modbus-go/blob/main/internal/driver/deviceclient.go#L58
Speci…