PyModbus / "OSError: no data received from slave"

  • Hello. I am trying to communicate to a Modbus RTU slave, in this case "Modbus Slave" running on a PC, and am getting the error "OSError: no data received from slave". I'm using UART 1 and I've tried it at 9600bps and 115200. I know that the hardware is good because it works with PuTTY and dupterm.

    Firmware and hardware:
    Pycom MicroPython 1.20.0.rc7 [v1.9.4-2833cf5] on 2019-02-08; GPy with ESP32

    from uModbus.serial import Serial
    mb = Serial(uart_id=1, baudrate=115200, pins=('P3', 'P4'))
    coil_status = mb.read_coils(0x01, 1, 1)
    print('Coil status: ' + ' '.join('{:d}'.format(x) for x in coil_status))


  • @postbox Yes I did. I replaced the readall() with read() and it appears to work. I can show you exactly what I did when I get home. Right now I don't have access to it.

  • Hey Snock .

    Did you manage to get this working ?

    Thanks Dale

  • Okay, so there may be something going on with the Witte Software "Modbus Slave" program I am using for testing in conjunction with the USB to RS232 converter I am using. The GPy never received anything from my Modbus Slave software so it never made it past the if self._uart.any() line in of uModbus:

        def _uart_read(self):
            response = bytearray()
            for x in range(1, 40):
                if self._uart.any():
                    # variable length function codes may require multiple reads
                    if self._exit_read(response):
            return response

    However that did not solve the problem as readall() is missing as indicated:

    >>> print(dir(UART))
    ['__class__', '__name__', 'EVEN', 'ODD', 'any', 'deinit', 'init', 'read', 'readinto', 'readline', 'sendbreak', 'wait_tx_done', 'write']

Log in to reply

Pycom on Twitter