simonvetter / modbus

Go modbus stack (client and server)
MIT License
262 stars 83 forks source link

Serial reading does not work, but it does with Python #6

Closed shibumi closed 2 years ago

shibumi commented 2 years ago

Hello,

I have the following python code:

client = ModbusSerialClient(method='rtu', port="/dev/ttymxc3", baudrate=38400, timeout=1000)
client.read_holding_registers(646, unit=10)

Reading registers does work with Python, but with Go modbus it does not work:

    client, err := modbus.NewClient(&modbus.ClientConfiguration{
        URL:     "rtu:///dev/ttymxc3,
        Speed:   38400,
        Timeout: 1 * time.Second,
    })
       if err != nil {
        return nil, err
    }

    err = client.SetUnitId(uint8(10))
    if err != nil {
        return nil, err
    }
    err = client.Open()
    if err != nil {
        return nil, err
    }
    client.ReadUint32(364, modbus.HOLDING_REGISTER)

I tried the modbus-cli as well and even that does not work: /modbus-cli --target=rtu:///dev/ttymxc3 --speed 38400 suid:10 rh:uint16:364

shibumi commented 2 years ago

Found the issue... I had to set a different stop bit (1) instead of 2.