Hey guys, has anyone built a python library for running modbus tcp commands?
This site is now in read-only archive mode. Please move all discussion, and create a new account at the new Victron Community site.
Hey guys, has anyone built a python library for running modbus tcp commands?
Hi,
I have diferent classes for modbusTCP. You can find them in github:
https://github.com/JanusHL/pvcontrol
I used different ways to work with modbusTCP. Direct access to socket for Python 2.x, and pyModbusTCP library for Python 3.x. PyModbusTCP has two different libraries you need to install the right version from:
https://pymodbustcp.readthedocs.io/en/latest/quickstart/index.html#package-setup
In Github:
The Classic folder has a Python 2.x class named classic.py. It uses sockets, you can modify it as your will.
The SMA folder has the sma.py file, it includes the class mbusTCP, it uses pyModbusTCP, the simple way to access registers in Python. This class return a set of registers:
data = mbus.read_data(reg_address, numberof regs).
The file test_sb.py is an example of how use it correctly and how to convert the data to floats and integers.
I hope to have help you
Francisco
Wow! Franscisco this is impressive and thankyou. I will play around with this now and will send through pull requests if I have any - I have not programmed in a while but I would love to help contribure
Hi,
I made these two python class to facilitate the programming. I think is more easy to use the pyModbusTCP for beginners. (sma.py). Remember that it uses only the function code "3": read_holding_registers. If you need other functions, could be appropiate to add diferent functions inside the class to do it. In the library page you have all the methods
If you have any issue about programming don't hesitate to reply in this thread.
Victron Venus OS Open Source intro page
Venus OS GitHub (please do not post to this)
22 People are following this question.