Guest User

MB2HAL

a guest
Oct 2nd, 2026
92
0
8 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.19 KB | Software | 0 0
  1. #This .INI file is also the HELP, MANUAL and HOW-TO file for mb2hal.
  2.  
  3. #Load the Modbus HAL userspace module as the examples below,
  4. #change to match your own HAL_MODULE_NAME and INI file name
  5. #Using HAL_MODULE_NAME=mb2hal or nothing (default): loadusr -W mb2hal config=config_file.ini
  6. #Using HAL_MODULE_NAME=mymodule: loadusr -Wn mymodule mb2hal config=config_file.ini
  7.  
  8. # ++++++++++++++++++++++++
  9. # Common section
  10. # ++++++++++++++++++++++++
  11. [MB2HAL_INIT]
  12.  
  13. #OPTIONAL: Debug level of init and INI file parsing.
  14. # 0 = silent.
  15. # 1 = error messages (default).
  16. # 2 = OK confirmation messages.
  17. # 3 = debugging messages.
  18. # 4 = maximum debugging messages (only in transactions).
  19. INIT_DEBUG=3
  20.  
  21. #OPTIONAL: Set to 1.1 to enable the new functions:
  22. # - fnct_01_read_coils
  23. # - fnct_05_write_single_coil
  24. # - changed pin names (see https://linuxcnc.org/docs/2.9/html/drivers/mb2hal.html#_pins).
  25. VERSION=1.1
  26.  
  27. #OPTIONAL: HAL module (component) name. Defaults to "mb2hal".
  28. HAL_MODULE_NAME=mb2hal
  29.  
  30. #OPTIONAL: Insert a delay of "FLOAT seconds" between transactions in order
  31. #to not to have a lot of logging and facilitate the debugging.
  32. #Useful when using DEBUG=3 (NOT INIT_DEBUG=3)
  33. #It affects ALL transactions.
  34. #Use "0.0" for normal activity.
  35. SLOWDOWN=0.0
  36.  
  37. #REQUIRED: The number of total Modbus transactions. There is no maximum.
  38. TOTAL_TRANSACTIONS=9
  39.  
  40. # ++++++++++++++++++++++++
  41. # Transactions
  42. # ++++++++++++++++++++++++
  43. #One transaction section is required per transaction, starting at 00 and counting up sequentially.
  44. #If there is a new link (not transaction), you must provide the REQUIRED parameters 1st time.
  45. #Warning: Any OPTIONAL parameter not specified are copied from the previous transaction.
  46. [TRANSACTION_00]
  47.  
  48. #REQUIRED: You must specify either a "serial" or "tcp" link for the first transaction.
  49. #Later transaction will use the previous transaction link if not specified.
  50. LINK_TYPE=serial
  51.  
  52. #if LINK_TYPE=tcp then REQUIRED (only 1st time): The Modbus slave device ip address.
  53. #if LINK_TYPE=serial then IGNORED
  54. TCP_IP=192.168.2.10
  55.  
  56. #if LINK_TYPE=tcp then OPTIONAL.
  57. #if LINK_TYPE=serial then IGNORED
  58. #The Modbus slave device tcp port. Defaults to 502.
  59. TCP_PORT=502
  60.  
  61. #if LINK_TYPE=serial then REQUIRED (only 1st time).
  62. #if LINK_TYPE=tcp then IGNORED
  63. #The serial port.
  64. SERIAL_PORT=/dev/ttyUSB0
  65.  
  66. #if LINK_TYPE=serial then REQUIRED (only 1st time).
  67. #if LINK_TYPE=tcp then IGNORED
  68. #The baud rate.
  69. SERIAL_BAUD=115200
  70.  
  71. #if LINK_TYPE=serial then REQUIRED (only 1st time).
  72. #if LINK_TYPE=tcp then IGNORED
  73. #Data bits. One of 5,6,7,8.
  74. SERIAL_BITS=8
  75.  
  76. #if LINK_TYPE=serial then REQUIRED (only 1st time).
  77. #if LINK_TYPE=tcp then IGNORED
  78. #Data parity. One of: even, odd, none.
  79. SERIAL_PARITY=none
  80.  
  81. #if LINK_TYPE=serial then REQUIRED (only 1st time).
  82. #if LINK_TYPE=tcp then IGNORED
  83. #Stop bits. One of 1, 2.
  84. SERIAL_STOP=2
  85.  
  86. #if LINK_TYPE=serial then OPTIONAL:
  87. #if LINK_TYPE=tcp then IGNORED
  88. #Serial port delay between for this transaction only.
  89. #In ms. Defaults to 0.
  90. SERIAL_DELAY_MS=10
  91.  
  92. #REQUIRED (only 1st time).
  93. #Modbus slave number.
  94. MB_SLAVE_ID=1
  95.  
  96. #REQUIRED: The first element address (decimal integer).
  97. FIRST_ELEMENT=0
  98.  
  99. #REQUIRED unless PIN_NAMES is specified: The number of elements.
  100. #It is an error to specify both NELEMENTS and PIN_NAMES
  101. #The pin names will be sequential numbers e.g mb2hal.plcin.01
  102. NELEMENTS=4
  103.  
  104. #REQUIRED unless NELEMENTS is specified: A list of element names.
  105. #these names will be used for the pin names, e.g mb2hal.plcin.cycle_start
  106. #NOTE: there must be no white space characters in the list
  107. # PIN_NAMES=cycle_start,stop,feed_hold
  108.  
  109. #REQUIRED: Modbus transaction function code (see www.modbus.org specifications).
  110. # fnct_01_read_coils (01 = 0x01) (new in 1.1)
  111. # fnct_02_read_discrete_inputs (02 = 0x02)
  112. # fnct_03_read_holding_registers (03 = 0x03)
  113. # fnct_04_read_input_registers (04 = 0x04)
  114. # fnct_05_write_single_coil (05 = 0x05) (new in 1.1)
  115. # fnct_06_write_single_register (06 = 0x06)
  116. # fnct_15_write_multiple_coils (15 = 0x0F)
  117. # fnct_16_write_multiple_registers (16 = 0x10)
  118. #
  119. # Created pins:
  120. # fnct_01_read_coils:
  121. # fnct_02_read_discrete_inputs:
  122. # mb2hal.m.n.bit (output)
  123. # mb2hal.m.n.bit-inv (output)
  124. # fnct_03_read_holding_registers:
  125. # fnct_04_read_input_registers:
  126. # mb2hal.m.n.float (output)
  127. # mb2hal.m.n.int (output)
  128. # fnct_05_write_single_coil:
  129. # mb2hal.m.n.bit (input)
  130. # NELEMENTS needs to be 1 or PIN_NAMES must contain just one name.
  131. # fnct_06_write_single_register:
  132. # mb2hal.m.n.float (input)
  133. # mb2hal.m.n.int (input)
  134. # NELEMENTS needs to be 1 or PIN_NAMES must contain just one name.
  135. # Both pin values are added and limited to 65535 (UINT16_MAX). Normally use one and let the other open (read as 0).
  136. # fnct_15_write_multiple_coils:
  137. # mb2hal.m.n.bit (input)
  138. # fnct_16_write_multiple_registers:
  139. # mb2hal.m.n.float (input)
  140. # mb2hal.m.n.int (input)
  141. # Both pin values are added and limited to 65535 (UINT16_MAX). Normally use one and let the other open (read as 0).
  142. #
  143. # m = HAL_TX_NAME or transaction number if not set, n = element number (NELEMENTS) or name from PIN_NAMES
  144. # Example: mb2hal.00.01.<type> (transaction=00, second register=01 (00 is the first one))
  145. # mb2hal.TxName.01.<type> (HAL_TX_NAME=TxName, second register=01 (00 is the first one))
  146. MB_TX_CODE=fnct_03_read_holding_registers
  147.  
  148. #OPTIONAL: Response timeout for this transaction. In INTEGER ms. Defaults to 500 ms.
  149. #This is how much to wait for 1st byte before raise an error.
  150. MB_RESPONSE_TIMEOUT_MS=500
  151.  
  152. #OPTIONAL: Byte timeout for this transaction. In INTEGER ms. Defaults to 500 ms.
  153. #This is how much to wait from byte to byte before raise an error.
  154. MB_BYTE_TIMEOUT_MS=500
  155.  
  156. #OPTIONAL: Instead of giving the transaction number, use a name.
  157. #Example: mb2hal.00.01 could become mb2hal.plcin.01
  158. #The name must not exceed 28 characters.
  159. #NOTE: when using names be careful that you dont end up with two transactions
  160. #using the same name.
  161. HAL_TX_NAME=remoteIOcfg
  162.  
  163. #OPTIONAL: Maximum update rate in HZ. Defaults to 0.0 (0.0 = as soon as available = infinite).
  164. #NOTE: This is a maximum rate and the actual rate may be lower.
  165. #If you want to calculate it in ms use (1000 / required_ms).
  166. #Example: 100 ms = MAX_UPDATE_RATE=10.0, because 1000.0 ms / 100.0 ms = 10.0 Hz
  167. MAX_UPDATE_RATE=0.0
  168.  
  169. #OPTIONAL: Debug level for this transaction only.
  170. #See INIT_DEBUG parameter above.
  171. DEBUG=2
  172.  
  173. #While DEBUGGING transactions note the returned "ret[]" value correspond to:
  174. #/* Modbus protocol exceptions */
  175. #ILLEGAL_FUNCTION -0x01 the FUNCTION code received in the query is not allowed or invalid.
  176. #ILLEGAL_DATA_ADDRESS -0x02 the DATA ADDRESS received in the query is not an allowable address for the slave or is invalid.
  177. #ILLEGAL_DATA_VALUE -0x03 a VALUE contained in the data query field is not an allowable value or is invalid.
  178. #SLAVE_DEVICE_FAILURE -0x04 SLAVE (or MASTER) device unrecoverable FAILURE while attempting to perform the requested action.
  179. #SERVER_FAILURE -0x04 (see above).
  180. #ACKNOWLEDGE -0x05 This response is returned to PREVENT A TIMEOUT in the master.
  181. # A long duration of time is required to process the request in the slave.
  182. #SLAVE_DEVICE_BUSY -0x06 The slave (or server) is BUSY. Retrasmit the request later.
  183. #SERVER_BUSY -0x06 (see above).
  184. #NEGATIVE_ACKNOWLEDGE -0x07 Unsuccessful programming request using function code 13 or 14.
  185. #MEMORY_PARITY_ERROR -0x08 SLAVE parity error in MEMORY.
  186. #GATEWAY_PROBLEM_PATH -0x0A (-10) Gateway path(s) not available.
  187. #GATEWAY_PROBLEM_TARGET -0x0B (-11) The target device failed to repond (generated by master, not slave).
  188. #/* Program or connection */
  189. #COMM_TIME_OUT -0x0C (-12)
  190. #PORT_SOCKET_FAILURE -0x0D (-13)
  191. #SELECT_FAILURE -0x0E (-14)
  192. #TOO_MANY_DATAS -0x0F (-15)
  193. #INVALID_CRC -0x10 (-16)
  194. #INVALID_EXCEPTION_CODE -0x11 (-17)
  195.  
  196. [TRANSACTION_01]
  197. MB_TX_CODE=fnct_01_read_coils
  198. FIRST_ELEMENT=1024
  199. NELEMENTS=24
  200. HAL_TX_NAME=remoteIOin
  201. MAX_UPDATE_RATE=0.0
  202. DEBUG=1
  203.  
  204. [TRANSACTION_02]
  205. MB_TX_CODE=fnct_02_read_discrete_inputs
  206. FIRST_ELEMENT=1280
  207. NELEMENTS=8
  208. HAL_TX_NAME=readStatus
  209. MAX_UPDATE_RATE=0.0
  210.  
  211. [TRANSACTION_03]
  212. MB_TX_CODE=fnct_05_write_single_coil
  213. FIRST_ELEMENT=100
  214. NELEMENTS=1
  215. HAL_TX_NAME=setEnableout
  216. MAX_UPDATE_RATE=0.0
  217.  
  218. [TRANSACTION_04]
  219. MB_TX_CODE=fnct_15_write_multiple_coils
  220. FIRST_ELEMENT=150
  221. NELEMENTS=10
  222. HAL_TX_NAME=remoteIOout
  223. MAX_UPDATE_RATE=0.0
  224.  
  225. [TRANSACTION_05]
  226. LINK_TYPE=serial
  227. SERIAL_PORT=/dev/ttyS0
  228. SERIAL_BAUD=115200
  229. SERIAL_BITS=8
  230. SERIAL_PARITY=none
  231. SERIAL_STOP=2
  232. SERIAL_DELAY_MS=50
  233. MB_SLAVE_ID=1
  234. MB_TX_CODE=fnct_03_read_holding_registers
  235. FIRST_ELEMENT=1
  236. NELEMENTS=2
  237. HAL_TX_NAME=XDrive01
  238. MAX_UPDATE_RATE=0.0
  239. DEBUG=1
  240.  
  241. [TRANSACTION_06]
  242. MB_TX_CODE=fnct_04_read_input_registers
  243. FIRST_ELEMENT=12
  244. NELEMENTS=3
  245. HAL_TX_NAME=XDrive02
  246. MAX_UPDATE_RATE=10.0
  247. DEBUG=1
  248.  
  249. [TRANSACTION_07]
  250. MB_TX_CODE=fnct_06_write_single_register
  251. FIRST_ELEMENT=20
  252. NELEMENTS=1
  253. HAL_TX_NAME=XDrive03
  254. MAX_UPDATE_RATE=0.0
  255. DEBUG=1
  256.  
  257. [TRANSACTION_08]
  258. MB_TX_CODE=fnct_16_write_multiple_registers
  259. FIRST_ELEMENT=55
  260. NELEMENTS=8
  261. HAL_TX_NAME=XDrive04
  262. MAX_UPDATE_RATE=10.0
  263. DEBUG=1
  264.  
Advertisement
Add Comment
Please, Sign In to add comment