Anybody know a way of creating a ModBus "BROADCAST" message?

Title says it all, I am trying to send a message to ID 0 over ModBus RTU. (This is a broadcast type message meaning all bus members receive it but nobody answers).

I’ve tried adding a bridge with id=0 and a a poller with refresh=0 to which I added a single data thing (without readstart but with a writetransform as I need to send some bytes) but the binding does not seem to write to the bus…

If someone knows a trick to get this to work I’d be thankful if it could be shared.

Steven

You can actually attach a write-only data Thing directly to a Bridge, with no intervening poller Thing.
Worth a try, but I suspect no-go here either.
Might need @ssalonen to review binding to handle id=0

You don’t mention, but you do need to link your data Thing to an Item and send an openHAB command to trigger a bus write.

Good to try out what happens with id=0. What do the verbose logs say?

Thanks for your help guys.

OK, if I remove the “poller” it looks like the message gets transmitted, which is great. My bus members receive the telegram.

2021-01-06 21:50:00.950 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 00 10 00 40 00 05 0a 32 00 00 15 01 06 00 15 aa 55 d2 96 

2021-01-06 21:50:01.457 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 00 10 00 40 00 05 0a 32 00 00 15 01 06 00 15 aa 55 d2 96

However, as no reply is coming the binding generates read errors…

2021-01-06 21:50:01.460 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)

2021-01-06 21:50:01.465 [DEBUG] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.WriteMultipleRegistersRequest@18e48ba (unit id 0 & transaction 735). Serial parameters: SerialParameters@16932d4[portName=/dev/ttyUSB0,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=500]

2021-01-06 21:50:01.469 [DEBUG] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.WriteMultipleRegistersRequest@18e48ba (unit id 0 & transaction 735). Serial parameters: SerialParameters@16932d4[portName=/dev/ttyUSB0,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=500]

2021-01-06 21:50:01.473 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 1 out of 2 failed when executing request (ModbusWriteRegisterRequestBlueprint@1732c0d[slaveId=0,reference=64,functionCode=WRITE_MULTIPLE_REGISTERS,registers=ModbusRegisterArrayImpl(32 00 00 15 01 06 00 15 aa 55),maxTries=2]). Will try again soon. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException Error reading response (EOF) [operation ID aea20838-58bb-44bd-902b-0480df52a2a0]

My bus members receive the broadcast so the send part works. It would be nice to to patch the binding as to say it should just timeout after sending ID=0 and not generate a read error (so we get the binding working without generating errors).

So “semi-solved” I’d say…

Steven

That’s a surprise but worth knowing. :slight_smile:
Logically a poller on id=0 is a nonsense in Modbus, so I suppose there is some sense in it.

Why, what problem does it give you?
This should be a very rare event.

Looking at your WARN log, you do probably want to change your writeMaxTries parameter to avoid double sending your broadcast. It will retry by default.

Odd that it did not work with the poller, it certainly should work. Verbose logs and thing and item definitions are needed to troubleshoot. Could be a simple typo in the parameters for example.

Indeed you are correct, with slave id 0, only writes should be possible and no response should be expected. Seems to be all clearly specified in the spec https://modbus.org/docs/Modbus_over_serial_line_V1.pdf

This is probably a corner case that has not been thought out in the binding.

Detailed logs…

Bridge modbus:serial:vva_bsp "VVA Broadcast" [port="/dev/ttyUSB0", id=0, baud=115200, stopBits="1.0", parity="even", dataBits=8, encoding="rtu", echo=false, receiveTimeoutMillis=500, flowControlIn="none", flowControlOut="none", timeBetweenTransactionsMillis=50, connectMaxTries=2, connectTimeoutMillis=1000] 
{
  Thing data vva_bsp_time_sync "BSP time sync" [writeTransform="JS(vva_ts_rpc_time_sync.js)"]
}

The connectMaxTries=2 is just to be “the same” as all the other bridges.

2021-01-07 07:40:30.801 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 00 10 00 40 00 05 0a 28 1e 00 07 01 07 00 15 aa 55 7d 42 

==> /var/log/openhab2/events.log <==

2021-01-07 07:40:30.677 [.event.RuleStatusInfoEvent] - d1a57a97-d28f-4755-b3fc-5c8367454eec updated: RUNNING

2021-01-07 07:40:30.679 [ome.event.ItemCommandEvent] - Item 'itm_vva_bsp_time_sync' received command 43605

2021-01-07 07:40:30.692 [.event.RuleStatusInfoEvent] - d1a57a97-d28f-4755-b3fc-5c8367454eec updated: IDLE

2021-01-07 07:40:30.694 [nt.ItemStatePredictedEvent] - itm_vva_bsp_time_sync predicted to become 43605

==> /var/log/openhab2/openhab.log <==

2021-01-07 07:40:31.306 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 00 10 00 40 00 05 0a 28 1e 00 07 01 07 00 15 aa 55 7d 42
##### This line indicates the problem, the binding expects a response even though ID=0
2021-01-07 07:40:31.308 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)

2021-01-07 07:40:31.312 [DEBUG] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.WriteMultipleRegistersRequest@1a80aa (unit id 0 & transaction 158). Serial parameters: SerialParameters@17077d5[portName=/dev/ttyUSB0,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=500]

2021-01-07 07:40:31.314 [DEBUG] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.WriteMultipleRegistersRequest@1a80aa (unit id 0 & transaction 158). Serial parameters: SerialParameters@17077d5[portName=/dev/ttyUSB0,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=500]

