Modbus Binding Version 1 on OpenHAB2

Hello,

I’m trying to connect my openHAB2 to the PLC using Modbus Binding Version 1 (with modbus.cfg)

Current modbus cfg that I have is :

poll=500

tcp.slave1.connection=192.168.0.105
tcp.slave1.type=coil
tcp.slave1.start=0
tcp.slave1.length=9

tcp.slave2.connection=192.168.0.105
tcp.slave2.type=holding
tcp.slave2.start=0
tcp.slave2.length=9

Error log comes out like this :

22:02:52.693 [ERROR] [net.wimpi.modbus.net.SerialConnection] - Could not get port identifier, maybe insufficient permissions. null
22:02:52.694 [ERROR] [ling.ModbusSlaveConnectionFactoryImpl] - connect try 1/3 error: Could not get port identifier, maybe insufficient permissions. null. Connection SerialConnection@76322f4c[portName=192.168.0.105,port=<null>]. Endpoint ModbusSerialSlaveEndpoint@3570a6aa[portName=192.168.0.105]

The problem is, on the slave1, it’s always read as serial connection. I’ve tried to change it to slave2 and slave3. But it still try connect to the slave1 even I’m not using it anymore. Can anyone help me with this ? Or should I use the previous version of openHAB instead of openHAB2 ?

The other problem, for the holding type. Why is it not responding to any input that I make to the PLC ? Is there anything that I need to configure before connecting it to the PLC ?

Hope you can understand it.
Thanks,

Randi

Hello Randi,
I think your configuration is missing port ( It’s said that in error log )

My modbus.cfg file for serial connection :

serial.slaveinput.connection=COM3:9600:8:even:1:rtu:35:1500:none:none
serial.slaveinput.type=input
serial.slaveinput.id=1
serial.slaveinput.start=2000
serial.slaveinput.length=24
serial.slaveinput.valuetype=uint16

serial.slaveholding.connection=COM3:9600:8:even:1:rtu:35:1500:none:none
serial.slaveholding.type=holding
serial.slaveholding.id=1
serial.slaveholding.start=2000
serial.slaveholding.length=12
serial.slaveholding.valuetype=uint16

for more infomation Modbus Binding

For easy to help, you should give some information about your system :

  • Version OpenHAB
  • Which OS that your OpenHAB run on ( Linux, Windows, MacOS, … )
  • Version Java JDK

Hello @KevinHab. Thank you for your response.

Here is my system :

  • I’m using openHAB2
  • Windows 10 OS
  • Java JDK 1.8.0_162

The problem is, if I put in port configuration in modbus.cfg, openHAB will read it as baud rate not as port configuration. And for the other slave except slave1, there is no problem in reading the port configuration.

Maybe there is another advice for the configuration ?

Thanks,

Randi

The first, check connection from OS to PLC. You can use ModbusTools software to check it. ( the same as image below )
Capture

The second, can you give some information about your PLC modbus setting ( ex : port, ip address, … )

P/S : With Modbus RTU over TCP

Some devices uses modbus RTU over TCP. This is usually Modbus RTU encapsulation in an ethernet packet. So, those devices does not work with Modbus TCP binding since it is Modbus with a special header. Also Modbus RTU over TCP is not supported by Openhab Modbus Binding. But there is a workaround: you can use a Virtual Serial Port Server, to emulate a COM Port and Bind it with OpenHab unsing Modbus Serial.

Hi

This is my modbus configuration, just changed the IP adress to xxx.xxx.xxx.xxx:
I’m using OH2.2 and have no problems.

tcp.slave1.connection=xxx.xxx.xxx.xxx:502:60:0:0:3:100
tcp.slave1.start=70
tcp.slave1.length=50
tcp.slave1.type=holding

tcp.slave2.connection=xxx.xxx.xxx.xxx:502:60:0:0:3:100
tcp.slave2.start=0
tcp.slave2.length=50
tcp.slave2.type=coil

tcp.slave3.connection=xxx.xxx.xxx.xxx:502:60:0:0:3:100
tcp.slave3.start=0
tcp.slave3.length=20
tcp.slave3.type=holding

tcp.slave4.connection=xxx.xxx.xxx.xxx:502:60:0:0:3:100
tcp.slave4.start=20
tcp.slave4.length=50
tcp.slave4.type=holding

tcp.slave5.connection=xxx.xxx.xxx.xxx:502:60:0:0:3:100
tcp.slave5.start=210
tcp.slave5.length=20
tcp.slave5.type=holding

Hope this hepls

Sorry for the late reply.

I’m already test it again yesterday using this configuration:

poll=500

tcp.slave2.connection=192.168.0.105
tcp.slave2.type=coil
tcp.slave2.start=0
tcp.slave2.length=9

tcp.slave3.connection=192.168.0.105
tcp.slave3.type=holding
tcp.slave3.start=0
tcp.slave3.length=9

And it works. And after trying using so much slave id, I find out that for my laptop, slave1 is reserved for serial connection. And the other slave can be tcp or serial. I’ve test it using slave2 - slave15 and slave255 and it works using tcp connection. It’s only slave1 that using serial connection “only”. I think using any other slave is fine as long it works for me.

I have another question for modbus binding communication. I’m using Poll Modbus from my handphone to test the read/write action on the PLC. And there is 1 little problem. If I change any coil or holding register state from openHAB, Poll Modbus read it so fast, but otherwise, if I change it from Poll Modbus, openHAB not read it that fast. Sometimes it has delay for about 10-30 seconds. Is it normal for openHAB to having any delay like that ? Btw, I’m only using local connection, not using internet connection yet. I want to make sure openHAB can communicate with PLC first.

Sorry for my bad english.

Thanks,

Randi

Thanks for your response @jcurado.

I’ve found out that openHAB on my laptop already reserved slave1 as serial connection “only”. I’ve tried using another slave and it works well using tcp connection. I don’t know what is wrong with my openHAB, but as long as openHAB can communicate with PLC using any other slave, it’s fine by me.

Thanks,

Randi

The problem with slave1 – it sounds like some sort of caching of things:

See my comment:

It might be issue with openHAB itself…

Regarding the delay, I do not think it’s normal. The updates should be very fast. Can you confirm that “Poll Modbus” writes the value instantly, e.g. using 3rd party polling tool, e.g. modpoll?

Sami

I have same problem above with serial communication. I don’t know why, either. I tried setting baud rate higher, or poll time faster, but can’t change anything, the problem still exists.

Can you reproduce the slowness of updates with e.g. Modpoll?

So basically using “Poll modbus” to write data and having modpoll constantly polling in the background .

Best
Sami

I’ll try to use modpoll to do the polling in the background on the next test.

There is something that I found from today test using both local connection and internet connection using openHAB cloud. OpenHAB not always slow when reading input from Poll Modbus. Sometimes it only take a few seconds to read input from it. But when openHAB try to connect to slave1, it’s slow to read. Maybe I should consider to remove slave1 from openHAB if possible ?

Thanks,

Randi

Yep, it probably helps to remove configuration that gives errors. Check out this Modbus Log -> Erro Item that doesn´t exists anymore

The retries take some time which might explain the slowness.

sorry for the late reply again sir.

After I remove the previous configuration by following this, the only reason why the slowness still happen is because my internet network speed that’s not good enough. Thanks a lot for your help sir!:smile: