Moderator: miprotek

 
gambrinus
Topic Author
Posts: 11
Joined: 18 Apr 2018, 19:26

Modbus

19 Apr 2018, 12:43

Hello,

I was directed here by Volker. I need to know if the RevPiModIO python module supports reading and writing to virtual modbus registers?

Thanks!
 
User avatar
volker
Posts: 1039
Joined: 09 Nov 2016, 15:41

Re: Modbus

28 Apr 2018, 23:58

You will never read and write "Modbus Registers" with the virtual devices Modbus RTU/TCP master or slave. These virtual modules are performing cyclically "actions" by sending or receiving Modbus function calls to the partner reading and writing Modbus registers of the partner. The results of these actions are read or written into named process variables of the central process image of the RevPi Core.
Any of the programs running on a RevPi is using read and write access to this central process image (CPI) to exchange data - so does also RevPiModIO. Sven may explain you more in detail how easy this can be done with his library. But there is no difference in where the data in the CPI has come from. this should be absolutely transparent to the library.
Unser RevPi Motto: Don't just claim it - make it!
 
gambrinus
Topic Author
Posts: 11
Joined: 18 Apr 2018, 19:26

Re: Modbus

01 May 2018, 18:13

Thanks, I figured it out. To any user who may be interested, you just use revpimodio2.RevPiModIO(n) where n is the position of the Modbus TCP virtual device.

In fact, you are not limited to words as the PiCtory app shows. Below is a functional example of how to write a float to an output that can be read as an Input Register from another device.
import revpimodio2

class MyDriver():
    def __init__(self):
        self.rpi = revpimodio2.RevPiModIO(autorefresh=True)
        self.rpi.handlesignalend() 
        self.modbus = revpimodio2.RevPiModIO(64)
        
        self.modbus.io.Output_3.replace_io("myfloat", "f") 
        

    def cyclefunction(self, cycletools):       
        self.modbus.io.myfloat.value = 3.14
        
    def start(self):
        self.rpi.cycleloop(self.cyclefunction, cycletime=1000) 

if __name__ == "__main__": 
    driver = MyDriver()
    driver.start()
    
 
User avatar
volker
Posts: 1039
Joined: 09 Nov 2016, 15:41

Re: Modbus

01 May 2018, 22:56

Hi,
please be aware that IEEE floats are not defined by Modbus. Therefor you will find several differing ways to implement floats in multiple Modbus Word registers. Our process image does convert the Modbus big endian words in liitle endian so that you can use any C word to read and write to Mobdu registers. But many Modbus devices use also big endian for multiple register formats (long integers or floating). Thus you will endup with a mixture of bigendian word order and little endian byte order in the words. So please take care and inform yourself about the device's format of multiple word process values. Especially energy measurement devices very often use 32 or 64 bit numbers stored in 2 or 4 Modbus registers and most of the time they are stored in big endian order.

If you use your own software for the Modbus slave and the Modbus master this will of course not be a problem as you mirror the encoding and decoding of IEEE float.
Unser RevPi Motto: Don't just claim it - make it!
 
gambrinus
Topic Author
Posts: 11
Joined: 18 Apr 2018, 19:26

Re: Modbus

02 May 2018, 14:11

Thanks Volker! The OPC server we're using allows us to configure byte order, so no problems =). I was able to get the float decoded into a tag on the OPC server easily enough. I'm working on a custom RAP file now.

Who is online

Users browsing this forum: No registered users and 1 guest