MB2HAL - reading multiple coils limited to 5 when using names
27 Nov 2022 13:38 #257730
by petervg
I'm trying to read multiple coils using MB2HAL, but something strange happens when I want to read more than 5 coils if I use names to identify the signals
This ini-file works:
SERIAL_PORT=/dev/ttyUSB0
SERIAL_BAUD=9600
SERIAL_BITS=8
SERIAL_PARITY=none
SERIAL_STOP=1
SERIAL_DELAY_MS=100
MB_SLAVE_ID=1
FIRST_ELEMENT=6
MB_TX_CODE=fnct_01_read_coils
PIN_NAMES=INPUT1,INPUT2,INPUT3,INPUT4,INPUT5
MB_RESPONSE_TIMEOUT_MS=500
MB_BYTE_TIMEOUT_MS=500
HAL_TX_NAME=VDF_RUNSTOP
MAX_UPDATE_RATE=10.0
when linunxcnc is started, this is the log I can see in terminal and all runs well
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [INIT_DEBUG] [4]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [VERSION] [1001]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [HAL_MODULE_NAME] [mb2hal]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [SLOWDOWN] [0.000]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [TOTAL_TRANSACTIONS] [1]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [LINK_TYPE] [serial] [0]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_PORT] [/dev/ttyUSB0]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_BAUD] [9600]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_BITS] [8]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_PARITY] [none]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_STOP] [1]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_DELAY_MS] [100]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_SLAVE_ID] [1]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [FIRST_ELEMENT] [6]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [PIN_NAMES] [INPUT1,INPUT2,INPUT3,INPUT4,INPUT5]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [NELEMENTS] [5]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MAX_UPDATE_RATE] [10.000]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_RESPONSE_TIMEOUT_MS] [500]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_BYTE_TIMEOUT_MS] [500]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [DEBUG] [1]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_TX_CODE] [fnct_01_read_coils] [7]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [HAL_TX_NAME] [VDF_RUNSTOP]
mb2hal parse_ini_file OK: parse_transaction_section 0 OK
mb2hal main OK: parse_ini_file done OK
mb2hal init_mb_links DEBUG: LINK 0 (RTU) link_type[0] device[/dev/ttyUSB0] baud[9600] data[8] parity[N] stop[1] fd[-1]
mb2hal main OK: init_gbl.mb_link done OK
mb2hal init_mb_tx DEBUG: MB_TX 0 lk_n[0] tx_n[0] cfg_dbg[1] lk_dbg[0] t_inc[0.100] nxt_t[0.000]
mb2hal main OK: init_gbl.mb_tx done OK
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.num_errors]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT1]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT2]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT3]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT4]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT5]
mb2hal main OK: HAL components created OK
mb2hal main OK: Link thread loop and logic 0 created OK
mb2hal main OK: mb2hal is running
But the VFD has 7 inputs, so I would like to read them in the same transaction and I changed the ini file to:
SERIAL_PORT=/dev/ttyUSB0
SERIAL_BAUD=9600
SERIAL_BITS=8
SERIAL_PARITY=none
SERIAL_STOP=1
SERIAL_DELAY_MS=100
MB_SLAVE_ID=1
FIRST_ELEMENT=6
MB_TX_CODE=fnct_01_read_coils
PIN_NAMES=INPUT1,INPUT2,INPUT3,INPUT4,INPUT5,INPUT6,INPUT7
MB_RESPONSE_TIMEOUT_MS=500
MB_BYTE_TIMEOUT_MS=500
HAL_TX_NAME=VDF_RUNSTOP
MAX_UPDATE_RATE=10.0
And this results in linuxcnc reporting an incorrect nr of elements and crashing:
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [INIT_DEBUG] [4]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [VERSION] [1001]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [HAL_MODULE_NAME] [mb2hal]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [SLOWDOWN] [0.000]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [TOTAL_TRANSACTIONS] [1]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [LINK_TYPE] [serial] [0]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_PORT] [/dev/ttyUSB0]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_BAUD] [9600]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_BITS] [8]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_PARITY] [none]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_STOP] [1]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_DELAY_MS] [100]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_SLAVE_ID] [1]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [FIRST_ELEMENT] [6]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [PIN_NAMES] [INPUT1,INPUT2,INPUT3,INPUT4,INPUT5,INPUT6,INPUT7]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [NELEMENTS] [17] <- This is not correct (should be 7 as stated above)
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MAX_UPDATE_RATE] [10.000]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_RESPONSE_TIMEOUT_MS] [500]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_BYTE_TIMEOUT_MS] [500]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [DEBUG] [1]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_TX_CODE] [fnct_01_read_coils] [7]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [HAL_TX_NAME] [VDF_RUNSTOP]
mb2hal parse_ini_file OK: parse_transaction_section 0 OK
mb2hal main OK: parse_ini_file done OK
mb2hal init_mb_links DEBUG: LINK 0 (RTU) link_type[0] device[/dev/ttyUSB0] baud[9600] data[8] parity[N] stop[1] fd[-1]
mb2hal main OK: init_gbl.mb_link done OK
mb2hal init_mb_tx DEBUG: MB_TX 0 lk_n[0] tx_n[0] cfg_dbg[1] lk_dbg[0] t_inc[0.100] nxt_t[0.000]
mb2hal main OK: init_gbl.mb_tx done OK
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.num_errors]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT1]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT2]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT3]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT4]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT5]
./custom.hal:4: mb2hal exited without becoming ready
Shutting down and cleaning up LinuxCNC...
Running HAL shutdown script
hm2_5i25.0: dropping AnyIO board at 0000:04:01.0
hm2/hm2_5i25.0: unregistered
RTAPI_PCI: Unmapped 65536 bytes at 0x7f7bf3458000
hm2_pci: driver unloaded
hm2: unloading
Note: Using POSIX realtime
LinuxCNC terminated with an error.
If I use the parameter NELEMEMTS and set this to 7, all works properly.
I did compile linuxcnc 2.8 from source and used the MB2HAL sourcecode from 2.9 as reading coils is not suported in 2.8. I'm reluctant to switch completely to 2.9 as his has not been released yet.
This ini-file works:
SERIAL_PORT=/dev/ttyUSB0
SERIAL_BAUD=9600
SERIAL_BITS=8
SERIAL_PARITY=none
SERIAL_STOP=1
SERIAL_DELAY_MS=100
MB_SLAVE_ID=1
FIRST_ELEMENT=6
MB_TX_CODE=fnct_01_read_coils
PIN_NAMES=INPUT1,INPUT2,INPUT3,INPUT4,INPUT5
MB_RESPONSE_TIMEOUT_MS=500
MB_BYTE_TIMEOUT_MS=500
HAL_TX_NAME=VDF_RUNSTOP
MAX_UPDATE_RATE=10.0
when linunxcnc is started, this is the log I can see in terminal and all runs well
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [INIT_DEBUG] [4]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [VERSION] [1001]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [HAL_MODULE_NAME] [mb2hal]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [SLOWDOWN] [0.000]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [TOTAL_TRANSACTIONS] [1]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [LINK_TYPE] [serial] [0]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_PORT] [/dev/ttyUSB0]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_BAUD] [9600]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_BITS] [8]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_PARITY] [none]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_STOP] [1]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_DELAY_MS] [100]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_SLAVE_ID] [1]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [FIRST_ELEMENT] [6]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [PIN_NAMES] [INPUT1,INPUT2,INPUT3,INPUT4,INPUT5]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [NELEMENTS] [5]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MAX_UPDATE_RATE] [10.000]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_RESPONSE_TIMEOUT_MS] [500]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_BYTE_TIMEOUT_MS] [500]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [DEBUG] [1]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_TX_CODE] [fnct_01_read_coils] [7]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [HAL_TX_NAME] [VDF_RUNSTOP]
mb2hal parse_ini_file OK: parse_transaction_section 0 OK
mb2hal main OK: parse_ini_file done OK
mb2hal init_mb_links DEBUG: LINK 0 (RTU) link_type[0] device[/dev/ttyUSB0] baud[9600] data[8] parity[N] stop[1] fd[-1]
mb2hal main OK: init_gbl.mb_link done OK
mb2hal init_mb_tx DEBUG: MB_TX 0 lk_n[0] tx_n[0] cfg_dbg[1] lk_dbg[0] t_inc[0.100] nxt_t[0.000]
mb2hal main OK: init_gbl.mb_tx done OK
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.num_errors]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT1]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT2]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT3]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT4]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT5]
mb2hal main OK: HAL components created OK
mb2hal main OK: Link thread loop and logic 0 created OK
mb2hal main OK: mb2hal is running
But the VFD has 7 inputs, so I would like to read them in the same transaction and I changed the ini file to:
SERIAL_PORT=/dev/ttyUSB0
SERIAL_BAUD=9600
SERIAL_BITS=8
SERIAL_PARITY=none
SERIAL_STOP=1
SERIAL_DELAY_MS=100
MB_SLAVE_ID=1
FIRST_ELEMENT=6
MB_TX_CODE=fnct_01_read_coils
PIN_NAMES=INPUT1,INPUT2,INPUT3,INPUT4,INPUT5,INPUT6,INPUT7
MB_RESPONSE_TIMEOUT_MS=500
MB_BYTE_TIMEOUT_MS=500
HAL_TX_NAME=VDF_RUNSTOP
MAX_UPDATE_RATE=10.0
And this results in linuxcnc reporting an incorrect nr of elements and crashing:
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [INIT_DEBUG] [4]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [VERSION] [1001]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [HAL_MODULE_NAME] [mb2hal]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [SLOWDOWN] [0.000]
mb2hal parse_common_section DEBUG: [MB2HAL_INIT] [TOTAL_TRANSACTIONS] [1]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [LINK_TYPE] [serial] [0]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_PORT] [/dev/ttyUSB0]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_BAUD] [9600]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_BITS] [8]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_PARITY] [none]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_STOP] [1]
mb2hal parse_serial_subsection DEBUG: [TRANSACTION_00] [SERIAL_DELAY_MS] [100]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_SLAVE_ID] [1]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [FIRST_ELEMENT] [6]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [PIN_NAMES] [INPUT1,INPUT2,INPUT3,INPUT4,INPUT5,INPUT6,INPUT7]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [NELEMENTS] [17] <- This is not correct (should be 7 as stated above)
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MAX_UPDATE_RATE] [10.000]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_RESPONSE_TIMEOUT_MS] [500]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_BYTE_TIMEOUT_MS] [500]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [DEBUG] [1]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [MB_TX_CODE] [fnct_01_read_coils] [7]
mb2hal parse_transaction_section DEBUG: [TRANSACTION_00] [HAL_TX_NAME] [VDF_RUNSTOP]
mb2hal parse_ini_file OK: parse_transaction_section 0 OK
mb2hal main OK: parse_ini_file done OK
mb2hal init_mb_links DEBUG: LINK 0 (RTU) link_type[0] device[/dev/ttyUSB0] baud[9600] data[8] parity[N] stop[1] fd[-1]
mb2hal main OK: init_gbl.mb_link done OK
mb2hal init_mb_tx DEBUG: MB_TX 0 lk_n[0] tx_n[0] cfg_dbg[1] lk_dbg[0] t_inc[0.100] nxt_t[0.000]
mb2hal main OK: init_gbl.mb_tx done OK
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.num_errors]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT1]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT2]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT3]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT4]
mb2hal create_each_mb_tx_hal_pins DEBUG: mb_tx_num [0] pin_name [mb2hal.VDF_RUNSTOP.INPUT5]
./custom.hal:4: mb2hal exited without becoming ready
Shutting down and cleaning up LinuxCNC...
Running HAL shutdown script
hm2_5i25.0: dropping AnyIO board at 0000:04:01.0
hm2/hm2_5i25.0: unregistered
RTAPI_PCI: Unmapped 65536 bytes at 0x7f7bf3458000
hm2_pci: driver unloaded
hm2: unloading
Note: Using POSIX realtime
LinuxCNC terminated with an error.
If I use the parameter NELEMEMTS and set this to 7, all works properly.
I did compile linuxcnc 2.8 from source and used the MB2HAL sourcecode from 2.9 as reading coils is not suported in 2.8. I'm reluctant to switch completely to 2.9 as his has not been released yet.
Please Log in or Create an account to join the conversation.
27 Nov 2022 19:08 #257752
by JPL
Replied by JPL on topic MB2HAL - reading multiple coils limited to 5 when using names
Can you upload your ini file here so we can have a closer look.
Please Log in or Create an account to join the conversation.
28 Nov 2022 12:00 #257839
by HansU
Replied by HansU on topic MB2HAL - reading multiple coils limited to 5 when using names
Interesting, I could reproduce this. So nothing wrong with your config as it seems. This seems to affect also other other function codes if you define more than 5 pin names.
I'll will have a deeper look in the code but probably not the next days.
I'll will have a deeper look in the code but probably not the next days.
The following user(s) said Thank You: JPL
Please Log in or Create an account to join the conversation.
28 Nov 2022 18:36 #257878
by HansU
Replied by HansU on topic MB2HAL - reading multiple coils limited to 5 when using names
I created an issue for that. You can track the progress there: github.com/LinuxCNC/linuxcnc/issues/2162
The following user(s) said Thank You: tommylight, JPL
Please Log in or Create an account to join the conversation.
29 Nov 2022 08:44 - 29 Nov 2022 08:52 #257952
by HansU
Replied by HansU on topic MB2HAL - reading multiple coils limited to 5 when using names
You can work around this bug if you increase the number in this definition
on this line github.com/LinuxCNC/linuxcnc/blob/bf664e...l/mb2hal_init.c#L127
But this is no final solution. I have to dig in deeper
#define NAME_ALLOC_SIZE 5
But this is no final solution. I have to dig in deeper
Last edit: 29 Nov 2022 08:52 by HansU.
Please Log in or Create an account to join the conversation.
29 Nov 2022 17:20 #257999
by HansU
Replied by HansU on topic MB2HAL - reading multiple coils limited to 5 when using names
I think I found the root. Would be nice if you can test that if it works for you as well:
github.com/LinuxCNC/linuxcnc/pull/2167
github.com/LinuxCNC/linuxcnc/pull/2167
Please Log in or Create an account to join the conversation.
02 Dec 2022 20:32 #258362
by petervg
Replied by petervg on topic MB2HAL - reading multiple coils limited to 5 when using names
Hi Hans,
thanks!! I had the machine configured for now just using NELEMENTS and using a separate document to keep track of everything because I wanted to get the VFD operating. I wasn't in the shop for a few days, but I'll try to test the new code this weekend to see if naming now works properly and report back.
Much appreciated!
thanks!! I had the machine configured for now just using NELEMENTS and using a separate document to keep track of everything because I wanted to get the VFD operating. I wasn't in the shop for a few days, but I'll try to test the new code this weekend to see if naming now works properly and report back.
Much appreciated!
Please Log in or Create an account to join the conversation.
Time to create page: 0.088 seconds