Phoenix Contact Buscoupler no coils or discrete inputs

I bought 2 phoenix contact buscouplers - IL ETH BK DI8 DO4 2TX-PAC

what it makes difficult to configure for me is that it does not support the “normal” function codes.

It supports only:
fc3 - Read Multiple Registers
fc4 - Read Input Registers
fc6 - Write Single Register
fc16 - Write Multiple Registers
fc23 - Read/Write Registers

The important ones are missing fc1 - fc2 - fc5

I thought it could work like this:

Here is the important part from my openhab.cfg:

modbus:poll=1000
modbus:writemultipleregisters=true

modbus:tcp.slave1.connection=192.168.0.20:502
modbus:tcp.slave1.type=input
modbus:tcp.slave1.id=1
modbus:tcp.slave1.start=8000
modbus:tcp.slave1.length=7
modbus:tcp.slave1.valuetype=bit

modbus:tcp.slave2.connection=192.168.0.20:502
modbus:tcp.slave2.type=holding
modbus:tcp.slave2.id=1
modbus:tcp.slave2.start=8007
modbus:tcp.slave2.length=3
modbus:tcp.slave2.valuetype=bit

here is the part from my *.items

Switch switch1 “Modbus 1” (EG_Kueche) {modbus=“slave2:0”}
Switch switch2 “Modbus 2” (EG_Kueche) {modbus=“slave2:1”}
Switch switch3 “Modbus 3” (EG_Kueche) {modbus=“slave2:2”}

My problem is that i only get 1 bit from each register.
How can i access the other bits???

