Modbus / Serial Connection with USB

Morning Lads,
i finally give up.

I dont get the Serial Connection to work (or at least the Modbus binding).
Doing exactly the same setup with the “modpoll” tool, everything works like a charm.

Here some more Infos:

Setup: Raspberry Pi 4 - Openhabian - 3.4.3
Modbus USB Device: This

SYMLINK:
SUBSYSTEM==“tty”, ATTRS{idVendor}==“1a86”, ATTRS{idProduct}==“7523”, SYMLINK+=“ttyUSB-MODBUS”, GROUP=“dialout”, MODE=“0660”

(which works like a charm with modpooll)

EXTRA_JAVA_OPTS=

What else to say? I even did this:

sudo usermod -a -G tty openhab
sudo usermod -a -G dialout openhab

Error Message:

2023-05-05 15:26:52.502 [WARN ] [ing.ModbusSlaveConnectionFactoryImpl] - Connect reached max tries 1, throwing last error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection [m_SerialPort=null, m_Parameters.getPortName()=/dev/ttyUSB-MODBUS]. Endpoint ModbusSerialSlaveEndpoint [getPortName()=/dev/ttyUSB-MODBUS]

2023-05-05 15:26:52.503 [WARN ] [ing.ModbusSlaveConnectionFactoryImpl] - Error connecting connection SerialConnection [m_SerialPort=null, m_Parameters.getPortName()=/dev/ttyUSB-MODBUS] for endpoint ModbusSerialSlaveEndpoint [getPortName()=/dev/ttyUSB-MODBUS]: Could not get port identifier, maybe insufficient permissions. null

2023-05-05 15:26:52.505 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Could not connect to endpoint ModbusSerialSlaveEndpoint [getPortName()=/dev/ttyUSB-MODBUS] – aborting request ModbusReadRequestBlueprint [slaveId=41, functionCode=READ_INPUT_REGISTERS, start=40, length=100, maxTries=1] [operation ID e50a9a94-e52a-4691-ba5e-54ef4b5cca64]

Screenshots:

I am done with this. I have no idea what else i can do.
I really hope for some help here. If you need anything else, just ask me. I can provide everything you want and maybe i forget something.

Thank you very much.
Marcel

I don’t do modbus so my ability to help will be somewhat limited. I can provide help with some of the basics though.

  1. modpooll is not running when you try to run Oh, right? Only one program can have a lock on the device at a time.

  2. Try a reboot of the machine. Sometimes when a program exists (i.e. modpooll) it doesn’t properly free up the lock on the device.

  3. What’s the ownership/permissions on /dev/ttyUSB-MODBUS?

  4. That looks like a symbolic link to the physical device. As an experiment, does it work if you connect to the actual device e.g ttyUSB1?

  5. Adding both the original device and the symbolic link on the EXTRA_JAVA_OPTS might be causing problems where OH gets a lock on the physical device and then fails on the symbolic link because a lock already exists (or vise versa). Though I’m not certain these opts are even required so as an experiment you can try without them.

The error could indicate either the file isn’t there, the file’s permissions don’t allow the openhab user to read/write, or there is a lock on the file. So figuring out which of these is the case and why is the path to move forward.

Creating a Symlink is not mandatory. So to narrow down the problem I would try without it.
Only select the Serial Port that is given by the system in the thing configuration:

If this works you can still create a symlink after.

Also it would be interesting if your OpenHAB configuration is working an an other OS.
So to make a quick test, I would try it with OpenHAB running Windows.

  1. modpoll did run while openhab was open.
  2. Tried reboot couple of times.
  3. how can i check this?
  4. of course i also tried the “direct” way - the symlink is because i have multiple USB-Sticks (Enocean / Zigbee / Modbus)
  5. I will remove ttyUSB0 and ttyUSB1 from the JAVA_OPTS Part.

Will check again

thank you very much for your reply.

I did tried ttyUSB0 / ttyUSB1 directly. But have exactly the same error.

ls -l /dev/*

Or to just check the one file

ls -l /dev/ttyUSB1

This is the result.
And yes i did multiple symlinks on the same Device. I will delete one of them, but it doesnt matter. :slight_smile:

  1. I will remove ttyUSB0 and ttyUSB1 from the JAVA_OPTS Part. → Didnt resolve the problem.

And make sure that user openhab is indeed a member of dialout.

id openhab

It should be after those usermods but when debugging a problem make no assumptions.

And if you remove them all? Adding them to EXTRA_JAVA_OPTS shouldn’t be necessary in the first place.

Well it looks like it is part of the group.

I comment out the line and I’m doing a reboot.

Let’s see in a second.

Still the same.

At this point I think we need a modbus expert to chime in. The only remaining test I can suggest is to try the ttyUSB device instead of the symbolic link just to eliminate as much as possible things that could be getting in the way.

Did try it. But not working yet. Thank you very much for your help. I really appreciate it.

Hopefully someone else have further ideas.

Best wishes
Marcel

According to your screenshots you have two rows containgin EXTRA_JAVA_OPTS. The second line overwrites the content of the first line.
So I think ( at least according to these screenshots ) you have never used the serial port settings in that environment variable.

Hi Wolfgang,
I already thoguth about this. But I am not sure how to merge both lines.

Could you provide a solution in a one-liner?

With screenshots I can`t do copy and paste …

Put the complete part on the right side of the equal sign in double quotes.
Use space as separator between the parts you would like to concatenate.
The row that is there as a comment ( starting with # ) shows an example of arguments that are concatenated and separated by a space.

Gimme a second.

Ok… Need a bit longer. Have to copy it from a laptop and a putty session as I am currently not at home.

But I was able comment and uncomment the certain lines.

Machine is rebooting. Let’s see. :slight_smile: I will reply in a bit.
Thank you very much for your help!

Regards
Marcel

Looks like you’re right. Or at least your hint brought me to the next step.
I cannot confirm this 100% but the error messages changed.

But I will verify this in 1-2 hours.

Thanks a lot and best wishes.
Marcel

1 Like

Back at home again.
I saw what you mean and did it like this:

I will restart and try again :slight_smile: