[SOLVED] Modbus connection on USB

  • Platform information: Raspberry PI 3

Hallo I have many problems during the configuration of a MODBUS connection on a USB.
This is my configuration:

modbus.things

Bridge modbus:serial:localSerial [port="/dev/ttyUSB0", id=1, baud=19200, stopBits="1", parity="none", dataBits=8, encoding="rtu"]
    {Bridge poller inputs [start=4267, length=2, refresh=1000, type="holding" ] 
        {Thing data ggg [ readStart="4267", readValueType="float32"]}

modbus.sitemaps

sitemap modbus label="My home" 
    {Frame label="Date" 
        {
          Text item=ggg label="Holding1501 out[%.1f °C]"
        }
    }

Modbus.items

Number ggg "Holding1501 [%.1f]" <temperature> {channel="modbus:data:localSerial:inputs:ggg:number"}

The usb device starts flashing the light of communication but no data could be read.
This is the log.

2019-11-02 09:29:22.349 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Error getting a new connection for endpoint ModbusSerialSlaveEndpoint@5e791c[portName=/dev/ttyUSB1]. Error was: java.lang.InterruptedException null

2019-11-02 09:29:22.353 [INFO ] [rt.modbus.internal.ModbusManagerImpl] - Poll task BasicPollTaskImpl@9dd96b[request=ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@5a3888[slaveId=0,functionCode=READ_MULTIPLE_REGISTERS,start=4267,length=2,maxTries=3],endpoint=ModbusSerialSlaveEndpoint@5e791c[portName=/dev/ttyUSB1],callback=org.openhab.binding.modbus.internal.handler.ModbusPollerThingHandlerImpl$ReadCallbackDelegator@7ebc18d8] canceled

2019-11-02 09:29:22.355 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Could not connect to endpoint ModbusSerialSlaveEndpoint@5e791c[portName=/dev/ttyUSB1] – aborting request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@5a3888[slaveId=0,functionCode=READ_MULTIPLE_REGISTERS,start=4267,length=2,maxTries=3] [operation ID 7605f5d6-a08b-4fc6-90b3-5edc791a2cf6]

The Modbus binding cannot use ttyUSB1.
Perhaps your device is called something else.
Perhaps another service is using it.
Perhaps openHAB doesn’t have permissions to use it.

It is a bit strange that it wants to use ttyUSB1, because your Thing is configured for ttyUSB0 and there is no mention of that in the errors that you have shown us.

If you have been editing your Things, I would recommend a binding restart or a system reboot now. Changes in Things do not make it into pollers that are already running.

Ok thanks i solved,
Just rebooting few time the system It starts to run correctly.

But by now every time i reboot the system maybe the usb Port changes.
I notice It on Raspberry 3.
On Raspberry 4 I think i understand It Is not true. It seems that USB doesn’t change.

Is It true?

And on Rsby 3 how i can have a USB Port make forced?
Thanks

Read about udev rules:

When using more than one USB-Serial converters, it may happen that the /dev/ttyUSB0 device is named /dev/ttyUSB1 after a reboot. To prevent this problem, alias names can be assigned to serial devices by adding them to /etc/udev/rules.d/99-com.rules .

See this:

And this:

:wink:

1 Like

Please!.
I did it seeing

so it appens very a strange thing…
Starting work well for more minutes then when i try to change the refresh time of polling it stops work and doesn’t start anymore.

this is the error message.

==> /var/log/openhab2/openhab.log <==
2019-11-15 16:15:34.433 [ERROR] [et.wimpi.modbus.net.SerialConnection] - Could not get port identifier, maybe insufficient permissions. gnu.io.NoSuchPortException: null

==> /var/log/openhab2/events.log <==
2019-11-15 16:15:34.435 [hingStatusInfoChangedEvent] - 'modbus:data:rtu1:bloccoenergia:energia1' changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE

==> /var/log/openhab2/openhab.log <==
2019-11-15 16:15:34.436 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - connect try 1/1 error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@1cfd9e4[portName=/dev/ttyUSBGed,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@d512e0[portName=/dev/ttyUSBGed]

2019-11-15 16:15:34.437 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - re-connect reached max tries 1, throwing last error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@1cfd9e4[portName=/dev/ttyUSBGed,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@d512e0[portName=/dev/ttyUSBGed]

2019-11-15 16:15:34.438 [ERROR] [ing.ModbusSlaveConnectionFactoryImpl] - Error connecting connection SerialConnection@1cfd9e4[portName=/dev/ttyUSBGed,port=<null>] for endpoint ModbusSerialSlaveEndpoint@d512e0[portName=/dev/ttyUSBGed]: Could not get port identifier, maybe insufficient permissions. null

2019-11-15 16:15:34.440 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Could not connect to endpoint ModbusSerialSlaveEndpoint@d512e0[portName=/dev/ttyUSBGed] -- aborting request ModbusPollerThingHandlerImpl.ModbusPollerReadRequest@165451a[slaveId=1,functionCode=READ_MULTIPLE_REGISTERS,start=4131,length=4,maxTries=3] [operation ID f0b95356-aa48-47fd-a50f-0d64cef82809]

2019-11-15 16:15:34.441 [ERROR] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:rtu1:bloccoenergia:energia1 'Modbus data' had ModbusConnectionException error on read: ModbusConnectionException(Error connecting to endpoint=ModbusSerialSlaveEndpoint@d512e0[portName=/dev/ttyUSBGed])

==> /var/log/openhab2/events.log <==
2019-11-15 16:15:34.447 [hingStatusInfoChangedEvent] - 'modbus:data:rtu1:bloccoenergia:energia1' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR)

2019-11-15 16:15:34.451 [hingStatusInfoChangedEvent] - 'modbus:poller:rtu1:bloccoenergia' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error with read: org.openhab.io.transport.modbus.ModbusConnectionException: Error connecting to endpoint ModbusSerialSlaveEndpoint@d512e0[portName=/dev/ttyUSBGed]

2019-11-15 16:15:34.455 [hingStatusInfoChangedEvent] - 'modbus:data:rtu1:bloccoenergia:energia1' changed from OFFLINE (COMMUNICATION_ERROR) to ONLINE


This is the /etc/default/openhab2
EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSBGed"

And given membership to openhab user for “dialout” and “tty”

How are you doing that?

Previous comment -

I was trying the polling time. Buy i tried more time redooting. It doesn’t work

If you have been editing your Things, I would recommend a binding restart or a system reboot now. Changes in Things do not make it into pollers that are already running.

Do you recall @rossko57 why this is so? Is a known issue in the binding or openhab?

I was under impression that at least editing the things file is robust

It’s a conclusion I arrived at when investigating what happened with duplicate Thing IDs - once a poller “robot” had been created (I have no idea what the actual mechanism is!), it seemed to operate independently until binding reboot.

I cannot recall exactly, but I think for example if you actually edited a Thing UID the old poller would keep going alongside a new version.
I suspect there is a similar problem too with poller related parameters - like the poll period.

It might all be a horrible misinterpretation of what actually goes on :wink:

Yes. Ok. Do you understand my problema why It crashes?

You’re getting crashes now? Crashes of what?

Sorry not crashes! I meant the problem exposed in previous posts

This?
No, there’s nothing further to add.
You know the general nature of the problem already, the binding cannot get hold of the named serial port for some reason.
You had it working, and then changed somethiing, we don’t know what.
Advised a reboot, don’t know if you’ve done that.
Any messages from after the reboot will probably be helpful.

After few days it broke.

2020-12-07 21:24:34.671 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Error getting a new connection for endpoint ModbusSerialSlaveEndpoint@c4a289[portName=/dev/ttyUSB0]. Error was: java.lang.InterruptedException null
2020-12-07 21:24:34.672 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Could not connect to endpoint ModbusSerialSlaveEndpoint@c4a289[portName=/dev/ttyUSB0] -- aborting request ModbusReadRequestBlueprint@80a76c[slaveId=1,functionCode=READ_INPUT_REGISTERS,start=6,length=2,maxTries=3] [operation ID 6cee1894-6bee-43f5-ae13-7aafbaab8e87]

None of options work now. even restart raspberry or restart openhab or restart binding.

Do you have only this one error? InterruptedException in the logs usually indicate some changes being applied to Things (e.g. Editing things file), binding gracefully cancels everything that it is doing asap. I would not expect same error to come after this.

If you´re running linux of any kind, you probably need to reinitialise the USB dongle again, unless you have set it up for static USB devices through symlinks.
This is a very common issue with linux and USB devices, which has been driven me nuts for years now. Happens each time you reboot your system.