Acsess Input Data over Modbus RTU



  • Hi
    I am trying to setup my UniPi Neuron xS50 using a Neuron S103 as main CPU.

    Here are the steps that I have performed:

    1. Install pymodbus
    2. Connect the RS485 lines of s103 and xS50
    3. Turn on the bus terminator on both devices.
    4. Created the following python script
    5. Set Adress to 0 and rebooted both devices
      
    from pymodbus.client.sync import ModbusSerialClient
    c = ModbusSerialClient(method = 'rtu',port ='/dev/extcomm/1/0',baudrate=19200)
    if 1:
        rs =  c.read_holding_registers(2, 1, unit=0)
        x = float(rs.getRegister(0))
        print x
        c.close()
    

    If I execute this program I get the following error

    File "/home/pi/.local/lib/python2.7/site-packages/pymodbus/client/sync.py", line 84, in execute
      raise ConnectionException("Failed to connect[%s]" % (self.__str__()))
    pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Failed to connect[rtu baud[19200]]
    

    Does anybody know what I am doing wrong?
    Kind regards
    Christoph Ebler


  • administrators

    Hello @christophebler

    I am not sure if pymodbus works well.. But what is more important if everything below is isntalled correctly.

    So a few steps (for 1 and 2 I recommend to use the our opensource image):

    1. What OS are you using?
    2. How did you install the overlay and neuron TCP server?
    3. Does the /dev/extcomm/1/0 file exists?


  • Hello @tomas_hora

    Thank you for your fast response.

    Currently am using the newest Raspian Stretch immage from the official Homepage.
    I have cloned the Modbus TCP overlay from github and istalled it.

    I am able to controll the onbord IO of th Neuron S103 using the modbus TCP server.

    If I run: sudo ls /dev/extcomm/1/ I get 0 as a resault so i assume that the tcp overlay is working.

    pi@Device:~ $ sudo ls /dev/extcomm/1
    0
    pi@Device:~ $ sudo ls /dev/extcomm/1/0
    /dev/extcomm/1/0
    

    if pymodbus is not the best choice what woud you suggest instead ?
    I woud Prefer python or c / c++ as a Programmin language.

    kind regards

    Christoph Ebler


  • administrators

    @christophebler Ok, than the serial line works well. But I still recommend using our opensource image because the parameters that can be set using the github version is limited and might cause some troubles which are fixed in the opensource image.

    Byt the way, what do you want to do by 'Set Adress to 0 and rebooted both devices'? You can set address only at the slave which is the xS50 and if you set it to 0, than the SW configuration is used (address 15, 19200bps, no parity) and you are opening different device...

    Address 0 is not allowed on Modbus, thus the behavior like I described.