Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pymodbus
#1
I'm using pymodbus to read modbus data from a controller, using serial over an rs485 to usb. I can read coils, registers,etc all the normal stuff.
My controller has some custom functions that cause it to switch modes, but I cannot find how to send custom functions with pymodbus. pleas help
Reply
#2
Did you look at this?

https://github.com/pymodbus-dev/pymodbus...tom_msg.py
Reply
#3
(Oct-20-2023, 04:15 PM)deanhystad Wrote: Did you look at this?

https://github.com/pymodbus-dev/pymodbus...tom_msg.py

I see it, but not understanding it. do you know of any examples? or can you explain it to me?
thanks
Reply
#4
What don't you understand?

The example creates a new command class named "CustomModbusRequest" that sends modbus function code 55. There is a related class named "CustomModbusResponse" that decodes the response. To use the custom request you would import the module containing the class and call it like this:
        # from my_custom_modbus_functions import CustomModbusResponse, CustomModbusRequest
        . . .
        client.register(CustomModbusResponse)   # Only do this once
        . . .
        request = CustomModbusRequest(32, slave=1)   # Can do this many times
        result = await client.execute(request)
        print(result)
To use custom functions like this, you would create a module (file) containing code similar to the example for each modbus function. You will give your classes better names.

In your client program you will import your module, regiser all the response classses, and call the new function classes as needed.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020