Skip to content

Commit 18b6059

Browse files
authored
Merge pull request #3493 from BsAtHome/backport_2.9_fix-hm2_modbus
Backport hm2_modbus fixes and additions from master
2 parents 65e68f2 + 684cf20 commit 18b6059

5 files changed

Lines changed: 298 additions & 119 deletions

File tree

docs/src/man/man1/mesambccc.1.adoc

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ needs to be covered. Differences are primarily byte-ordering.
9797

9898
The byte-ordering is specified with one of the following suffixes:
9999

100+
* `_A`, `_B`
100101
* `_AB`, `_BA`
101102
* `_ABCD`, `_BADC`, `_CDAB`, `_DCBA`
102103
* `_ABCDEFGH`, `_BADCFEHG`, `_CDABGHEF`, `_DCBAHGFE`,
@@ -107,6 +108,18 @@ Modbus standard byte-ordering is big-endian, which is the first in each list
107108
may use any of the byte-orderings necessary and required because some device
108109
vendors have not paid attention to the proper on-wire ordering.
109110

111+
The orderings `_A` and `_B` are single byte values from a modbus register. A
112+
single byte will be taken from the register value. You cannot access successive
113+
bytes from the same register using these types. (You require a second component
114+
that de-multiplexes the HAL value(s) into individual bytes from the data stream
115+
using the hm2_modbus presented pin values.) +
116+
The ordering `_A` will use the the least significant byte (LSB), with respect
117+
to the default big endian order for Modbus. Ordering `_B` will use the most
118+
significant byte (MSB). Note that there is no floating point type when only
119+
using sizes of one single byte. +
120+
Single byte values have the additional restriction that they cannot be used as
121+
data values in '<initlist>/<command>/<data>'.
122+
110123
The byte-ordering suffix is prefixed with S (signed), U (unsigned) or F (float)
111124
to complete the 'modbustype' attribute value. For example, a 32-bit float in
112125
big-endian is named `F_ABCD`. A 64-bit signed integer value in little-endian is
@@ -115,6 +128,9 @@ S_HGFEDCBA.
115128
The types have following ranges and will be clamped to the min/max values if
116129
the 'clamp' attribute is set in the '<command>':
117130

131+
* 8-bit:
132+
** signed integer [-128..+127] (`S_A`, `S_B`)
133+
** unsigned integer [0..255] (`U_A`, `U_B`)
118134
* 16-bit:
119135
** float16 [-65504.0..+65504.0] (`F_AB`, `F_BA`)
120136
** signed integer [-32768..+32767] (`S_AB`, `S_BA`)
@@ -177,9 +193,11 @@ other setup values as attributes:
177193
and reply sizes. The 'timeout' value can be overridden in the '<command>'
178194
definitions. Default auto.
179195
*writeflush* [Boolean]::
180-
Set to true when the _very first_ round of write commands must be flushed to
181-
synchronize the internal state to the pin state. This flush happens either
182-
once when the module starts or each time the module comes out of 'suspend'. +
196+
Set to true when the first round of write commands must synchronize the
197+
internal state to the pin state. The writes are calculated but not sent to
198+
the Modbus device (i.e. flushed). This flush happens either once when the
199+
module starts, each time when the module comes out of 'suspend', or
200+
specifically for a command when it gets re-enabled. +
183201
The write flush is necessary when you need to ensure proper and correct pin
184202
data is present _before_ the Modbus commands start sending potentially
185203
harmful or invalid data because the pins have not yet been initialized to
@@ -503,6 +521,15 @@ Recognized '<commands>/<command>' attributes:
503521
The Modbus device to communicate with. The 'device' attribute
504522
references '<device>[name]'. +
505523
The device name '`broadcast`' will send the command to all devices on the bus.
524+
*disabled* [Boolean]::
525+
Start the command in disabled state when set, preventing it from being
526+
executed. Using the 'disabled' flag is a fine grain per command control.
527+
In contrast, 'suspend' works on the entire state machine and controls
528+
operation of all commands in an all-or-nothing way. A command in the disabled
529+
state can be enabled by toggling the reset pin of the command. Using 'disable'
530+
can be particularly useful when you need to delay one particular command
531+
while others may already be run. The 'writeflush' setting is honored when
532+
coming out of the disabled state. Default false.
506533
*function* [see link:#_modbus_functions[*MODBUS FUNCTIONS*]]::
507534
The attribute value is one of the supported Modbus functions.
508535
*haltype* [see link:#_hal_types[*HAL TYPES*]]::
@@ -571,6 +598,14 @@ Recognized '<commands>/<command>' attributes:
571598
should be emitted when it does. This differs from 'noanswer' in that a reply
572599
may be expected within the timeout period but not after the timeout expires.
573600
This may be required for flaky devices. Default false.
601+
*unaligned* [Boolean]::
602+
Set to true to suppress the alignment warning in multi-register reads or
603+
writes where 32-bit or 64-bit values are not aligned to their natural Modbus
604+
address boundaries. This is useful for devices that do not care about
605+
alignment or do not use Modbus addresses in conventional ways. +
606+
Setting 'unaligned' is purely a cosmetic attribute to suppress console
607+
clutter when compiling the mbccs file. It has no functional effect on the
608+
communication with the device. Default false.
574609
*writeflush* [Boolean]::
575610
The override the 'writeflush' value. See '<mesamodbus>[writeflush]' for
576611
details. Default '<mesamodbus>[writeflush]'.

docs/src/man/man9/hm2_modbus.9.adoc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,17 @@ Each command in the MBCCB file (not init commands) will generate a set of pins
142142
to reflect the current state, where `MM` is the command number counting from zero
143143
(00):
144144

145+
hm2_modbus.N.command.MM.disable (bit, input)::
146+
Disable this command on the rising edge of this pin. You need to use the
147+
command's corresponding reset pin to re-enable it.
145148
hm2_modbus.N.command.MM.disabled (bit, output)::
146149
Set if the command is no longer sent in the commands loop.
147150
hm2_modbus.N.command.MM.error-code (u32, output)::
148151
The errno code of the last error. The following error codes can be set:
149152

150153
** 5, 0x05 (EIO): The receiver detected an overrun, a false start-bit or wrong parity.
151154
** 9, 0x09 (EBADF): The reply returned an unsupported function.
155+
** 11, 0x0b (EAGAIN): The command was manually disabled in the mbccb or via the disable pin.
152156
** 22, 0x16 (EINVAL): An invalid value was detected (internal error).
153157
** 27, 0x1b (EFBIG): The received data packet size exceeds the internally allocated buffer.
154158
** 34, 0x22 (ERANGE): The received data packet was too small or the message's length indicator was wrong.
@@ -166,7 +170,9 @@ hm2_modbus.N.command.MM.errors (u32, output)::
166170
when the command succeeds.
167171
hm2_modbus.N.command.MM.reset (bit, input)::
168172
Reset this command's error counter and re-enable the command on the rising
169-
edge of the input pin.
173+
edge of the input pin. +
174+
Note: Re-enabling the command will honor the 'writeflush' setting of the
175+
command.
170176

171177
Each mbccb file will generate a set of pins as defined in the mbccb file. See
172178
*mesambccc*(1) for details.

0 commit comments

Comments
 (0)