With the RevPiModIODriver class, the python3-revpimodio module can be used to simply write a driver for the virtual devices on the RevPi.
The actual programming of the controller may be for example logiCAD. If you need other data from other sources, you use “Virtual Devices”. These are treated just like real hardware from logiCAD.
In our example, we collect data from RevolutionPi and write it into virtual devices. This is the system time in UTC, the percentage of disk space, and the CPU temperature.
Of course, it is also possible to write data with logiCAD and then evaluate it with the Python program.
We create a virtual device, which receives position number 64.
In the Python program, the class is instantiated: (For RevPiModIODriver, all functions and classes are available just like RevPiModIO.)
self.rpi = revpimodio.RevPiModIODriver([64])
Next, only a few bytes have to be connected to data fields. For the timestamp, e.g. 4 bytes in which we store an int () value. (Note: For our Python program, the outputs are the inputs from the point of view of logiCad – and vice versa! We are the driver – and the hardware: D)
self.rpi.devices[64].reg_out("timestamp", "Input_1_i09", "L")
We use the struct library of Python to determine the data type and the byte length – “L” stands for 4 bytes int () without sign
As a last step, we only need to write a value that we create cyclically with the Python program in to our new output “timestamp”:
self.rpi.devices[64]["timestamp"].value = int(time.time())
When the program is running, the timestamp (in our case) is available as little-endian (Input_1_i09 – Input_4_i09):
Or,with the right datatype in logiCAD: