Hope you are doing great! I recently started using python for modbus communication. I want to clear my few doubts.
While using pymodbus3 module, I was able to write coils using following code:
import pymodbus3
import serial
from pymodbus3.pdu import ModbusRequest
from pymodbus3.client.sync import ModbusSerialClient as ModbusClient
from pymodbus3.transaction import ModbusRtuFramer
from serial.tools.list_ports import comports
client = ModbusClient(method = "rtu", port = 'COM4',stopbits = 1, bytesize = 8, parity = 'N', baudrate= 19200)
connection = client.connect()
client.write_coil(1000, 1, unit = 0x01)
For reading coil status (function 0x01):
result = client.read_coils(1000,1)
print(result)
client.close()
Its returning None.
Or writing to register and reading is also not working:
client.write_register(0, 1000, unit=0x01)
resu= client.read_holding_registers(0, 1, unit=0x01)
print(resu)
client.close()
Positive response is welcomed!
This is a rather old question, but I want to put this information out there so there is less confusion.
pymodbus3
was a fork of pymodbus
created to support python3 before pymodbus
did so. pymodbus
now fully supports python3 and pymodbus3
is no longer maintained and does not have all the latest that the original does.
See https://github.com/uzumaxy/pymodbus3/issues/7 for details.