3

I need to get device information (device name, etc) through pymodbus. Does anyone know how to accomplish that?

Thanks

2 Answers2

3

If your modbus device supports the Device Information command via the encapsulated interface command (0x2b 0x0e), you can use the following to get the device information with pymodbus (Put in your correct addresses and such) :

>>> from pymodbus.client.sync import ModbusSerialClient as ModbusClient
>>> mc = ModbusClient(method='rtu', port='/dev/ttyACM1')
>>> mc.connect()
True
>>> from pymodbus import mei_message
>>> rq = mei_message.ReadDeviceInformationRequest(unit=5,read_code=0x03)
>>> rr = mc.execute(rq)
>>> rr.information
{0: ...}
2

If you are communicating through a serial port (usb-/comport) you can get a list of serial devices on Comports using list_ports from serial:

64bit python:

import serial.tools.list_ports as portlist
for port in portlist.comports():
    print(port)
    print(port.device)

Outputs:

COM10 - Serial USB-device (COM10)

USB VID:PID=15A2:0300 SER=6 LOCATION=1-4.3

For my Modbus device on Comport 10

32-bit python:

import serial.tools.list_ports as portlist 
for port in portlist.comports():
    print(port)

Outputs a tuple including device name, vendor id, product id etc.

Community
  • 1
  • 1
Hvitnov
  • 21
  • 2