With the beautiful Bookworm release, we can export the actual modules value to OPC UA Server virtual module such as RevPi DIO, RevPi AIO and also Modbus virtual modules easily which are using Boolean and Word data type.
But for one of our requirement, we need to also use Float data type.
Normally we will combine 2 words from Modbus virtual modules in Python or Node-RED, but we can't find the way to export these values from Python to RevPi's OPC UA Server's virtual module.
Can anyone give us some advice on how to make this work?
Using Float with OPC UA Server virtual module
Re: Using Float with OPC UA Server virtual module
Just to close this topic that we were able to do it successfully by combining several information around these forums.
One of the keypoint is to modify /etc/revpipyload/replace_ios.conf as in attached picture.
In PiCtory, you have to also.
1) Add Virtual Device 32 Bytes
2) Add OPC UA Server module and set Output_mode to Read and Write
Below is the Python code that worked perfectly.
import revpimodio2
import struct
revpi = revpimodio2.RevPiModIO(autorefresh=True)
float_value = 123.123
float_bytes = struct.pack('<f', float_value)
revpi.io.Output_1_i07.value = float_bytes[0]
revpi.io.Output_2_i07.value = float_bytes[1]
revpi.io.Output_3_i07.value = float_bytes[2]
revpi.io.Output_4_i07.value = float_bytes[3]
float_value = 456.456
float_bytes = struct.pack('<f', float_value)
revpi.io.Output_5_i07.value = float_bytes[0]
revpi.io.Output_6_i07.value = float_bytes[1]
revpi.io.Output_7_i07.value = float_bytes[2]
revpi.io.Output_8_i07.value = float_bytes[3]
revpi.cleanup()
One of the keypoint is to modify /etc/revpipyload/replace_ios.conf as in attached picture.
In PiCtory, you have to also.
1) Add Virtual Device 32 Bytes
2) Add OPC UA Server module and set Output_mode to Read and Write
Below is the Python code that worked perfectly.
import revpimodio2
import struct
revpi = revpimodio2.RevPiModIO(autorefresh=True)
float_value = 123.123
float_bytes = struct.pack('<f', float_value)
revpi.io.Output_1_i07.value = float_bytes[0]
revpi.io.Output_2_i07.value = float_bytes[1]
revpi.io.Output_3_i07.value = float_bytes[2]
revpi.io.Output_4_i07.value = float_bytes[3]
float_value = 456.456
float_bytes = struct.pack('<f', float_value)
revpi.io.Output_5_i07.value = float_bytes[0]
revpi.io.Output_6_i07.value = float_bytes[1]
revpi.io.Output_7_i07.value = float_bytes[2]
revpi.io.Output_8_i07.value = float_bytes[3]
revpi.cleanup()