openhab / openhab1-addons

Add-ons for openHAB 1.x
Eclipse Public License 2.0
3.43k stars 1.7k forks source link

[MODBUS] Wago and Modbus Wrong and Crazy response #4890

Closed BrutalBirdie closed 7 years ago

BrutalBirdie commented 7 years ago

My Problem

Welcome and thanks ahead for your time. I am trying to access my Wago controller via Modbus only for reading values and status. (No the Wago Binding does not suit as a solution for my Problem) The Modbus binding gives me sometimes wrong or crazy values. But with some items perfect results. My Technician gave me the Wago Absolute Addresses which I have to calculate into Modbus Addresses.

Some Examples

IP | Modbus | Data Type | Item Type X | %MX10.0 | BOOL | DI X | %MX10.1 | BOOL | DI X | %MD200 | REAL | AI X | %MX20.0 | BOOL | DO X | %MW50 | WORD | AI

Wago Absolute Address to Modbus Address calculation

%MX10.0 % Start a Absolute Address M is a Flag X is Bit operator 10 the Word number to read .0 the Bit to read

After reading the Wago 750-880 Manual multiple times I understood the calculation as followed ( EN Page 265 and EN Page 101) | Modbus Address | IEC 61131 Address | 12288 ...24575 | %MW0 ...%MW12287 The bit number can be determined using the following equation: Bit No. = (word * 16) + Bit No. in word

Example for %MX10.0

Bit No. = (10 * 16) + 0 = 160 With my understanding I need to add the 160 to the Offset 12288 giving the Modbus Address 12448

Example for %MD200

After talking to my Wago Technician he told me I need to multiply the 200 * 2 and add it to the Offset 400 + 12288 = 12688

Example for %MW50

Wago Technician said simple add the Word to the Offset which 50 + 12288 = 12338

openhab.cfg

%MX10 mapping

modbus:tcp.slaveMX10.connection=X modbus:tcp.slaveMX10.type=discrete modbus:tcp.slaveMX10.start=12488 modbus:tcp.slaveMX10.length=2 modbus:tcp.slaveMX10.valuetype=bit Why length=2? Because of the second item %MX10.1

%MD200 mapping

modbus:tcp.slaveMD200.connection=X modbus:tcp.slaveMD200.type=input modbus:tcp.slaveMD200.start=12688 modbus:tcp.slaveMD200.length=2 modbus:tcp.slaveMD200.valuetype=float32

%MW50 Mapping !THIS WORKS PERFECT!

modbus:tcp.slaveMW50.connection=X modbus:tcp.slaveMW50.type=input modbus:tcp.slaveMW50.start=12338 modbus:tcp.slaveMW50.length=1 modbus:tcp.slaveMW50.valuetype=int16

openhab.items

%MX10 and %MX10.1

Switch slaveMX10 "Signal [%s]" (test) {modbus="slaveMX10:0"} Switch slaveMX101 "Signal 2 [%s]" (test) {modbus="slaveMX10:1"}

%MD200

Number slaveMD200 "Valuue L1 [%f]" (test) {modbus="slaveMD200:0"}

%MW50

Number slaveMW50 " Value 2 [%d]" (test) {modbus="slaveMW50155:0"}

openhab.sitemap (yes I only want text no real switches)

Text item=slaveMX10 Text item=slaveMX101 Text item=slaveMD200 Text item=slaveMW50

Now the troublemakers

The slaveMX10 gives me a correct response The slaveMX101 give me a wrong response The slaveMD200 gives me CRAZY values The slaveMW50 gives me perfect values

I got real problems reading the REAL values and map the Bit operators correctly. If someone understands my clusterfuck of Informations, please give me some Ideas. I summon you @ssalonen thanks ahead.

My Environment and Documents

ssalonen commented 7 years ago

Hi!

I think this discussion is more suitable for community forums as there is no issue discovered with the actual binding.

