Connection pooling in modbus binding

Thanks, this helps.

It can read something from the slave:
`19:21:52.888 [TRACE] [i.modbus.io.ModbusRTUTransport:127 ] - Managed to read at least one byte``
but when reading rest of the response, the serial library returns EOF immediately it seems (notice the same timestamp):

19:21:52.888 [ERROR] [i.modbus.io.ModbusRTUTransport:171  ] - Last request: 01 01 00 02 00 01 5c 0a
19:21:52.888 [ERROR] [i.modbus.io.ModbusRTUTransport:172  ] - failed to read: Error reading response (EOF)

Basically we would expect that the EOF error comes only after timeout has elapsed. The default timeout is 1500ms = 1.5 seconds:

19:21:52.898 [ERROR] [w.m.io.ModbusSerialTransaction:199 ] - execute try 1/3 error: I/O exception - failed to read. Request: net.wimpi.modbus.msg.ReadCoilsRequest@511d78d1 (unit id 1 & transaction 1). Serial parameters: SerialParameters@102c4d88[portName=COM6,baudRate=38400,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=none,encoding=rtu,echo=false,receiveTimeoutMillis=1500]

I have a bad feeling that this issue might be platform dependent – not sure I know how the serial library openhab really works with different platforms.

Do you have the issue with other tools, such as modpoll?

I’m not test with modpol, but with PLC Simulator, it was no problem all work, logfile.

starting modpoll I have this result logfile

Actually I meant that you would try to read data with modpull. Please keep openhab closed at this time.

If you could then paste the modpoll output, that would be most useful.

Their website has pretty good documentation on the usage but I’m happy to help if needed.

Good day, ssalonen.

I test device with modpoll and received such a result:

modpoll -b 34800 -p none -m rtu -a 1 -r 1 -c 5 -t 0 COM4
modpoll 3.4 - FieldTalk™ Modbus(R) Master Simulator
Copyright (c) 2002-2013 proconX Pty Ltd
Visit http://www.modbusdriver.com for Modbus libraries and tools.

Protocol configuration: Modbus RTU
Slave configuration…: address = 1, start reference = 1, count = 5
Communication…: COM4, 34800, 8, 1, none, t/o 1.00 s, poll rate 1000 ms
Data type…: discrete output (coil)

– Polling slave… (Ctrl-C to stop)
Reply time-out!
– Polling slave… (Ctrl-C to stop)
Reply time-out!

Intresting result. First of all I test modpoll on my simulator program, be sure to select the correct settings of modpoll option.

with simulator

modpoll -b 34800 -p none -m rtu -a 1 -r 1 -c 5 -t 0 COM14
modpoll 3.4 - FieldTalk™ Modbus(R) Master Simulator
Copyright (c) 2002-2013 proconX Pty Ltd
Visit http://www.modbusdriver.com for Modbus libraries and tools.

Protocol configuration: Modbus RTU
Slave configuration…: address = 1, start reference = 1, count = 5
Communication…: COM14, 34800, 8, 1, none, t/o 1.00 s, poll rate 1000 ms
Data type…: discrete output (coil)

– Polling slave… (Ctrl-C to stop)
[1]: 0
[2]: 1
[3]: 1
[4]: 1
[5]: 0
– Polling slave… (Ctrl-C to stop)
[1]: 0
[2]: 1
[3]: 1
[4]: 1
[5]: 0

then I change programm in Arduino (other modbus library) and test device on modpol:

modpoll -b 38400 -p none -m rtu -a 1 -r 20 -c 5 -t 0 COM3

Protocol configuration: Modbus RTU
Slave configuration…: address = 1, start reference = 20, count = 5
Communication…: COM3, 38400, 8, 1, none, t/o 1.00 s, poll rate 1000 ms
Data type…: discrete output (coil)

– Polling slave… (Ctrl-C to stop)
[20]: 1
[21]: 0
[22]: 0
[23]: 0
[24]: 0

below you can see results with openhab:
my openhab.cfg

openhab.log in debug mode
I have response to switch on localhost page.

I’m so sorry but I’m quite confused with the openhab logs you are pasting and the different devices you are trying out… If I understood correctly you have communication issue with modpoll as well as the openhab when communicating with real device.

If I understood correctly it seems to work with Arduino (COM3) but not real device (COM4)?

excuse me, I want to do everything at once.
I confuse you with COM ports because I run modpoll with simulator via 0-modem emulator (COM14 in logs). it was necessary, it mean I correctly set option to modpoll.
Then I change modbus library in Arduino and received normal ping via modpoll<->Arduino (COM3).
After correcting openhab.cfg to last working condition of Arduino I receive a new openhab.log
once again I apologize for confusion.

1 Like

what is the arduino code you are using. I have a couple arduinos I can program and test with as well.

at first time i use this library (arduino-modbus-slave). this library apprehensive to read registers and good worked with modbus-master simulators. finally modpoll don’t recognized registers from arduino.
then I saw one example where was table with registers, so I knew data accordance. i try to connect this library (Modbus-Master-Slave-for-Arduino) with modpoll and have nice result. now i use this library.

I’m trying to get more information whether this behaviour is expected with windows and whether there is some parameter or similar that needs to be set on windows…

It would be excellent if someone else could reproduce the EOF issue with windows as well. @LeXLuther422 and/or @mbs38, can you test how the Modbus/RTU serial works with windows?

Best
Sami

I’ll do some testing. It might take a couple of days - I need to get myself a virtual Windows machine first :wink:

1 Like

interesting things happened. I reinstall drivers to my USB adapter, try to connect with arduino and it become respond to openhab. but with some errors.
do you have some ideas about it.

openhab.cfg

openhab.log

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.