pythonmodbusrs485minimalmodbus

Can't communicate with Modbus device using minimalmodbus


I am failing to communicate with a device using minimalmodbus, Modbus RTU.

I have connected the device to a raspberry pi via a usb to rs-485 adapter (FTDI chip) A to A and B to B.

The device configurations are as follows:

Modbus Holding registers (simplified for the purpose of this example)

I have tried using raw serial commands to communicate with the device, as well as using pymodbus, and now on my latest attempt minimal modbus. Please see below my code attempt using minimalmodbus.

Also, i know the serial adapter works as i use it for various other serial sensors. Only difference is that i am working with modbus now.

import minimalmodbus

instrument = minimalmodbus.Instrument('/dev/tty/USB1',1)

instrument.debug = True
instrument.handle_local_echo = True # The serial device echos back every write, hence this
instrument.serial.baudrate = 9600
instrument.serial.timeout = 1

value = instrument.read_register(0,2)

print value

I expected to receive some sort of reply even if an error or incorrect, but i am getting nothing. the debug output of minimalmodbus says "IOError: No communication with the instrument(no answer)"

Is there any obvious mistakes in my code vs the sensor requriements? I confirmed my wiring with the manufacturer, and is correct.


Solution

  • Quoting from the manual of your cable:

    The USB-RS485-WE cable allows for local echo to be enabled/disabled by changing a bit in the FT232R EEPROM. If CBUS4 in the EEPROM is set for “PWRON#” local echo is enabled. If CBUS4 in the EEPROM is set for “TXDEN” local echo is disabled. Users can set this with MPROG from www.ftdichip.com The default for the local echo is disabled (CBUS4 set for “TXDEN)

    Phew! lots of info in there. According to the thread of comments on your question you activated the software echo handling on minimalModbus because otherwise your routine would not wait for the response from the device on the other end. That makes one think whether your cable has the local echo enabled or disabled.

    Fortunately, you can check that very easily. As the manual says just go get MPROG here. Extract and run (yeap, you need Windows for this tool, but you can run it on a Virtual Machine).

    Connect your cable to the USB port (don't forget to send the device to the virtual machine if you are running one) and select Tools-->Read and Parse on MPROG.

    This is what you should get:

    MPROG screenshot

    Make sure you have TXEN selected on box C4. According to the manual, you should have TXEN by default, if you see PWRON# it means the local echo is active. Disable it and you should be good to go to use Modbus.