Error was: net.wimpi.modbus.ModbusSlaveException Error Code = 4

Hi,

For discrete inputs everything is working fine.

For digital outputs/coils, it’s working … but getting these error messages.

Getting these errors with Modbus and Beckhoff BC9100 / Digital Output

16:10:24.605 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘DO01’ received command ON
16:10:24.669 [INFO ] [arthome.event.ItemStatePredictedEvent] - DO01 predicted to become ON
16:10:24.694 [INFO ] [smarthome.event.ItemStateChangedEvent] - DO01 changed from OFF to ON
16:10:24.935 [WARN ] [ort.modbus.internal.ModbusManagerImpl] - Try 1 out of 3 failed when executing request (BasicModbusWriteCoilRequestBlueprint@89da23[slaveId=1,reference=0,functionCode=WRITE_COIL,bits=SingleBitArray(bit=1),maxTries=3]). Will try again soon. Error was: net.wimpi.modbus.ModbusSlaveException Error Code = 4 [operation ID c2ca648b-fe2c-44d5-a6c4-42099609d1cf]
16:10:25.015 [WARN ] [ort.modbus.internal.ModbusManagerImpl] - Try 2 out of 3 failed when executing request (BasicModbusWriteCoilRequestBlueprint@89da23[slaveId=1,reference=0,functionCode=WRITE_COIL,bits=SingleBitArray(bit=1),maxTries=3]). Will try again soon. Error was: net.wimpi.modbus.ModbusSlaveException Error Code = 4 [operation ID c2ca648b-fe2c-44d5-a6c4-42099609d1cf]
16:10:25.096 [ERROR] [ort.modbus.internal.ModbusManagerImpl] - Last try 3 failed when executing request (BasicModbusWriteCoilRequestBlueprint@89da23[slaveId=1,reference=0,functionCode=WRITE_COIL,bits=SingleBitArray(bit=1),maxTries=3]). Aborting. Error was: net.wimpi.modbus.ModbusSlaveException Error Code = 4 [operation ID c2ca648b-fe2c-44d5-a6c4-42099609d1cf]
16:10:25.110 [ERROR] [ternal.handler.ModbusDataThingHandler] - Thing modbus:data:beckhoff:coils:do01 ‘Modbus Data’ had ModbusSlaveErrorResponseExceptionImpl error on write: ModbusSlaveErrorResponseException(error=4)
16:10:25.129 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - ‘modbus:data:beckhoff:coils:do01’ changed from ONLINE to OFFLINE (COMMUNICATION_ERROR): Error (ModbusSlaveErrorResponseExceptionImpl) with write. Request: BasicModbusWriteCoilRequestBlueprint@89da23[slaveId=1,reference=0,functionCode=WRITE_COIL,bits=SingleBitArray(bit=1),maxTries=3]. Description: ModbusSlaveErrorResponseException(error=4). Message: Slave responsed with error=4
16:10:25.217 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - ‘modbus:data:beckhoff:coils:do01’ changed from OFFLINE (COMMUNICATION_ERROR): Error (ModbusSlaveErrorResponseExceptionImpl) with write. Request: BasicModbusWriteCoilRequestBlueprint@89da23[slaveId=1,reference=0,functionCode=WRITE_COIL,bits=SingleBitArray(bit=1),maxTries=3]. Description: ModbusSlaveErrorResponseException(error=4). Message: Slave responsed with error=4 to ONLINE

Beckhoff
BC9100 (factory reseted and set to fieldbus)
4x KL1408 | 8-channel digital input
2x KL2408 | 8-channel digital output

RasberryPi

Things:
Bridge modbus:tcp:beckhoff [ host=“192.168.5.253”, port=502, id=1 ] {
Bridge poller discreteInputs [ start=0, length=32, refresh=1000, type=“discrete” ] {
Thing data di01 [ readStart=“0”, readValueType=“bit” ]
Thing data di02 [ readStart=“1”, readValueType=“bit” ]
}
Bridge poller coils [ start=0, length=16, refresh=1000, type=“coil” ] {
Thing data do01 [ readStart=“0”, readValueType=“bit”, writeStart=“0”, writeValueType=“bit”, writeType=“coil” ]
Thing data do02 [ readStart=“1”, readValueType=“bit”, writeStart=“1”, writeValueType=“bit”, writeType=“coil” ]
}
}

Items:
Switch DO01 “Digital Output index 01 [%d]” (beckhoff_out) { channel=“modbus:data:beckhoff:coils:do01:switch” }
Switch DO02 “Digital Output index 02 [%d]” (beckhoff_out) { channel=“modbus:data:beckhoff:coils:do02:switch” }

When changing output state from outside openhab the status changs in openhab without error msg

2020-04-07 16:28:02.952 [vent.ItemStateChangedEvent] - DO01 changed from ON to OFF
2020-04-07 16:28:07.413 [vent.ItemStateChangedEvent] - DO01 changed from OFF to ON

Anyone an idea please?

Modbus exception code 4 is a rejection from your PLC, “error”
http://www.simplymodbus.ca/exceptions.htm

It doesn’t like what your asking it to do.
I don’t know what your PLC might like instead; review the addressing of your coils, review if the PLC works with only one of FC05 or FC15 to write coils

No, but it does work, state is changing … only getting the error msg on top … so addressing should be ok (?)
tried with writetype holding and writeMultipleEvenWithSingleRegisterOrCoil
same or worse result

State gets updated because openHAB predicts it when the item receives a command.

You can disable this behavior using autoupdate flag in your item definition, see Modbus - Bindings | openHAB

With autoupdate disabled, I would expect the state to remain unchanged.

State does change on the KL2408 (led turns on/off) … so it really works …
(did already try with autoupdate set to false before)

1 Like

The exception code absolutely comes from your PLC.
If you think the expected write is working, i.e. accepted by the PLC, there remains the possibility that oipenHAB is issuing a “bad” write as well.

You’ve been tinkering with Thing settings in-flight, now reboot so that you know the binding is using only what you think are “good” settings.

1 Like

Did restart openhab few times and also reinstalled the modbus binding.
Restarted and reset beckhoff bc9000 too.
Still getting the error 4.

set log level to TRACE :
openHAB Add-ons :: Bundles :: Modbus Binding
openHAB Add-ons :: Bundles :: IO :: Modbus Transport
But extra info …

This Beckhoff manual page describes why the PLC would respond with modbus exception code 4

the text is

Watchdog or K-bus error
EK9000: E-bus error

and they also make clear that illegal modbus commands would produce different EC to 4

On that basis, I’d say your openHAB config is fine, and the problem is with your PLC config.

It seems odd to both appear to “work” and report an error, but I suppose sometimes the PLC has to try to implement a command to discover an error, so there is a sort of sense there.

Checked and tried all terminals one by one (others removed)
Any Beckhoff/Modbus specialists around or ida how to further troubleshoot this?