I' trying to connect from my Mac laptop to a Modbus device (MR-SI4) using a serial connection using a USB RS485 converter that gets "mounted" to /dev/cu.SLAB_USBtoUART
.
This is my code:
import logging
logging.basicConfig()
log = logging.getLogger()
log.setLevel(logging.DEBUG)
from pymodbus.constants import Endian
from pymodbus.constants import Defaults
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.transaction import ModbusRtuFramer
# settings for USB-RS485 adapter
SERIAL = '/dev/cu.SLAB_USBtoUART'
BAUD = 19200
# set Modbus defaults
Defaults.UnitId = 1
Defaults.Retries = 5
client = ModbusClient(method='rtu', port=SERIAL, stopbits=1, bytesize=8, timeout=3, baudrate=BAUD, parity='E')
connection = client.connect()
print "Readout started"
#result = client.read_discrete_inputs(0)
#result = client.read_holding_registers(12,19)
result = client.read_input_registers(0,1)
print(result)
The output in the console is:
$ sudo python test.py
Readout started
DEBUG:pymodbus.transaction:Running transaction 1
DEBUG:pymodbus.transaction:send: 0x1 0x4 0x0 0x0 0x0 0x1 0x31 0xca
DEBUG:pymodbus.client.sync:will sleep to wait for 3.5 char
DEBUG:pymodbus.transaction:recv:
DEBUG:pymodbus.transaction:getting transaction 1
Modbus Error: [Input/Output] No Response received from the remote unit
I would love to have a little help understanding the error I'm getting. I tried with the configuration of pymodbus
and also with different functions like read_discrete_inputs
or read_holding_registers
. Any help?
Thanks
I have also had similar error where there was no response. My device address was wrong. It was 1 i.e unit = 1. It was supposed to be zero. i.e
client.read_holding_registers(500,1,unit=0)
Otherwise error output was