Modbus on Fipy returning not values but request



  • Hi,

    I am trying to get readings form modbus device. but no matter what i tired i have same results.
    This is my code:

    from uModBus.serial import Serial
    import machine
    
    ######################### RTU SERIAL MODBUS #########################
    uart_id = 0x01
    modbus_obj = Serial(uart_id, pins=('P9', 'P10'))
    # if the serial modbus requires a ctrl pin, you can set it like this:
    # modbus_obj = Serial(uart_id, pins=('P9','P10'), ctrl_pin='P8')
    
    # baudrate=115200, data_bits=8, stop_bits=1, parity=None
    ###################### READ INPUT REGISTERS ##################
    slave_addr=0x01
    starting_address=0x06
    register_quantity=1
    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))
    
    

    in serial module I added few print statements and get these results:

    Send to device:
     bytearray(b'\x01\x04\x00\x06\x00\x01\xd1\xcb')
    UART response:
     bytearray(b'\x01\x04\x00\x06\x00\x01\xd1\xcb')
    Input register value: 1536
    

    I know that response is the same like request, and value that is read is 06 00 (hex) is 1536 decimal

    sensor that shouldrespond with value is working and if I make a request to it i get:

    TX: 01 04 00 06 00 01 D1 CB
    RX: 01 04 02 01 96 38 CE
    

    value is 01 96(hex) wich is 406 and that is correct.

    Maybe somebode had the same problem?



  • So I was right, when i connected over UART to RS485 converter everything is working fine.

    This shloud be mentioned in docs, that you need to use RS485 converter and not to try connecting directly.



  • @jcaron no I haven't tried to connect to another host Fipy device since in should be a master on modbus.

    I connected A and B of modbus pins to pytrack 2.0 external pins P9 and P10. And after more research i think this is a problem, since i need RS485 to UART converter to use... as most of the forums says...

    I downloaded library from pycom repo https://github.com/pycom/pycom-modbus bu it needs a little bit of adjusment since readall() function is deprecated and need to be changed do read().



  • @Tautvydas-Bujauskas have you tried using the same device to another host to see how it behaves there? Connecting it to your PC for instance.

    Also can you give more details about the device and how you connected it to the FiPy?

    Finally, can you tell us where you got the umodbus library from?


Log in to reply
 

Pycom on Twitter