How can I write on modbus WAGO digital outputs

  • Platform information:

    • Hardware: virtualbox, Wago 750-881, digital output 750-1504
    • OS: Linux Mint 19
    • Java Runtime Environment: openjdk-8-jre
    • openHAB version: 2.4
  • Issue of the topic:
    No write on the output is taken into account, it seems it’s read only. On the modbus log, I can see a message is sent. When I set the output with an another system (Calaos), the state of the output is updated in habpanel.
    The solution autoupdate=“false” doesn’t work.
    Thanks for your help.

  • Configurations:

    • Things configuration:
Bridge modbus:tcp:wago [ host="", port=502, id=1 ] {
        Bridge poller coils [ start=512, length=16, refresh=5000, type="coil" ] {
                Thing data do0 [ readStart="512", readValueType="bit", writeStart="512", writeValueType="bit", writeType="coil" ]        
                Thing data do1 [ readStart="513", readValueType="bit", writeStart="513", writeValueType="bit", writeType="coil" ]
	        Thing data do2 [ readStart="514", readValueType="bit", writeStart="514", writeValueType="bit", writeType="coil" ]
	        Thing data do3 [ readStart="515", readValueType="bit", writeStart="515", writeValueType="bit", writeType="coil" ]
	        Thing data do4 [ readStart="516", readValueType="bit", writeStart="516", writeValueType="bit", writeType="coil" ]
	        Thing data do5 [ readStart="517", readValueType="bit", writeStart="517", writeValueType="bit", writeType="coil" ]
	        Thing data do6 [ readStart="518", readValueType="bit", writeStart="518", writeValueType="bit", writeType="coil" ]
	        Thing data do7 [ readStart="519", readValueType="bit", writeStart="519", writeValueType="bit", writeType="coil" ]
	        Thing data do8 [ readStart="520", readValueType="bit", writeStart="520", writeValueType="bit", writeType="coil" ]
	        Thing data do9 [ readStart="521", readValueType="bit", writeStart="521", writeValueType="bit", writeType="coil" ]
	        Thing data do10 [ readStart="522", readValueType="bit", writeStart="522", writeValueType="bit", writeType="coil" ]
	        Thing data do11 [ readStart="523", readValueType="bit", writeStart="523", writeValueType="bit", writeType="coil" ]
	        Thing data do12 [ readStart="524", readValueType="bit", writeStart="524", writeValueType="bit", writeType="coil" ]
	        Thing data do13 [ readStart="525", readValueType="bit", writeStart="525", writeValueType="bit", writeType="coil" ]
	        Thing data do14 [ readStart="526", readValueType="bit", writeStart="526", writeValueType="bit", writeType="coil" ]
	        Thing data do15 [ readStart="527", readValueType="bit", writeStart="527", writeValueType="bit", writeType="coil" ]
  • Items configuration:
Switch WO_4_01            "Digital Output index 0 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do0:switch" }
Switch WO_4_02            "Digital Output index 1 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do1:switch" }
Switch WO_4_03            "Digital Output index 2 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do2:switch" }
Switch WO_4_04            "Digital Output index 3 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do3:switch" }
Switch WO_4_05            "Digital Output index 4 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do4:switch" }
Switch WO_4_06            "Digital Output index 5 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do5:switch" }
Switch WO_4_07            "Digital Output index 6 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do6:switch" }
Switch WO_4_08            "Digital Output index 7 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do7:switch" }
Switch WO_4_09            "Digital Output index 8 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do8:switch" }
Switch WO_4_10            "Digital Output index 9 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do9:switch" }
Switch WO_4_11            "Digital Output index 10 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do10:switch" }
Switch WO_4_12            "Digital Output index 11 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do11:switch" }
Switch WO_4_13            "Digital Output index 12 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do12:switch" }
Switch WO_4_14            "Digital Output index 13 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do13:switch" }
Switch WO_4_15            "Digital Output index 14 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do14:switch" }
Switch WO_4_16            "Digital Output index 15 [%d]"  (Wago_output_4)  { channel="modbus:data:wago:coils:do15:switch" }
  • Logs modbus:
2019-07-31 14:32:21.598 [DEBUG] [rt.modbus.internal.ModbusManagerImpl] - Scheduling one-off write task BasicWriteTask@521e6645[request=BasicModbusWriteCoilRequestBlueprint@4445e674[slaveId=1,reference=522,functionCode=WRITE_COIL,bits=SingleBitArray(bit=1),maxTries=3],endpoint=ModbusTCPSlaveEndpoint@4b5a371c[address=,port=502],callback=org.openhab.binding.modbus.internal.handler.ModbusDataThingHandler@77857b0f]
2019-07-31 14:32:21.599 [DEBUG] [rt.modbus.internal.ModbusManagerImpl] - Will now execute one-off write task BasicWriteTask@521e6645[request=BasicModbusWriteCoilRequestBlueprint@4445e674[slaveId=1,reference=522,functionCode=WRITE_COIL,bits=SingleBitArray(bit=1),maxTries=3],endpoint=ModbusTCPSlaveEndpoint@4b5a371c[address=,port=502],callback=org.openhab.binding.modbus.internal.handler.ModbusDataThingHandler@77857b0f], waited in thread pool for 1
2019-07-31 14:32:21.600 [DEBUG] [] - connect()
2019-07-31 14:32:21.661 [DEBUG] [ernal.handler.ModbusDataThingHandler] - Successful write, matching request BasicModbusWriteCoilRequestBlueprint@4445e674[slaveId=1,reference=522,functionCode=WRITE_COIL,bits=SingleBitArray(bit=1),maxTries=3]
2019-07-31 14:32:21.663 [DEBUG] [rt.modbus.internal.ModbusManagerImpl] - Modbus operation ended, timing info: {total: 64 ms, connection: 24, transaction=39, callback=1} [operation ID 5f64aac3-b23d-42c8-ad8d-00c420627481]

There is no poller Thing in your Modbus things configuration.

Oddly, I don’t think that will stop it writing to Modbus - but you would never read back any results.

Thanks for this remark, I deleted this line with the comment.
The post is corrected.

Other people use WAGO 750-881 with openHAB, so stick with it.

One thing I do notice from previous threads, is that the WAGO usually expects read and write to different addresses. I don’t know why or have any idea about how to set the WAGO up.
Example -

What would be most useful here is - what does that other system send and to where?

You can check my topic Modbus binding: resend values to device after power down and i’m sure you will get it working as i think everything is explained there in the last post.

In the wago PLC, I use M bits to control the outputs.
That way I can control the outputs via PLC or OpenHab.
In the PLC it looks like this:
output := (modbus bit OR PLC bit)

If you have anymore questions just ask and I will try to check my configuration again and give more info.

Good evening !
I think I programed everything fine in CodeSys.
I can read the digital input, i can write %MX0.0, but when I want to write de digital output, it doesn’t work.
I can force the ouput to true in CodeSys when online.

Variables :

    mb_con_bit_00 		AT %MX0.0: BOOL;
    DI_1_00 AT %IX0.0 : BOOL;
    DO_1_00 AT %QX0.0 : BOOL;


DO_1_00:= DI_1_00;

all the same with this :

DO_1_00:= mb_con_bit_00;

Thanks for your help.

Do you have both these statements

DO_1_00:= DI_1_00;
DO_1_00:= mb_con_bit_00;

Below each other in the PLC?
If so, the last statement always overrules the first statement.
So please check that first.

I tried with the first statement only and after I tried with the second statement. Not both at the same time.

If you have

DO_1_00:= mb_con_bit_00;

and force mb_con_bit_00 to TRUE in the PLC, the output becomes active right?

If I look at your configuration, your start address might be wrong.
Below you can find my working config.

Wago is actually quite simple regarding modbus.
Inputs bits are mapped to a certain modbus address range, output bits to another range,
input words, output words, flags, flagwords, … they are all mapped to a certain modbus address range.
You should check the manual for this.

When you get the start address, you need to calculate the address you actually need in your config.
Below I show you how to calculate the address for MX600.0 and so on.


    //Controlbits to be set from OpenHab
    //In the PLC these are located at MW600-M699 = 99*16=1584 control bits
    //Modbus starta ddress for bits: MX0.0 starts at modbus address12288.
    //600 words * 16 bits => +9600 ==> So modbus start address: 21888
    Bridge poller wagooutputscon [ start=21888, length=1024, refresh=100, type="coil" ] {
        Thing data mb_con_bit_0 [ writeStart="21888", writeValueType="bit", writeType="coil"]
        Thing data mb_con_bit_1 [ writeStart="21889", writeValueType="bit", writeType="coil"]
        Thing data mb_con_bit_2 [ writeStart="21890", writeValueType="bit", writeType="coil"]
        Thing data mb_con_bit_3 [ writeStart="21891", writeValueType="bit", writeType="coil"]
        Thing data mb_con_bit_4 [ writeStart="21892", writeValueType="bit", writeType="coil"]
        Thing data mb_con_bit_5 [ writeStart="21893", writeValueType="bit", writeType="coil"]
        Thing data mb_con_bit_6 [ writeStart="21894", writeValueType="bit", writeType="coil"]
        Thing data mb_con_bit_7 [ writeStart="21895", writeValueType="bit", writeType="coil"]


Switch mb_con_bit_0 "mb_con_bit_0" {channel="modbus:data:wago:wagooutputscon:mb_con_bit_0:switch", autopudate="false"}
Switch mb_con_bit_1 "mb_con_bit_1" {channel="modbus:data:wago:wagooutputscon:mb_con_bit_1:switch", autopudate="false"}
Switch mb_con_bit_2 "mb_con_bit_2" {channel="modbus:data:wago:wagooutputscon:mb_con_bit_2:switch", autopudate="false"}
Switch mb_con_bit_3 "mb_con_bit_3" {channel="modbus:data:wago:wagooutputscon:mb_con_bit_3:switch", autopudate="false"}

Variable declaration in Wago PLC:

	(*Digital control via modbus (%MW600-M699 = 99*16=1584 controle bits)		*)
	(*#Modbus startadres voor bits: MX0.0 start op modbus adres 12288.			*)
	(*600 woorden * 16 bits => +9600 ==> Dus modbus startadres: 21888			*)
	(*Used to change state of outputs											*)
	mb_con_bit_0 		AT %MX600.0: BOOL := FALSE;		(*Adres 21888*)
	mb_con_bit_1 		AT %MX600.1: BOOL := FALSE;		(*Adres 21889*)
	mb_con_bit_2 		AT %MX600.2: BOOL := FALSE;		(*Adres 21890*)
	mb_con_bit_3 		AT %MX600.3: BOOL := FALSE;		(*Adres 21891*)
	mb_con_bit_4 		AT %MX600.4: BOOL := FALSE;		(*Adres 21892*)
	mb_con_bit_5 		AT %MX600.5: BOOL := FALSE;		(*Adres 21893*)
	mb_con_bit_6 		AT %MX600.6: BOOL := FALSE;		(*Adres 21894*)
	mb_con_bit_7 		AT %MX600.7: BOOL := FALSE;		(*Adres 21895*)

Code in Wago PLC:

(*Uitgangen Leefruimte*)

You want to use MX0.0, so that starts at modbus address 12288 instead of 512.

Also one thing you could check, I declared my MX600.0 and so on as a GLOBAL VARIABLE.
I’m not sure if it’s important but you could try that too if it doesn’t work.