## 1. Introduction MB2HAL is a generic non-realtime HAL component to communicate with one or more Modbus devices. So far, there are two options to communicate with a Modbus device: 1. One option is to create a HAL component as a driver see VFD Modbus. 2. Another option is to use Classic Ladder which has Modbus built in, see ClassicLadder. 3. Now there is a third option that consists of a "generic" driver configured by text file, this is called MB2HAL. Why MB2HAL? Consider using MB2HAL if: 1. You have to write a new driver and you don’t know anything about programming. 2. You need to use Classic Ladder "only" to manage the Modbus connections. 3. You have to discover and configure first time the Modbus transactions. MB2HAL have debug levels to facilitate the low level protocol debug. 4. You have more than one device to connect. MB2HAL is very efficiently managing multiple devices, transactions and links. Currently I am monitoring two axis drivers using a Rs232 port, a VFD driver using another Rs232 port, and a remote I/O using TCP/IP. 5. You want a protocol to connect your Arduino to HAL. Look the included sample configuration file, sketch and library for Arduino Modbus. ## 2. Usage 1. Create a config file from the example below - Set component name (optional) Set HAL_MODULE_NAME=mymodule (default HAL_MODULE_NAME=mb2hal) - Load the modbus HAL non-realtime component 2. Default component name: loadusr -W mb2hal config=config_file.ini 3. Custom component name: loadusr -Wn mymodule mb2hal config=config_file.ini ## 3. Options ### 3.1 Init Section [MB2HAL_INIT] |Value|Type|Required|Description| |-----|----|--------|-----------| |INIT_DEBUG|Integer|No|Debug level of init and INI file parsing
.0 = silent
1 = error messages (default)
2 = OK confirmation messages
3 = debugging messages
4 = maximum debugging messages (only in transactions) |VERSION|String|No|Version number in the format N.N[NN]. Defaults to 1.0.| |HAL_MODULE_NAME|String|No|HAL module (component) name. Defaults to "mb2hal".| |SLOWDOWN|Float|No|Insert a delay of "FLOAT seconds" between transactions in order to not to have a lot of logging and facilitate the debugging. Useful when using DEBUG=3 (NOT INIT_DEBUG=3). It affects ALL transactions. Use "0.0" for normal activity.| |TOTAL_TRANSACTIONS|Integer|Yes|The number of total Modbus transactions. There is no maximum.| ### 3.2 Transaction Sections One transaction section is required per transaction, starting at [TRANSACTION_00] and counting up sequentially. If there is a new link (not transaction), you must provide the REQUIRED parameters 1st time. Warning: Any OPTIONAL parameter not specified are copied from the previous transaction. |Value|Type|Required|Description| |-----|----|--------|-----------| |LINK_TYPE|String|Yes|You must specify either a "serial" or "tcp" link for the first transaction. Later transactions will use the previous transaction link if not specified.| |TCP_IP|IP address|If LINK_TYPE=tcp|The Modbus slave device IP address. Ignored if LINK_TYPE=serial.| |TCP_PORT|Integer|No|The Modbus slave device TCP port. Defaults to 502. Ignored if LINK_TYPE=serial.| |SERIAL_PORT|String|If LINK_TYPE=serial|The serial port. For example "/dev/ttyS0". Ignored if LINK_TYPE=tcp.| |SERIAL_BAUD|Integer|If LINK_TYPE=serial|The baud rate. Ignored if LINK_TYPE=tcp.| |SERIAL_BITS|Integer|If LINK_TYPE=serial|Data bits. One of 5, 6, 7, 8. Ignored if LINK_TYPE=tcp.| |SERIAL_PARITY|String|If LINK_TYPE=serial|Data parity. One of: even, odd, none. Ignored if LINK_TYPE=tcp.| |SERIAL_STOP|Integer|If LINK_TYPE=serial|Stop bits. One of 1, 2. Ignored if LINK_TYPE=tcp.| |SERIAL_DELAY_MS|Integer|If LINK_TYPE=serial|Serial port delay between transactions of this section only. In ms. Defaults to 0. Ignored if LINK_TYPE=tcp.| |MB_SLAVE_ID|Integer|Yes|Modbus slave number.| |FIRST_ELEMENT|Integer|Yes|The first element address.| |NELEMENTS|Integer|Unless PIN_NAMES is specified|The number of elements. It is an error to specify both NELEMENTS and PIN_NAMES. The pin names will be sequential numbers, e.g. mb2hal.plcin.01.| |PIN_NAMES|List|Unless NELEMENTS is specified|A list of element names. These names will be used for the pin names, e.g. mb2hal.plcin.cycle_start.
**NOTE:** There must be no white space characters in the list. Example: PIN_NAMES=cycle_start,stop,feed_hold| |MB_TX_CODE|String|Yes|Modbus transaction function code (see specifications):