I recommend you take step back and figure out the addressing logic of your slave. You can use mbpoll (http://mblogic.sourceforge.net/mbtools/mbpoll.html) to print out the registers in different formats.

Once you know the register numbers, openhab configuration should be straight forward

Best Sami

BrutalBirdie commented 7 years ago

@ssalonen thank you so much! I'll try it. I am working only via ssh, so maybe that will be a problem. But first try, then cry.

ssalonen commented 7 years ago

Mbpoll is command line tool so it should work pretty well. With Linux you usually have python available already so the tool works.

BrutalBirdie commented 7 years ago

Update

Hey @ssalonen,

after reading my Registers I get the Data correctly, so my modbus calculation was OK! -h xx.xx.xx.xx -p 502 -f 3 -a 12756 -q 2 gives me 70a33f7d I know that the value has to be between 0 and 2 REAL. So my assumption is the following. It's encoded as Float - Mid-Little Endian (CDAB) or Float - Little Endian (DCBA). Float - Big Endian (ABCD) is not possible because the value would be to high. Dataanalyzer

Or am I nuts? If I am not. How to get this working with the modbus binding(1.8.3)?

Thanks again looking to hear from you :)

ssalonen commented 7 years ago

@BrutalBirdie try this (with 1.9.0 binding)

modbus:tcp.slaveMD200.connection=X
modbus:tcp.slaveMD200.type=input
modbus:tcp.slaveMD200.start=12756
modbus:tcp.slaveMD200.length=2
modbus:tcp.slaveMD200.valuetype=float32

or this

modbus:tcp.slaveMD200.connection=X
modbus:tcp.slaveMD200.type=input
modbus:tcp.slaveMD200.start=12756
modbus:tcp.slaveMD200.length=2
modbus:tcp.slaveMD200.valuetype=float32_swap

with the following item definition

Number myitem "modbus test" (ALL) {modbus="slaveMD200:0"}

Wiki has the details:

valuetype=float32:

  • registers (2 index) and ( 2 *index + 1) are interpreted as signed 32bit floating point number.
  • it assumed that the first register contains the most significant 16 bits
  • it is assumed that each register is encoded in most significant bit first order

i.e. register0=AB, register1=CD, the result will be float32(ADCD)

valuetype=float32_swap:

  • registers (2 index) and ( 2 *index + 1) are interpreted as signed 32bit floating point number.
  • it assumed that the first register contains the least significant 16 bits
  • it is assumed that each register is encoded in most significant bit first order (Big Endian)

i.e. register0=AB, register1=CD, the result will be float32(CDAD)

If the bit pattern "mixed" (highly unexpected since modbus spec specified bit order inside register), one needs to do the transformation via openhab rules.

Best, Sami

BrutalBirdie commented 7 years ago

@ssalonen I'll try it now with 1.9.0.b3 Binding from here wrong link? if so could you be so nice to give me the correct one

EDIT

Nevermind! Found the original one

BrutalBirdie commented 7 years ago

Update @ssalonen

openhab.cfg

modbus:tcp.C2MW113.connection=X modbus:tcp.C2MW113.type=input modbus:tcp.C2MW113.start=12752 modbus:tcp.C2MW113.length=2 modbus:tcp.C2MW113.valuetype=float32_swap

openhab.items

Number C2MW113 "Leistungsfaktor phi [%f]" (SBW2OGUV) {modbus="C2MW113:0"}

20:03:24.134 [ERROR] [.modbus.internal.ModbusBinding:567 ] - Exception when parsing configuration parameter tcp.C2MW113.valuetype = float32_swap -- org.osgi.service.cm.ConfigurationException valuetype : the given value type 'float32_swap' is invalid

I still think I have the wrong binding.... could you please give the direct link to the jar? Do I have to use openHAB 2?

ssalonen commented 7 years ago

Please find the link from Wiki in the troubleshooting section.

You can use openhab 1 or openhab2, does lot matter

Best Sami

BrutalBirdie commented 7 years ago

Thank you so much! Yes it's working now. If the Project is finished and I publish it, I will remember and credit you. Thank you, I will remember this!

ssalonen commented 7 years ago

Great to hear! Enjoy!