ModBus library on LoPy : no data received from slave



  • Hello,

    I am trying to read ModBus data from a slave using ModBus library. I am continuously getting error "OSError: no data received from slave". Below is the code I am using

    ######################### RTU SERIAL MODBUS #########################
    uart_id = 0x01
    modbus_obj = Serial(uart_id, pins=('P3', 'P4'))

    ###################### READ HOLDING REGISTERS ##################
    slave_addr=0x01
    starting_address=0x110
    register_quantity=10
    signed=True

    register_value = modbus_obj.read_holding_registers(slave_addr, starting_address, register_quantity, signed)
    print('Holding register value: ' + ' '.join('{:d}'.format(x) for x in register_value))

    I tried reading the same slave from a ModBus master simulator and getting the expected data. But it is failing with the LoPy. Below is the error msg. Please check.

    Traceback (most recent call last):
    File "<stdin>", line 46, in <module>
    File "/flash/lib/uModBus/serial.py", line 127, in read_holding_registers
    File "/flash/lib/uModBus/serial.py", line 86, in _send_receive
    File "/flash/lib/uModBus/serial.py", line 91, in _validate_resp_hdr
    OSError: no data received from slave

    Regards,
    Sameer



  • Hello,
    I'm working on a modbus project using the pycom controller to read a few input registers. But there I get the same error as you Sameer and I'm not able to make the code run correctly.
    What did you do that the code work?

    Regards,
    Jan

    current code:
    ######################### RTU SERIAL MODBUS #########################
    uart_id = 0x01
    modbus_obj = Serial(uart_id, pins=('P3', 'P4'))

    ###################### READ INPUT REGISTERS ##################
    slave_addr=0x01
    starting_address=0x04
    register_quantity=2
    signed=True

    register_value = modbus_obj.read_input_registers(slave_addr, starting_address, register_quantity, signed)
    print('Input register value: ' + ' '.join('{:d}'.format(x) for x in register_value))



  • @sameerchouksey this might be a long shot, but I would try using the original micropython modbus code.
    The pycom modbus code is different and adds the signed option. (which I find strange because endianess is not a given in modbus (ie not defined) so can vary from platform to platform) which would be required to correctly interpret signed values. The original doesn't include this extra code.



  • @timh Yes. I have used Modbus Poll simulator and I can read 10 registers there.

    Regards
    Sameer



  • @sameerchouksey have you confirmed you can read multiple registers from this device using some other software/hardware other than pycom ?

    T



  • @timh I tried reading 2 adjacent registers. But getting only one value.

    There is no hole between two registers. You can see in the screenshot that I first reading register address 0x110 with register count as 2. And then I am reading register address 0x111. In the second call I can read the second register.

    Please check the screenshot.

    0_1521445988223_520b1af9-a056-4682-b7f5-0a4a48bf2d54-image.png



  • @sameerchouksey

    Oh I didn't know you could read a single register. That information missing from you post above.

    Have you checked that the contiguous register range is valid (ie no holes).

    We talk to a number of devices that have large holes in the register range . We can read multiple registers if we avoid the holes. ie registers 50 to 100 (decimal) might have two unused registers at 68 & 69. So we can't read from address 50 for a length of 50. We have read start register 50, length of 27, then from 70 with a length of 30.

    Can you read 2 adjacent registers or are you limited to a single register?

    Tim



  • Thanks for the support. I am able to read it with a potential divider circuit.

    One query, how many registers can I read in one single call?? I am setting up register_quantity=10, but still I am able to read only one register at a time.

    Regards
    Sameer



  • You can use something like that

    0_1521332539702_Capture.JPG

    Search for "XY-017 RS485" in google you'll find it everywhere starting less than $2 (on ebay for example)



  • @sameerchouksey have you tried using TTL and a different library on something like a raspberry pi ?

    One of things we have had issues with various serial modbus adaptors is the timeout for the read is too short, which typically gives you OSError: no data received from slave. For instance an ATLAS COPCO engine controller I couldn't get to work using modbus_tk, but could with PyModbus due to the way modbus_tk was handling serial timeouts (and I didn't then want to spend time debugging modbus_tk ;-)

    The other obvious things are checking comms details and slave address which will also generally give you the same error.
    You code example isn't showing baud etc...

    T



  • Hello,

    Thanks for your prompt response. Yes, the device supports RS485 and I am using a Rs485 to TTL converter between PyCom board and the ModBus slave. Still getting same error.

    Regards,
    Sameer



  • @timh
    Yes, it is TTL only.

    @SameerChouksey
    you must use converter e.g. SN65HVD230 - direct connection can brake your device as it is 3V3 levels device only.



  • @sameerchouksey

    Hi this might be a silly question, but most MODBUS RTU devices are serial RS323 or RS485. I personally haven't seen any industrial modbus devices that use TTL.

    I am pretty sure the serial UART on the ESP32 is TTL so it won't work with any RS232/RS485 devices with out something like a MAX3232

    Cheers

    Tim


 

Pycom on Twitter