A solution would be for example {modbus="slave2:0:0} to get acces to the bits i need but that does not work.

Am i doing something wrong is there no way to get it work?

Hi!

It’s no issue for the binding even if some of the functions are not supported

The binding only reads and writes what you ask. Naturally you cannot read or write coils (functions 1&5),nor you can read discrete inputs (function 2).

You can read the input and holding registers, however.

The bit is meant for getting single bit from the register. For more details, consult the wiki on valuetype parameter.

Regarding to your question, just increase the read index in the item configuration to read other bits. The bit addressing details are explained in wiki

Best
Sami

Hey Sami,

thank you for trying to help, but i trust me if i say i read everything i found before twice and found no solution.

i am german, maybe i dont understand it but here is my problem:

{modbus=“slave2:0”} reads Adress: 8007 bit 0
{modbus=“slave2:1”} reads Adress: 8008 bit 0
{modbus=“slave2:2”} reads Adress: 8009 bit 0

How to get bits 1-15?

Thanks for understanding, no offense meant! OK thanks for further clarification, I think we are on the sama page.

The three examples should refer to the same register (8007). Are you saying this not the case? With index 16 to 31 you are referring to second register (8008)

From the wiki explaining valuetype=bit:

a single bit is read from the registers
indices between 0…15 (inclusive) represent bits of the first register
indices between 16…31 (inclusive) represent bits of the second register, etc.
index 0 refers to the least significant bit of the first register
index 1 refers to the second least significant bit of the first register, etc.

In your case first register should be register 8007. You are not seeing this behaviour?

Best
Sami

Yes that’s exactly my problem.

If I increase the index it reads the first bit from next register instead of the next bit in the same register.

I tried with binding 1.8.3 and 1.9.0.b3

Hi @marcusjelsch!

I have tried to reproduce the issue with diagslave and pollmb, following the idea in wiki. I used openhab 1.8.2 (should not matter I think) with modbus binding 1.9.0 from cloudbees.

Unfortunately I could not reproduce any issue.

Can you please go through my findings and see if you anything that does not match your expectations? Can you repeat the test?

0. Openhab configuration

openhab.cfg

modbus:tcp.slave1.connection=127.0.0.1:55502
modbus:tcp.slave1.type=holding
modbus:tcp.slave1.length=2
modbus:tcp.slave1.valuetype=bit

default.items

Number ModbusItem0 "bit 0 [%d]" {modbus="slave1:0"}
Number ModbusItem1 "bit 1 [%d]" {modbus="slave1:1"}
Number ModbusItem2 "bit 2 [%d]" {modbus="slave1:2"}
Number ModbusItem3 "bit 3 [%d]" {modbus="slave1:3"}
Number ModbusItem4 "bit 4 [%d]" {modbus="slave1:4"}
Number ModbusItem5 "bit 5 [%d]" {modbus="slave1:5"}
Number ModbusItem6 "bit 6 [%d]" {modbus="slave1:6"}
Number ModbusItem7 "bit 7 [%d]" {modbus="slave1:7"}
Number ModbusItem8 "bit 8 [%d]" {modbus="slave1:8"}
Number ModbusItem9 "bit 9 [%d]" {modbus="slave1:9"}
Number ModbusItem10 "bit 10 [%d]" {modbus="slave1:10"}
Number ModbusItem11 "bit 11 [%d]" {modbus="slave1:11"}
Number ModbusItem12 "bit 12 [%d]" {modbus="slave1:12"}
Number ModbusItem13 "bit 13 [%d]" {modbus="slave1:13"}
Number ModbusItem14 "bit 14 [%d]" {modbus="slave1:14"}
Number ModbusItem15 "bit 15 [%d]" {modbus="slave1:15"}

Number ModbusItem16 "bit 16 [%d]" {modbus="slave1:16"}
Number ModbusItem17 "bit 17 [%d]" {modbus="slave1:17"}
Number ModbusItem18 "bit 18 [%d]" {modbus="slave1:18"}
Number ModbusItem19 "bit 19 [%d]" {modbus="slave1:19"}
Number ModbusItem20 "bit 20 [%d]" {modbus="slave1:20"}
Number ModbusItem21 "bit 21 [%d]" {modbus="slave1:21"}
Number ModbusItem22 "bit 22 [%d]" {modbus="slave1:22"}
Number ModbusItem23 "bit 23 [%d]" {modbus="slave1:23"}
Number ModbusItem24 "bit 24 [%d]" {modbus="slave1:24"}
Number ModbusItem25 "bit 25 [%d]" {modbus="slave1:25"}
Number ModbusItem26 "bit 26 [%d]" {modbus="slave1:26"}
Number ModbusItem27 "bit 27 [%d]" {modbus="slave1:27"}
Number ModbusItem28 "bit 28 [%d]" {modbus="slave1:28"}
Number ModbusItem29 "bit 29 [%d]" {modbus="slave1:29"}
Number ModbusItem30 "bit 30 [%d]" {modbus="slave1:30"}
Number ModbusItem31 "bit 31 [%d]" {modbus="slave1:31"}

default.sitemap

sitemap demo label="Main Menu" {
Text item=ModbusItem0 
Text item=ModbusItem1 
Text item=ModbusItem2 
Text item=ModbusItem3 
Text item=ModbusItem4 
Text item=ModbusItem5 
Text item=ModbusItem6 
Text item=ModbusItem7 
Text item=ModbusItem8 
Text item=ModbusItem9 
Text item=ModbusItem10 
Text item=ModbusItem11 
Text item=ModbusItem12 
Text item=ModbusItem13 
Text item=ModbusItem14 
Text item=ModbusItem15 
Text item=ModbusItem16 
Text item=ModbusItem17 
Text item=ModbusItem18 
Text item=ModbusItem19 
Text item=ModbusItem20 
Text item=ModbusItem21 
Text item=ModbusItem22 
Text item=ModbusItem23 
Text item=ModbusItem24 
Text item=ModbusItem25 
Text item=ModbusItem26 
Text item=ModbusItem27 
Text item=ModbusItem28 
Text item=ModbusItem29 
Text item=ModbusItem30 
Text item=ModbusItem31 

}

1. Start slave

$ ./diagslave -m tcp -p 55502

2. Write data using pollmb

(assumes pollmb script is available at subfolder pollmb)

First register:

$ pollmb/pollmb.py -h 127.0.0.1 -p 55502 -f 16 -a 0 -d 42C8

Contacting Modbus host at 127.0.0.1 port 55502 timeout 60.0 sec.
Sending Modbus function: 16, addr: 0, qty: 1, data: 42C8 for 1 polls at 1 msec
1: Reply was: function: 16, data: 0001

Second register:

$ pollmb/pollmb.py -h 127.0.0.1 -p 55502 -f 16 -a 1 -d aaaa

Contacting Modbus host at 127.0.0.1 port 55502 timeout 60.0 sec.
Sending Modbus function: 16, addr: 1, qty: 1, data: 1234 for 1 polls at 1 msec
1: Reply was: function: 16, data: 0001

For details, consult help using pollmb/pollmb.py.

Verify data

$ pollmb/pollmb.py -p 55502 -f 3 -a 0 -q 2

Contacting Modbus host at localhost port 55502 timeout 60.0 sec.
Sending Modbus function: 3, addr: 0, qty: 2, data: 0000 for 1 polls at 1 msec
1: Reply was: function: 3, data: 42c81234

Result in sitemap

http://localhost:8080/openhab.app

(newline added afterwards)

bit 0 0
bit 1 0
bit 2 0
bit 3 1
bit 4 0
bit 5 0
bit 6 1
bit 7 1
bit 8 0
bit 9 1
bit 10 0
bit 11 0
bit 12 0
bit 13 0
bit 14 1
bit 15 0

bit 16 0
bit 17 0
bit 18 1
bit 19 0
bit 20 1
bit 21 1
bit 22 0
bit 23 0
bit 24 0
bit 25 1
bit 26 0
bit 27 0
bit 28 1
bit 29 0
bit 30 0
bit 31 0

Note that (ref: hex-to-binary converter)

(42C8)16 = (0100 0010 1100 1000)2
(1234)16 = (0001 0010 0011 0100)2

If you read openhab bits “backards”

bits 15...0 : 0100 0010 1100 1000 (OK! matches (42C8)16 )
bits 31...16 : 0001 0010 0011 0100 (OK! matches (1234)16 )

Best,
Sami

Hi Sami,

this is the result:

marcus@marcus-AOD255:~$ python pollmb.py -h 127.0.0.1 -p 55502 -f 16 -a 0 -d 42C8

Contacting Modbus host at 127.0.0.1 port 55502 timeout 60.0 sec.
Sending Modbus function: 16, addr: 0, qty: 1, data: 42C8 for 1 polls at 1 msec
1: Reply was: function: 16, data: 0001
marcus@marcus-AOD255:~$ python pollmb.py -h 127.0.0.1 -p 55502 -f 16 -a 1 -d aaaa

Contacting Modbus host at 127.0.0.1 port 55502 timeout 60.0 sec.
Sending Modbus function: 16, addr: 1, qty: 1, data: aaaa for 1 polls at 1 msec
1: Reply was: function: 16, data: 0001
marcus@marcus-AOD255:~$ python pollmb.py -p 55502 -f 3 -a 0 -q 2
Contacting Modbus host at localhost port 55502 timeout 60.0 sec.
Sending Modbus function: 3, addr: 0, qty: 2, data: 0000 for 1 polls at 1 msec
1: Reply was: function: 3, data: 42c8aaaa

diagslave:

validateMasterIpAddr: accepting connection from 127.0.0.1
Slave   1: writeHoldingRegisters from 1, 1 references
....
validateMasterIpAddr: accepting connection from 127.0.0.1
Slave   1: writeHoldingRegisters from 2, 1 references
...
validateMasterIpAddr: accepting connection from 127.0.0.1
Slave   1: readHoldingRegisters from 1, 2 references

And in Openhab-UI i only see zeros.

Marcus

Ok, that’s weird, let’s make sure there are no issues with the openhab configuration…

And you copy pasted the items and openhab cfg lines above? Perhaps if you could put those as well to pastebin.com so I can try reproduce?

Can you please provide me the verbose logs from openhab, including the startup? Please use pastebin.com to store the logs.

Sami

Hey Sami,

thank u for the hint with looking at the logs, i had to do this before posting.

Here is the Openhab Output at starting.

Here openhab.cfg.

Now i got your test working.

Here is what i did:

I installed openhab via apt.
Then installed as service.

Tested my code with which i had the problems.
Then got ur advice with diagslave and pollmb. -> not working

After looking at the logs today full with errors i stopped the service with

sudo openhab service stop

And started it manual with:

sudo /usr/share/openhab/bin/openhab.sh -o

and now it did work!!! I got the expected output! Great. Its the first step forward.

What is the difference between starting as service or starting manual i think that there is something going wrong.

Should i remove it with apt and then reinstall manually?

Great to hear you got it working!

I would use the service always with apt based installation. That ensures that you are running only single instance of openhab…

Basically the service calls the start script eventually so the should be pretty similar.

Best
Sami

But, why does it only work when starting Openhab manual?

Don’t know really, I have had quite positive experience with the service.

Perhaps you could shut down the openhab,ensure that is not running (sudo ps aux|grep java), and start the service.

I would expect the logs to contain more information then.

Best
Sami

Please tell me exactly which logs u need.

I tested many things now and i cant get it to work.

It only sets the first bit of each register. And nothing more.
And maybe tell me how the pastebin.com-thing works…

Thank you

Please configure verbose logging as documented in the modbus openhab wiki, see this section.

I’m interested in all the logs related to modbus binding. Logs right from startup should be enough. Let it run for couple of minutes so that the basic polling should be there.

I hope that you have Minimal configuration, no rules writing commands etc. You can for example use the configuration that I pasted before.Let’s try to get the read part working first.

Using pastebin.com : 1) go to the site 2) paste logs to the text box 3) click new paste 4) copy the url and paste it here.

