2

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)
CompMan
  • 57
  • 2
  • 6
  • As the board does not respond and your code sends data (did you veryfy the format?), it would be a good idea, to debug the target device, not the PC. – too honest for this site Nov 09 '16 at 20:24
  • I'm in the process of checking the bit stream on my o-scope now. I know the target device requires an additional stop start and parity bit for each PDU but I am have trouble figuring out exactly how the bit stream should look. Is it possible the latency of the converter can alter the baud rate? – CompMan Nov 09 '16 at 20:39
  • Do you know if all modbus devices expect these exact additional bits? or are they specific to this board? also, when you say debug target device do you mean software? like using GDB to step through the firmware as i am trying to communicate with it? – CompMan Nov 09 '16 at 20:45
  • I have no idea. Never worked with ModBus. How about reading the specification, check if the timing and signal forms are within limits? Let apart your question does not follow the advice given in [ask], it might not even be a programming problem. At least you did not exclude other causes. Please note we are no debugging/consulting site, nor a discussion site. – too honest for this site Nov 09 '16 at 20:47

2 Answers2

0

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.

zx485
  • 28,498
  • 28
  • 50
  • 59
egelados
  • 16
  • 1
0

Try to set the slave id with instrument = minimalmodbus.Instrument('COM4',1) , where 1 is the Slave ID for your custom instrument.

And try to increase the timeout parameter with this line

minimalmodbus.TIMEOUT = 1 where 1 is equal to 1000 milliseconds.