2021-01-07 07:40:31.316 [WARN ] [rt.modbus.internal.ModbusManagerImpl] - Try 1 out of 2 failed when executing request (ModbusWriteRegisterRequestBlueprint@1404955[slaveId=0,reference=64,functionCode=WRITE_MULTIPLE_REGISTERS,registers=ModbusRegisterArrayImpl(28 1e 00 07 01 07 00 15 aa 55),maxTries=2]). Will try again soon. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException Error reading response (EOF) [operation ID 712cbe65-e51c-4e40-b1f4-013cdb325432]

2021-01-07 07:40:31.431 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Sent: 00 10 00 40 00 05 0a 28 1e 00 07 01 07 00 15 aa 55 7d 42 

2021-01-07 07:40:31.934 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - Last request: 00 10 00 40 00 05 0a 28 1e 00 07 01 07 00 15 aa 55 7d 42

2021-01-07 07:40:31.935 [DEBUG] [t.wimpi.modbus.io.ModbusRTUTransport] - failed to read: Error reading response (EOF)

2021-01-07 07:40:31.938 [DEBUG] [pi.modbus.io.ModbusSerialTransaction] - execute try 1/1 error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.WriteMultipleRegistersRequest@1a285e (unit id 0 & transaction 159). Serial parameters: SerialParameters@6bf61e[portName=/dev/ttyUSB0,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=500]

2021-01-07 07:40:31.940 [DEBUG] [pi.modbus.io.ModbusSerialTransaction] - execute reached max tries 1, throwing last error: I/O exception: IOException Error reading response (EOF). Request: net.wimpi.modbus.msg.WriteMultipleRegistersRequest@1a285e (unit id 0 & transaction 159). Serial parameters: SerialParameters@6bf61e[portName=/dev/ttyUSB0,baudRate=115200,flowControlIn=none,flowControlOut=none,databits=8,stopbits=1,parity=even,encoding=rtu,echo=false,receiveTimeoutMillis=500]

2021-01-07 07:40:31.941 [ERROR] [rt.modbus.internal.ModbusManagerImpl] - Last try 2 failed when executing request (ModbusWriteRegisterRequestBlueprint@1404955[slaveId=0,reference=64,functionCode=WRITE_MULTIPLE_REGISTERS,registers=ModbusRegisterArrayImpl(28 1e 00 07 01 07 00 15 aa 55),maxTries=2]). Aborting. Error was I/O error, so reseting the connection. Error details: net.wimpi.modbus.ModbusIOException I/O exception: IOException Error reading response (EOF) [operation ID 712cbe65-e51c-4e40-b1f4-013cdb325432]

2021-01-07 07:40:31.985 [DEBUG] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:vva_bsp:vva_bsp_time_sync 'BSP time sync' had ModbusSlaveIOExceptionImpl error on write: ModbusSlaveIOException(cause=ModbusIOException, EOF=false, message='I/O exception: IOException Error reading response (EOF)', cause2=null)

2021-01-07 07:40:31.992 [DEBUG] [rt.modbus.internal.ModbusManagerImpl] - Modbus operation ended, timing info: {total: 1209 ms, connection: 98, transaction=1065, callback=7} [operation ID 712cbe65-e51c-4e40-b1f4-013cdb325432]

==> /var/log/openhab2/events.log <==

2021-01-07 07:40:31.992 [hingStatusInfoChangedEvent] - 'modbus:data:vva_bsp:vva_bsp_time_sync' changed from OFFLINE (COMMUNICATION_ERROR): Error (ModbusSlaveIOExceptionImpl) with write. Request: ModbusWriteRegisterRequestBlueprint@135de17[slaveId=0,reference=64,functionCode=WRITE_MULTIPLE_REGISTERS,registers=ModbusRegisterArrayImpl(28 00 00 07 01 07 00 15 aa 55),maxTries=2]. Description: ModbusSlaveIOException(cause=ModbusIOException, EOF=false, message='I/O exception: IOException Error reading response (EOF)', cause2=null). Message: Modbus IO Error with cause=ModbusIOException, EOF=false, message='I/O exception: IOException Error reading response (EOF)', cause2=null to OFFLINE (COMMUNICATION_ERROR): Error (ModbusSlaveIOExceptionImpl) with write. Request: ModbusWriteRegisterRequestBlueprint@1404955[slaveId=0,reference=64,functionCode=WRITE_MULTIPLE_REGISTERS,registers=ModbusRegisterArrayImpl(28 1e 00 07 01 07 00 15 aa 55),maxTries=2]. Description: ModbusSlaveIOException(cause=ModbusIOException, EOF=false, message='I/O exception: IOException Error reading response (EOF)', cause2=null). Message: Modbus IO Error with cause=ModbusIOException, EOF=false, message='I/O exception: IOException Error reading response (EOF)', cause2=null

Basically what is missing in the binding is:
Normally when you SEND a modbus message you update the modbus state to “Reply time out” so you wait until you get a reply from the slave before raising the “no reply error” (or you handle the reply if a reply comes in).

When you send a broadcast you don’t go to state “reply time out delay” but you head for state “message turn around delay”. In the standard the state machine “2.4.1 Master State diagram” explains that clearly.

It’s probably easy to “fix” in the error handler (check for ID=0 in the sent frame and not generate no reply error on expiry of reply time out) or switch state to “turn around delay” after sending the message out and ignore error handling all together.

I have no experience in java but I wrote a modbus master/slave in C for ARM so I’m willing to help getting this to work as per standard.

1 Like

Agreed.

The fix probably needs to take place in two places

Could you file a ticket in the openhab-core repo? pm me if you would like to have assistance on this, contributions are certainly welcome.