Connection pooling in modbus binding

Hi thanks for the new log!

The log seems quite similar than before? Sometimes not even three times is not enough for a successful response read, sometimes it works with less retries.

As before, it seems that EOF is received before 1.5seconds (ie receive timeout) elapses, something that we did not observe with @mbs38 linux openhab. The root cause for the discrepency is unknown to me. It does seem to be certain that the 3rd party serial library (nrjavaserial) openhab uses behaves differently. Not sure whether it is the library, os differences, or actual differences between devices or drivers.

I forgot to mention it here but I have asked for support in the serial library openhab uses. Also mentioned this in the pull request. So far no reply from anywhere…

I wonder who’s behind the serial binding, probably he/she would have a lead regarding this.

Best
Sami

@ssalonen I’ve finally tested it on a Windows 7 32bit system. Works without any problems and seems to be just as fast as on Arch Linux.

Configuration: http://pastebin.com/KWvJjN0M

Best Regards, Max

1 Like

Thank you very much for taking the time to test it.

Good to hear it works it works!

Just for the record, the feature has been merged, and release milestone has been set to 1.9.0.

Thank you very much for your help testing the binding!

Best,
Sami

Hello
Is there any way to use this binding for RTU over TCp ?

thank you

Hi.

I’ve tried the new version.
I do not know whether it supports my configurations file.

poll=10000
writemultipleregisters=true

# Read kWh & kW from EM23 El Meter
serial.em23.connection=/dev/ttyUSB0:9600:8:none:1:rtu:1000
serial.em23.id=1
serial.em23.start=12
serial.em23.length=3
serial.em23.type=input

# Read Nilan Temp
serial.nilan.connection=/dev/ttyUSB0:19200:8:even:1:rtu:1000
serial.nilan.id=30
serial.nilan.valuetype=int16
serial.nilan.start=203
serial.nilan.length=6
serial.nilan.type=input

# Read Nilan RH
serial.nilan2.connection=/dev/ttyUSB0:19200:8:even:1:rtu:1000
serial.nilan2.id=30
serial.nilan2.valuetype=int16
serial.nilan2.start=221
serial.nilan2.length=1
serial.nilan2.type=input

# Read Nilan AlarmStatus
serial.nilan3.connection=/dev/ttyUSB0:19200:8:even:1:rtu:1000
serial.nilan3.id=30
serial.nilan3.valuetype=int16
serial.nilan3.start=400
serial.nilan3.length=10
serial.nilan3.type=input

# Read/Write Nilan ControlSet
serial.nilan4.connection=/dev/ttyUSB0:19200:8:even:1:rtu:1000
serial.nilan4.id=30
serial.nilan4.start=1001
serial.nilan4.length=4
serial.nilan4.type=holding

# Read/Write Nilan Speed
serial.nilan5.connection=/dev/ttyUSB0:19200:8:even:1:rtu:1000
serial.nilan5.id=30
serial.nilan5.start=200
serial.nilan5.length=2
serial.nilan5.type=holding

It works fine if I only connect to one device, Nilan or EM23.

Should it be possible to connect to both with just one USB device?

This is the errors i see in the log:

