goburrow / modbus

Fault-tolerant implementation of modbus protocol in Go (golang)
BSD 3-Clause "New" or "Revised" License
947 stars 369 forks source link

response slave id does not match request #8

Closed jonaz closed 8 years ago

jonaz commented 9 years ago

Im not sure if this is an issue with the library or an issue with my modbus device. I have a raspberry pi with a USB modbus dongle and a ventilation system which i fetch temperatures from modbus registers.

I make the connection like this and then fetch registers every 30 second after that.

func (m *Modbus) Connect() error {
    // Modbus RTU/ASCII
    handler := modbus.NewRTUClientHandler("/dev/ttyUSB0")
    handler.BaudRate = 9600
    handler.DataBits = 8
    handler.Parity = "N"
    handler.StopBits = 2
    handler.SlaveId = 1
    handler.Timeout = 5 * time.Second
    //handler.Logger = log.New(os.Stdout, "test: ", log.LstdFlags)
    m.handler = handler
    if err := handler.Connect(); err != nil {
        return err
    }

    m.client = modbus.NewClient(handler)
    return nil
}

It works fine for a few days then i start getting below errors. I restart my app and its fine again. Im thinking of only checking for error and then making the connection again. But this might be a library issue?

2015/07/20 20:31:18 modbus: response slave id '241' does not match request '1'
2015/07/20 20:31:18 modbus: response slave id '35' does not match request '1'
2015/07/20 20:31:18 modbus: response slave id '249' does not match request '1'
2015/07/20 20:31:18 modbus: response slave id '241' does not match request '1'
2015/07/20 20:31:18 modbus: response slave id '143' does not match request '1'
2015/07/20 20:31:19 modbus: response slave id '69' does not match request '1'
2015/07/20 20:31:48 modbus: response slave id '180' does not match request '1'
2015/07/20 20:31:48 modbus: response slave id '48' does not match request '1'
2015/07/20 20:31:48 modbus: response slave id '241' does not match request '1'
2015/07/20 20:31:48 modbus: response slave id '143' does not match request '1'
2015/07/20 20:31:48 modbus: response slave id '154' does not match request '1'
2015/07/20 20:31:49 modbus: response slave id '117' does not match request '1'
nqv commented 9 years ago

@jonaz Sorry for late response. Do you see any other errors before:

015/07/20 20:31:18 modbus: response slave id '241' does not match request '1'

It would be great if you have request/response logged somewhere so I can take a look. I guess a frame is corrupted and it is not flushed properly.