question

mike-casey avatar image

modbus tcp python library?

Hey guys, has anyone built a python library for running modbus tcp commands?

Venus OS
2 |3000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

2 Answers
farriaza avatar image
farriaza answered ·

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.

2 |3000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

farriaza avatar image
farriaza answered ·

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



1 comment
2 |3000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

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