I am a beginner with both python and modbus and I'm trying to control a fan connected to a serial port with pymodbus for hours now. Using a proprietary software from the manufacturer I was able to control the fan, so the connection itself works. Yet, my own code does not.
According to the manual the fan is set to the following values:
mode: RTU
baudrate: 19200
parity: even
timeout: 1
slave ID: 247 (F7h)
databits: 8
I modified the pymodbus example code from the Pymodbus Library Examples. This is my code:
from pymodbus3.client.sync import ModbusSerialClient as ModbusClient
Fan = ModbusClient(method='rtu',port ='/dev/ttymxc1', parity = 'E', baudrate='19200', timeout=1)
connection = Fan.connect()
a = Fan.write_register(2,1, unit=0xF7)
b = Fan.read_holding_registers(2,1, unit = 0xF7)
Fan.close()
Both the read and write command result in the following error:
pymodbus3.exceptions.ModbusIOException: Modbus Error: [Input/Output] Server responded with bad response
The same message I get even when the cable is not plugged in.
Does anyone have a suggestion what's wrong?
Timeout is the time for the port to wait for an answer.
Set the timeout to something like ~2000, 1 is 1ms and they probably meant 1s.
And try also address 1 (if the above is not working), check also if the Modbus address can be configured to something else (it might be some switchs on the fan).