What is the correct failure mode for Modbus (0x10) Write Multiple Registers (if any)?

StackOverflow https://stackoverflow.com/questions/18319789

  •  25-06-2022
  •  | 
  •  

Question

How should a Modbus device fail if an error is encountered after a Write Multiple Register (0x10) request has been validated but before all writes have been completed? The specification (6.12) seems vague on this point and web searches have not proven fruitful. I see three possibilities:

  1. Attempt to write each register in turn. If an error occurs immediately give up/send an exception.
  2. Treat the request as an atomic transaction where either all data should be written or none of it.
  3. Attempt to write all data sending an exception at the end if any failure was observed.

Is there a conventional or proper way to fail here or is the way a device fails implementation specific requiring only that it be documented in the manual?

Était-ce utile?

La solution

According to Figure 22: Write Multiple Registers state diagram on page 31 of the specification exception code 4 should be returned but the protocol itself does not specify how the application layer should work.

The way your device fails must consider constraints and possible side effects. For example if you accept some control commands (set point value or just setting multiple outputs assigned to different registers) it is a good practice to never assign such values directly from registers but with some validation first before re-writing the value to internal program variables which are used to drive IOs or influence any control actions. Such approach complies with option 2 from your list.

You can implement whatever behavior works best provided it’s documented. If your slave is under control of a master capable of implementing part of your application layer you may also consider support for diagnostic or error information requests from slave in case of failure but such functionality is not specified for exception 0x4 to function code 0x10.

Autres conseils

Since master can't know what is successfully written and what is not in case of such a partially failed write operation, most appropriate approach would be "all-or-nothing", just like you mentioned at #2. It's the hardest path to implement, but it's the only approach where master won't end up in an ambiguous state on such an error.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top