table of contents
| MESAMBCCC(1) | LinuxCNC Documentation | MESAMBCCC(1) |
NAME¶
mesambccc - Utility for compiling hm2_modbus command control description files
SYNOPSIS¶
mesambccc [-h|--help] [-v|--verbose] [-o file|--output=file] <filename.source.mbccs>
DESCRIPTION¶
The mesambccc utility is used to compile hm2_modbus driver command control description files for running Modbus devices with Mesa cards using the PktUARTs. The MBCCS source file is an XML formatted document which describes the devices connected, pins to create and commands to issue to the PktUART port using the Modbus protocol. See MBCCS FILE FORMAT below.
OPTIONS¶
-h, --help
-o file, --output=file
-v, --verbose
MBCCS FILE FORMAT¶
The Modbus command control source file (mbccs file) is an XML formatted document describing the communication parameters, connected devices, HAL pins and command functions to be sent over Modbus. The overall layout is as follows:
<?xml version="1.0" encoding="UTF-8"?> <mesamodbus [attributes...]>
<devices>...</devices>
<initlist>...</initlist>
<commands>...</commands> </mesamodbus>
The <devices> tag must be defined before either <initlist> or <commands> are defined.
ATTRIBUTE VALUES¶
Attribute values are generally case insensitive, except for the name attributes, which should always be lower case.
Boolean attributes accept values "false" and "0" for false and "true" and "1" for true. Integer numerical values can be entered in decimal, hexadecimal, octal or binary form. The latter three require the value to be prefixed with "0x", "0o" or "0b" respectively. Floating point values follow standard rules for floating point values.
All values are checked to be within an acceptable range. Errors and warnings are emitted when values are out of bounds. In case of a warning they may be clamped to the acceptable range.
MODBUS FUNCTIONS¶
A subset of the Modbus functions is supported (with function number in parentheses):
You can use the function’s symbolic name or numerical value in <command> in the function attribute (as in function="W_REGISTERS" or function="16").
MODBUS TYPES¶
The modbustype attribute declares the interpretation of values to or from a Modbus device’s registers. They can be a signed integer (S), unsigned integer (U) or a floating point value (F). The size of the value can be 16-bit, 32-bit or 64-bit and the byte-ordering must be specified. The Modbus default, when speaking in "register" quantities, is an unsigned 16-bit value in big-endian (U_AB).
Modbus devices may implement other interpretations covering multiple consecutive registers to create larger or other types. In doing so, multiple device vendors have created some different interpretations of the data that needs to be covered. Differences are primarily byte-ordering.
The byte-ordering is specified with one of the following suffixes:
Modbus standard byte-ordering is big-endian, which is the first in each list (_AB, _ABCD and _ABCDEFGH). Little-endian is the last in each list. The user may use any of the byte-orderings necessary and required because some device vendors have not paid attention to the proper on-wire ordering.
The orderings _A and _B are single byte values from a modbus register. A single byte will be taken from the register value. You cannot access successive bytes from the same register using these types. (You require a second component that de-multiplexes the HAL value(s) into individual bytes from the data stream using the hm2_modbus presented pin values.) The ordering _A will use the the least significant byte (LSB), with respect to the default big endian order for Modbus. Ordering _B will use the most significant byte (MSB). Note that there is no floating point type when only using sizes of one single byte. Single byte values have the additional restriction that they cannot be used as data values in <initlist>/<command>/<data>.
The byte-ordering suffix is prefixed with S (signed), U (unsigned) or F (float) to complete the modbustype attribute value. For example, a 32-bit float in big-endian is named F_ABCD. A 64-bit signed integer value in little-endian is S_HGFEDCBA.
The types have following ranges and will be clamped to the min/max values if the clamp attribute is set in the <command>:
<mesamodbus>¶
The main enclosing tag <mesamodbus> contains the communication parameters and other setup values as attributes:
baudrate [1200..1000000]
drivedelay [auto, 1..31]
duplex [full, half]
icdelay [auto, 1..255]
interval [0..3600000000]
The interval may be overridden in the individual <commands><command> instructions. Default 0.
parity [N, O, E]
rxdelay, txdelay [auto, 1..1020]
stopbits [1, 2]
suspend [Boolean]
timeout [auto, 10000..10000000]
writeflush [Boolean]
The write flush is necessary when you need to ensure proper and correct pin data is present before the Modbus commands start sending potentially harmful or invalid data because the pins have not yet been initialized to their proper values. When set, only pin values that are changed from their initial values are propagated in Modbus write commands.
This value represents the global default used buy the individual commands from the <commands> section and can be overridden in the individual <command> instructions. Default true.
The default parameters, without any attributes defined in <mesamodbus>, are half duplex serial setup using 8E1@9600 and running all commands as fast as possible. Timeouts and other timing parameters are calculated automatically.
<devices>¶
Each connected device to the physical bus must be declared in a <device> tag with a name and an address attribute. A device with name broadcast is implicitly added with address zero (0). Device entries may include a <description> tag, which serves as a user’s comment.
<devices>
<device address="0x01" name="binbox" />
<device address="0x02" name="vroom">
<description>Round and round and round...</description>
</device>
<device address="0x66" name="clickies">
<description>Many, many relays</description>
</device> </devices>
Recognized <devices>/<device> attributes:
address [1..247]
name
<initlist>¶
The <initlist> tag contains a list of <command> tags that are only sent once at the startup of the system. The commands can be used to initialize any devices on the bus prior to normal operation. Commands can be both read and write functions. Write functions must have data defined to be sent. Each <command> entry may include a <description> tag, which serves as a user’s comment.
Note: if the driver starts in suspended mode (supend="true" in <mesamodbus>), then the <initlist> commands are first sent when the driver comes out of suspend.
<initlist>
<command device="scd30" function="W_REGISTER" address="0x0034">
<description>Soft reset</description>
<data value="1" />
</command>
<command device="relay" function="W_COILS" address="0">
<data value="0" />
<data value="1" />
<data value="1" />
<data value="0" />
<description>Four relays set to off-on-on-off</description>
</command>
<command device="boombox" function="W_COIL" address="0">
<data value="0xff00" />
<description>Single output set to on to hear the boombox</description>
</command>
<command delay="2000000">
<description>Wait for reset to finish</description>
</command>
<command device="fltbox" function="W_REGISTERS" address="0xcafe">
<data modbustype="F_ABCD" value="0.53" />
<data modbustype="F_ABCD" value="99.999" />
<description>Send four 16-bit words: 0x3f07 0xae14 0x42c7 0xff7d
(floats in binary, big-endian)</description>
</command> </initlist>
A <command> is either a delay instruction, a communication parameter change or a Modbus transaction to perform. Only the delay attribute is supported in case of a delay instruction and all activity is suspended during the specified delay. A communication parameter change can use any communication related attribute from the <mesamodbus> tag and must revert to the defaults set in the <mesamodbus> tag at the end on the <initlist>.
Modbus write functions must include one or more <data> tags to encapsulate the data to send. The <data> tag has a mandatory attribute value to capture the value to send. An optional modbustype attribute models the data to send to the format of the modbustype. The default is U_AB if the type is not specified.
The write coils Modbus function W_COILS (15) further restrict the value to zero (0) or one (1). The write coil W_COIL (5) has a fixed type of U_AB and expects a value of 0x0000 or 0xff00. Other values may be given, but a warning will then be emitted.
The Modbus read functions R_COILS (1), R_INPUTS (2), R_REGISTERS (3) and R_INPUTREGS (4) are supported in the <initlist>/<command> but the returned data is ignored and discarded. Read functions are supported because some devices require a read function as a trigger.
Recognized <initlist>/<command> attributes when sending Modbus commands:
address [0..65535]
bcanswer [Boolean]
count [1..2000]/[1..125]
device
The device name broadcast will send the command to all devices on the bus.
function [see MODBUS FUNCTIONS]
noanswer [Boolean]
timeout [auto, 1..60000000]
timeoutbits [0..1000000]
timesout [Boolean]
Delay instruction
Recognized <initlist>/<command> attributes in delay commands:
delay [0..60000000]
Communication parameter change
Communication parameters may be temporarily changed to perform live setup of Modbus devices to change their own communication parameters. Some devices will start with a fixed rate and must be reprogrammed at start to change to a different rate. The default setup from <mesamodbus> must be restored if one or more parameters were changed or a warning will be emitted.
Recognized <initlist>/<command> attributes in communication parameter change commands. Attributes not specified will be taken from the <mesamodbus> tag’s attributes:
baudrate [1200..1000000]
drivedelay [auto, 1..31]
icdelay [auto, 1..255]
parity [N, O, E]
rxdelay, txdelay [auto, 1..1020]
stopbits [1, 2]
Initialization data
Recognized <initlist>/<command>/<data> attributes:
modbustype [see MODBUS TYPES]
value
HAL TYPES¶
A <command> in the <commands> section maps to one or more HAL pins with specific type using the haltype attribute. Recognized are:
The types are also recognized without the HAL_ prefix. Note that coil and binary input functions R_COILS (1), R_INPUTS (2), W_COIL (5) and W_COILS (15) can only map to HAL_BIT and do so implicitly.
The HAL_BIT and HAL_U32 types always map to one single HAL pin.
The HAL_FLOAT and HAL_S32 types can generate one single pin or can generate multiple pins with offset and scale. Output pins with R_REGISTERS (3) and R_INPUTREGS (4) can add a scaled pin to the set.
Mapping HAL pins to commands requires a modbustype attribute to encode the format and necessary conversions. Register functions R_REGISTERS (3), R_INPUTREGS (4), W_REGISTER (6) and W_REGISTERS (16) may map to HAL_BIT only when using unsigned modbustype where a value of zero (0) is false and any other value is true for write functions or one (1) for read functions.
Note on 64-bit integer types
As a consequence, 64-bit integer Modbus types can only map to 32-bit HAL pins, which will reduce accuracy. A warning is emitted when you map the larger 64-bit integer Modbus types to a smaller 32-bit HAL type.
<commands>¶
The <commands> section defines one or more <command> tags to describe the Modbus function(s) to execute in a periodical way. Each <command> tag maps to one or more HAL pins and specifies data conversion between device data and HAL pin data.
A delay command may be added using the delay attribute causing the communication to be suspended for the specified time. This may be required in broadcast situations where the Modbus devices must have time for internal processing before the next data is sent or requested.
The <command> entries may include a <description> child-tag, which serves as a user’s comment. Additionally, the <command> tag may have one or more <pin> child-tags to create user-defined HAL pin names. Each <pin> tag may again include a <description> child-tag.
Modbus read functions R_COILS (1), R_INPUTS (2), R_REGISTERS (3) and R_INPUTREGS (4) will always be sent at the specified interval. However, the Modbus write functions W_COIL (5), W_REGISTER (6), W_COILS (15) and W_REGISTERS (16) are only sent when the source data (pin value) changed. You must specify the resend attribute to force repeated writes at the specified interval.
<commands>
<command device="wavebox" function="R_COILS" address="0x0000" count="4" name="state" />
<description>Type is implicit HAL_BIT, will become HAL pins:
- (out) hm2_modbus.0.wavebox.state-00
- (out) hm2_modbus.0.wavebox.state-01
- (out) hm2_modbus.0.wavebox.state-02
- (out) hm2_modbus.0.wavebox.state-03
</description>
</command>
<command device="scd30" modbustype="F_ABCD" haltype="HAL_FLOAT" function="R_REGISTERS"
address="0x0028" scale="0">
<pin name="co2"><description>Too much will kill you...</description></pin>
<pin name="temperature" />
<pin name="humidity" />
<description>Will become HAL pins:
- (out) hm2_modbus.0.scd30.co2
- (out) hm2_modbus.0.scd30.temparature
- (out) hm2_modbus.0.scd30.humidity
Count will automatically be calculated (6 Modbus 16-bit registers).
</description>
</command>
<command device="broadcast" function="W_COILS" address="0x1234" count="2"
name="anyandall" bcanswer="1">
<description>Will create HAL_BIT pins:
- (in) hm2_modbus.0.anyandall-00
- (in) hm2_modbus.0.anyandall-01
The bcanswer flag signifies that a device erroneously sends a reply on
broadcast (oopsie), which needs to be ignored .
</description>
</command>
<!-- A delay is suggested after a broadcast to allow devices to handle the data -->
<command delay="10000" />
<command device="watcher" function="W_REGISTER" haltype="HAL_U32" modbustype="U_AB"
address="0x1ee7" noanswer="1" resend="1">
<pin name="watcher" />
<description>Will create a HAL_U32 pin
- (in) hm2_modbus.0.watcher
The 'count' is implicit 1. The data is mapped to U_AB and is clamped.
The data is sent every time (resend=1), regardless whether the HAL pin
changed. No answer is expected to be received (noanswer=1). This
command generates a (valid) Modbus packet on the bus and nothing more.
You must be sure that no reply is sent from the device or errors will
occur (for example silent watchdog).
</description>
</command> </commands>
Recognized <commands>/<command> attributes:
address [0..65535]
bcanswer [Boolean]
clamp [Boolean]
count [1..2000]/[1..125]/[1..62]/[1..31]
(the range depends on haltype and modbustype)
delay [0..60000000]
device
The device name broadcast will send the command to all devices on the bus.
disabled [Boolean]
function [see MODBUS FUNCTIONS]
haltype [see HAL TYPES]
interval [once,0..3600000000]
A special value of once will run this command only once. However, it will be retried is an error occurred. You normally do not need the value once and it may be better to use an entry in the <initlist>. But sometimes you need to have other periodic commands before a once marked command that cannot be achieved in the <initlist> sequence. Default <mesamodbus>[interval].
modbustype [see MODBUS TYPES]
name
Example: if count="2" and name="myname", then the pins will have names myname-00 and myname-01, unless one or more <pin> tags override the name.
noanswer [Boolean]
resend [Boolean]
scale [Boolean]
The Modbus write functions W_REGISTER (6) and W_REGISTERS (16) create extra HAL pins pin.name.offset (in, 64-bit haltype) and pin.name.scale (in, HAL_FLOAT).
The scale attribute is only supported for HAL_FLOAT, HAL_S32 and HAL_S64. Default is true for HAL_FLOAT and false for others. The scale pin is initialized to one (1.0) and the offset pin is initialized to zero (0).
Scaling is always multiplicative to prevent division-by-zero. The offset is always subtracted before scaling. The scaling action performed and subject to clamping is:
timeout [auto, 1..60000000]
timeoutbits [0..1000000]
timesout [Boolean]
unaligned [Boolean]
Setting unaligned is purely a cosmetic attribute to suppress console clutter when compiling the mbccs file. It has no functional effect on the communication with the device. Default false.
writeflush [Boolean]
Pins
Defining <pin> tags allows for custom naming schemes and allows reducing read and write function overhead. Using <pin> tags enables you to combine different modbustype and haltype values to be read or written to or from consecutive addresses. A warning is emitted if 32-bit and 64-bit values are not aligned to their native boundary (it may be an error, depending device). The attributes of the <command> tag set the defaults for the <pin> tag attributes and can be overridden by adding them to the <pin> tag.
<command device="booboo"
function="R_REGISTERS"
address="0x0240"
haltype="HAL_FLOAT"
modbustype="F_ABCD"
scale="1">
<!-- addr: 0x0240-0x0241; disable scaling pins -->
<pin name="speed" scale="0" />
<!-- addr:0x0242; one register to bit-->
<pin name="ping" haltype="HAL_BIT" modbustype="U_AB" />
<!-- Align the next value -->
<pin skip="1" />
<!-- addr: 0x0244-0x0245; use defaults from this command -->
<pin name="afloat" /> <!--
The above <command><pin> tags read 6 registers and generate pins:
hm2_modbus.0.speed HAL_FLOAT (out)
hm2_modbus.0.ping HAL_BIT (out)
hm2_modbud.0.afloat HAL_FLOAT (out)
hm2_modbud.0.afloat.offset HAL_FLOAT (in)
hm2_modbud.0.afloat.scale HAL_FLOAT (in)
hm2_modbud.0.afloat.scaled HAL_FLOAT (out) --> </command>
Recognized <commands>/<command>/<pin> attributes:
clamp [Boolean]
haltype [see HAL TYPES]
modbustype [see MODBUS TYPES]
name
scale [Boolean]
skip [0..24]
Using a skip value larger than 11 will emit a warning. Large skips make the transfers less efficient and skipping 12+ registers may be better off by splitting the function in two commands. An exception may be atomicity where the device allows access to the intermediate (unused) register addresses and only guarantees atomicity in a single read/write transaction.
Beware that the skipped registers must be readable or writable (depending function). The skipped values must be transferred in the Modbus transaction and the target device must allow read or write access to the skipped register addresses.
Beware: using skip in write commands writes value zero (0) to the skipped registers.
SEE ALSO¶
https://linuxcnc.org/docs/stable/html/drivers/mesa_modbus.html
AUTHOR¶
This man page written by B.Stultiens, as part of the LinuxCNC project.
REPORTING BUGS¶
Report bugs at https://github.com/LinuxCNC/linuxcnc/issues
COPYRIGHT¶
Copyright © 2025 B.Stultiens
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
| 10/22/2025 | LinuxCNC |