I'm trying to communicate to a custom board via Modbus RTU-half duplex RS-485 connection from my windows machine (windows 10). I'm using the python MinimalModbus API and have all the dependent libraries installed. I also have the proper RS-422/485 adapter. I know the baud-rate, COM port, slave address and parity bit are all correct. I also know my code is outputting a bit-stream from an O-scope trace. For someone reason the board wont respond back at all. Any help would be MUCH appreciated.
import minimalmodbus
import serial
#minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True
minimalmodbus.PARITY = serial.PARITY_EVEN
#minimalmodbus.handle_local_echo=True
minimalmodbus.BAUDRATE = 57600
minimalmodbus.TIMEOUT = .01
instrument = minimalmodbus.Instrument('COM4',0)
instrument.debug = True
print(instrument.read_register(11,1))
MinimalModbus debug mode. Writing to instrument (expecting 7 bytes back): '\x00\x03\x00\x0b\x00\x01ô\x19' (00 03 00 0B 00 01 F4 19)
MinimalModbus debug mode. No sleep required before write. Time since previous read: 1478637162864.7 ms, minimum silent period: 0.67 ms.
MinimalModbus debug mode. Response from instrument: '' () (0 bytes), roundtrip time: 10.9 ms. Timeout setting: 10.0 ms.
Traceback (most recent call last):
File "RS485.py", line 11, in <module>
print(instrument.read_register(11,1))
File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\minimalmodbus.py", line 258, in read_register
return self._genericCommand(functioncode, registeraddress, numberOfDecimals=numberOfDecimals, signed=signed)
File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\minimalmodbus.py", line 697, in _genericCommand
payloadFromSlave = self._performCommand(functioncode, payloadToSlave)
File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\minimalmodbus.py", line 795, in _performCommand
response = self._communicate(request, number_of_bytes_to_read)
File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\minimalmodbus.py", line 930, in _communicate
raise IOError('No communication with the instrument (no answer)')
OSError: No communication with the instrument (no answer)
Problem is at the line:
instrument = minimalmodbus.Instrument('COM4',0)
You are instructing minimalmodbus
to reach for an instrument having modbus id equal to zero. This is an invalid id.
Check the settings of your instrument and correct the id in your code.