2016-07-09 06:55:55.465 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 04 00 0c 00 03 70 08
2016-07-09 06:55:55.466 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2016-07-09 06:55:55.469 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/3 error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@63a5e4 (unit id 1 & transaction 165). Serial parameters: SerialParameters@1985547[portName=/dev/ttyUSB0,baudRate=19200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2016-07-09 06:55:57.985 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 04 00 0c 00 03 70 08
2016-07-09 06:55:57.986 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2016-07-09 06:55:57.989 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 2/3 error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@63a5e4 (unit id 1 & transaction 165). Serial parameters: SerialParameters@1985547[portName=/dev/ttyUSB0,baudRate=19200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2016-07-09 06:56:00.505 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 04 00 0c 00 03 70 08
2016-07-09 06:56:00.506 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2016-07-09 06:56:00.508 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 3/3 error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@63a5e4 (unit id 1 & transaction 165). Serial parameters: SerialParameters@1985547[portName=/dev/ttyUSB0,baudRate=19200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2016-07-09 06:56:00.510 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 3, throwing last error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@63a5e4. Serial parameters: SerialParameters@1985547[portName=/dev/ttyUSB0,baudRate=19200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2016-07-09 06:56:00.511 [ERROR] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (em23): Error getting modbus data for request net.wimpi.modbus.msg.ReadInputRegistersRequest@63a5e4. Error: I/O exception - failed to read. Endpoint ModbusSerialSlaveEndpoint@7f71ee[portName=/dev/ttyUSB0]. Connection: SerialConnection@d687e0[portName=/dev/ttyUSB0,port=/dev/ttyUSB0]

Hope someone can help… Thanks.

Certainly it works with many devices. Can you please confirm what version of modbus binding you are running?

I also noticed that you have different baud rates with slaves – even though they are connected via same serial port. That might cause issues…

Best
Sami

Hi, rtu over tcp is not supported currently. Perhaps you would like to open separate thread about this?

Best,
Sami

Hi.

I use this version.

yes I have different baud rate, but this can unfortunately not be changed on the devices.

@carzten2000, please find the late official 1.9.0 snapshot version here. I recommend using the above official development version instead of the custom build you are currently using (now that the new functionality is merged). I’m afraid that it’s unlikely that it works even there due to different baud rates.

So it works if you remove the slave having different baud rate, eg em23?

I believe there was discussion in this thread regarding the challenges of having different baud rates in the same line. I’m not sure you can really get that working reliably… But perhaps some one else has more information on this?

Technically speaking the binding currently configures (baud rate, parity etc) the serial port in the very beginning, and does not change it afterwards. That alone now causes issues for you as the baud rate would have to be reconfigured again and again to match the slave device requirements. This detail is easy to change though… We could try it out if you like?

Hi.

Yes, everything is working great when I remove the connection to the device em23.
So it is because of the differnet baud rates.

that would be greet if you want to change the binding so i can test it.

@carzten2000 Please try out this version and report back please. Now this version re-configures the serial port after every transaction.

Best,
Sami

Hi.

I’am still getting the same error.

2016-07-12 09:27:15.321 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 04 00 0c 00 03 70 08
2016-07-12 09:27:15.323 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2016-07-12 09:27:15.327 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/3 error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@392119 (unit id 1 & transaction 3). Serial parameters: SerialParameters@38130d[portName=/dev/ttyUSB0,baudRate=19200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2016-07-12 09:27:17.195 [INFO ] [marthome.event.ItemStateChangedEvent] - room08_room_temp changed from 22.60 to 22.50
2016-07-12 09:27:17.841 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 04 00 0c 00 03 70 08
2016-07-12 09:27:17.848 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2016-07-12 09:27:17.850 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 2/3 error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@392119 (unit id 1 & transaction 3). Serial parameters: SerialParameters@38130d[portName=/dev/ttyUSB0,baudRate=19200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2016-07-12 09:27:20.361 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 01 04 00 0c 00 03 70 08
2016-07-12 09:27:20.362 [ERROR] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)
2016-07-12 09:27:20.364 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute try 3/3 error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@392119 (unit id 1 & transaction 3). Serial parameters: SerialParameters@38130d[portName=/dev/ttyUSB0,baudRate=19200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2016-07-12 09:27:20.365 [ERROR] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 3, throwing last error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadInputRegistersRequest@392119. Serial parameters: SerialParameters@38130d[portName=/dev/ttyUSB0,baudRate=19200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=1500]
2016-07-12 09:27:20.367 [ERROR] [.binding.modbus.internal.ModbusSlave] - ModbusSlave (em23): Error getting modbus data for request net.wimpi.modbus.msg.ReadInputRegistersRequest@392119. Error: I/O exception - failed to read. Endpoint ModbusSerialSlaveEndpoint@1b70321[portName=/dev/ttyUSB0]. Connection: SerialConnection@6c8b5f[portName=/dev/ttyUSB0,port=/dev/ttyUSB0]

It does not look like the baud rate is changing.

If I remember correctly, the binding prints summary of parsed slaves in the beginning . That should make it clear what baud etc will be used.

Can you repeat the test with debug level logging and paste the relevant log snippet here? you can find instructions to logging configuration from the modbus binding wiki page

Best
Sami

The whole idea of mixing speed/parity modes etc. down a single wire seems a bit perilous. In theory, the timing of RTU inter-message gaps and suchlike is set by linespeed. Even if cleverness could be worked into the binding to make safe allowances at the master end, you can’t predict how the slaves are going to cope.

The Modbus RTU specification states
"The transmission mode (and serial port parameters) must be the same for all devices on a MODBUS Serial Line."
which means that slave designers need not handle the case in any sensible way.
Reminder - it is possible the particular problem being attacked here is slave-based i.e. one of the devices is entering error recovery when it sees “gibberish” intended for another slave.

Also think that trying to get the binding to cope with it is essentially wasted effort for non-compliant cases. Personally I wouldn’t like to guess how well different hardware and operating system hosts would handle rapid reconfiguring of serial ports to make it feasible anyway.

The “correct” solution here is to set up two serial buses (would that just be a second USB<>RS485 adaptor in this case?)

1 Like

@ssalonen

After reading the reply from @rossko57 I thing that best solution would be to just ad another usb<>rs485.
I going to test this next week, and I will report back with the result.

I didn’t mean to sound snippy about it, like “you can’t do that” !

I’m sure it would work in many cases. The difficulty is that in cases where it doesn’t work properly, the problem may lie in some ‘Black Box’ (Operating system, serial adaptor, modbus slave) outside of your control. No-one will be interested in fixing those because they won’t be seen as broken - “That is not the way to use them”. Note that fully-featured modbus slaves would be counting up more errors than good transfers.
Worse case, you get it working - but then later some small change in host or slave breaks it. Me, I just wouldn’t risk that.

Please do let us all know if multiple serial buses works for you - that may be an untested case (so far) for the OH binding.

Really good that you brought this up! Indeed from the perspective of the rtu slave it is really bad situation if there are many baud rates on the same line.

Therefore will leave the binding as is and looking forward to hear the feedback from the test.

Hi @rossko57 and @ssalonen

I have now tried with an extra usb <> rs485 device.
And it is working :slight_smile:

Thanks :slight_smile:

This is the configration:

poll=10000
writemultipleregisters=true

# Read kWh & kW from EM23 El Meter
serial.em23.connection=/dev/ttyUSB1:9600:8:none:1:rtu:1000
serial.em23.id=1
serial.em23.start=12
serial.em23.length=3
serial.em23.type=input

# Read Nilan Temp
serial.nilan.connection=/dev/ttyUSB0:19200:8:even:1:rtu:1000
serial.nilan.id=30
serial.nilan.valuetype=int16
serial.nilan.start=203
serial.nilan.length=6
serial.nilan.type=input

# Read Nilan RH
serial.nilan2.connection=/dev/ttyUSB0:19200:8:even:1:rtu:1000
serial.nilan2.id=30
serial.nilan2.valuetype=int16
serial.nilan2.start=221
serial.nilan2.length=1
serial.nilan2.type=input

# Read Nilan AlarmState
serial.nilan3.connection=/dev/ttyUSB0:19200:8:even:1:rtu:1000
serial.nilan3.id=30
serial.nilan3.valuetype=int16
serial.nilan3.start=400
serial.nilan3.length=10
serial.nilan3.type=input

# Read/Write Nilan ControlSet
serial.nilan4.connection=/dev/ttyUSB0:19200:8:even:1:rtu:1000
serial.nilan4.id=30
serial.nilan4.start=1001
serial.nilan4.length=4
serial.nilan4.type=holding

# Read/Write Nilan Speed
serial.nilan5.connection=/dev/ttyUSB0:19200:8:even:1:rtu:1000
serial.nilan5.id=30
serial.nilan5.start=200
serial.nilan5.length=2
serial.nilan5.type=holding

Thank you for reporting back. Great to hear it is working!

Clarified this bit in the wiki