Best
Sami

Hey Sami,

is this the log u need?
Configuration and installation is minimal. For the first i wanted to get the modbus-thing working.

openhab.log
*.Items
openhab.cfg

In my buscoupler i can use static and dynamic tables.
In this actual configuration i tried to use the static modbus-tables.
Starting from 0 for input-register and starting from 384 for holding registers.

The behavior is always the same. It only reads/writes the first bit from each register. And using the other switches i see no fc6 write-command only when switching switch 1.

If u need other information then tell me.

Hi thanks for the log and effort

Please check the logging configuration, it seems not to be configured according to wiki or you are using older version of the binding . Please paste your logback xml files for double check.

And just to be sure, you are now using 1.9.0 modbus binding, right?

Best
Sami

Hey Sami,

with the last log was something wrong.

New Log

Now i did it again, with fresh install and working logging.

I hope that u can see now what is wrong.

Marcus

Hi @marcusjelsch

Sorry to bounce you but I believe there is something I don’t understand with your setup…

For example, log lines like the following

19:32:24.860 [INFO ] [.modbus.internal.ModbusBinding:233  ] -   -> rawDataMultiplier: 1.0
19:32:24.860 [INFO ] [.modbus.internal.ModbusBinding:234  ] -   -> config.readRegister: 2
19:32:24.861 [INFO ] [.modbus.internal.ModbusBinding:235  ] -   -> slaveValueType: bit
19:32:24.861 [INFO ] [.modbus.internal.ModbusBinding:239  ] -   -> config.getItem(): null
19:32:24.862 [INFO ] [.modbus.internal.ModbusBinding:240  ] -   -> newState: 0

do not match the code in master branch! I do see familiar log messages with TRACE and DEBUG as expected so that is good at least.

Can you make sure you have the 1.9.0 snapshot version of the modbus from the cloudbees

After that, could you please just zip your whole installation, or if you are using apt-based installation, the relevant directories (see wiki).

I can’t really help if I don’t know what I’m debugging…

Best,
Sami

Hey Sami,

u must not apologize!

i used a snapshot of the binding that i found somewhere in the web.

I took the version from cloudbees and still the same behavior but another output.

I let it run for a minute. And then zipped the whole installation. I did not install over apt.

My openhab installation.

Lets go on and find a solution. I give u everything u need. just ask.

Marcus

Thanks. I will have a look

Btw, so was this working as expected? You mentioned earlier that manual installation worked but the service from apt based installation did not.

Best
Sami