The mapping of pins in MB2HAL
04 Jun 2017 16:06 #94051
by zhcong
The mapping of pins in MB2HAL was created by zhcong
I use MB2HAL to communicate with PLC, forgive me as a beginner, I don't know the mapping of pins to Modbus address. Like pin1 to Modbus address 10001(use modbus function code 2), how to write in configure file "mb2hal.ini"? how many pins should I configure them?
And another question is what the data type. Each pins will boolean or float data send to plc?
Thanks.
And another question is what the data type. Each pins will boolean or float data send to plc?
Thanks.
Please Log in or Create an account to join the conversation.
- Todd Zuercher
-
- Away
- Platinum Member
-
Less
More
- Posts: 4978
- Thank you received: 1377
04 Jun 2017 20:31 #94057
by Todd Zuercher
Replied by Todd Zuercher on topic The mapping of pins in MB2HAL
Unfortunately the documentation for Mb2hal is a little terse.
The names and types of pins created by Mb2hal is determined by what you put in the Mb2hal ini file. Specifically the transactions that you define there. There are at least 5 different transaction types that can be used. And these determine if the pins created are boolean, floats, inputs or outs.
fnct_02_read_discrete_inputs: creates boolean output HAL pins.
fnct_03_read_holding_registers: creates a floating point output HAL pins. also creates a u32 output HAL pins.
fnct_04_read_input_registers: creates a floating point output HAL pins.also creates a u32 output HAL pins.
fnct_15_write_multiple_coils: creates boolean input HAL pins.
fnct_16_write_multiple_registers: creates a floating point input HAL pins.
The number of hal pins created by each "transaction" is determined by the number of "elements" in that transaction.
The names of the hal pins created are the default name:
Example pin name for the 1st transaction 2nd element would be:
mb2hal.00.01 (transaction=00, second register=01 (00 is the first element))
or the transaction number can be replaced by name you define with
HAL_TX_NAME=name
Would give: mb2hal.name.01
The names and types of pins created by Mb2hal is determined by what you put in the Mb2hal ini file. Specifically the transactions that you define there. There are at least 5 different transaction types that can be used. And these determine if the pins created are boolean, floats, inputs or outs.
fnct_02_read_discrete_inputs: creates boolean output HAL pins.
fnct_03_read_holding_registers: creates a floating point output HAL pins. also creates a u32 output HAL pins.
fnct_04_read_input_registers: creates a floating point output HAL pins.also creates a u32 output HAL pins.
fnct_15_write_multiple_coils: creates boolean input HAL pins.
fnct_16_write_multiple_registers: creates a floating point input HAL pins.
The number of hal pins created by each "transaction" is determined by the number of "elements" in that transaction.
The names of the hal pins created are the default name:
Example pin name for the 1st transaction 2nd element would be:
mb2hal.00.01 (transaction=00, second register=01 (00 is the first element))
or the transaction number can be replaced by name you define with
HAL_TX_NAME=name
Would give: mb2hal.name.01
Please Log in or Create an account to join the conversation.
05 Jun 2017 03:16 #94067
by zhcong
Replied by zhcong on topic The mapping of pins in MB2HAL
This is one of pins configure:and this is captured by wireshark:Value is 000000, I just want to push pins' value to my PLC.
I have no idea.
[TRANSACTION_01]
MB_TX_CODE=fnct_15_write_multiple_coils
FIRST_ELEMENT=1701
NELEMENTS=24
HAL_TX_NAME=mb2hal.00.00
MAX_UPDATE_RATE=0.0
DEBUG=1
Modbus
Function Code: Write Multiple Coils (15)
Reference Number: 1701
Bit Count: 24
Byte Count: 3
Data: 000000
I have no idea.
![:S :S](/media/kunena/emoticons/dizzy.png)
Please Log in or Create an account to join the conversation.
- Todd Zuercher
-
- Away
- Platinum Member
-
Less
More
- Posts: 4978
- Thank you received: 1377
05 Jun 2017 04:03 #94070
by Todd Zuercher
Replied by Todd Zuercher on topic The mapping of pins in MB2HAL
If you want to use the default pin name, don't put in the line HAL_TX_NAME= at all.
If you put in what you did, the pin name would be "mb2hal.mb2hal.00.00.00" quite confusing if it even works at all.
Also the transaction numbering starts from 00. Plus I don't see any of the required transaction port info in the blurb of code you posted. Maybe you should post your whole mb2hal ini file.
If you put in what you did, the pin name would be "mb2hal.mb2hal.00.00.00" quite confusing if it even works at all.
Also the transaction numbering starts from 00. Plus I don't see any of the required transaction port info in the blurb of code you posted. Maybe you should post your whole mb2hal ini file.
Please Log in or Create an account to join the conversation.
05 Jun 2017 06:11 - 05 Jun 2017 08:42 #94072
by zhcong
Replied by zhcong on topic The mapping of pins in MB2HAL
Thanks.
Sum up my question now, I found Pins define now. if I want to send the Pin "axis.1.homed", should I write in configure:But value still zero. and this is my configure file:
Sum up my question now, I found Pins define now. if I want to send the Pin "axis.1.homed", should I write in configure:
[TRANSACTION_08]
MB_TX_CODE=fnct_15_write_multiple_coils
FIRST_ELEMENT=1709
NELEMENTS=1
HAL_TX_NAME=axis.1.homed
MAX_UPDATE_RATE=0.0
[MB2HAL_INIT]
#OPTIONAL: Debug level of init and INI file parsing.
# 0 = silent.
# 1 = error messages (default).
# 2 = OK confirmation messages.
# 3 = debugging messages.
INIT_DEBUG=3
#OPTIONAL: HAL module (component) name. Defaults to "mb2hal".
HAL_MODULE_NAME=mb2hal
#OPTIONAL: Insert a delay of "FLOAT seconds" between transactions in order
#to not to have a lot of logging and facilitate the debugging.
#Usefull when using DEBUG=3 (NOT INIT_DEBUG=3)
#It affects ALL transactions.
#Use "0.0" for normal activity.
SLOWDOWN=0.0
#REQUIRED: The number of total Modbus transactions. There is no maximum.
TOTAL_TRANSACTIONS=9
#One transaction section is required per transaction, starting at 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.
[TRANSACTION_00]
LINK_TYPE=tcp
TCP_IP=192.168.0.1
TCP_PORT=502
MB_SLAVE_ID=1
FIRST_ELEMENT=1701
NELEMENTS=1
MB_TX_CODE=fnct_15_write_multiple_coils
#The pins are named based on component name, transaction number and order number.
#Example: mb2hal.00.01 (transaction=00, second register=01 (00 is the first one))
#OPTIONAL: Instead of giving the transaction number, use a name.
#Example: mb2hal.00.01 could become mb2hal.plcin.01
#The name must not exceed 32 characters.
#NOTE: when using names be careful that you dont end up with two transactions
#usign the same name.
HAL_TX_NAME=axis.2.in-position
MAX_UPDATE_RATE=0.0
[TRANSACTION_01]
LINK_TYPE=tcp
TCP_IP=192.168.0.1
TCP_PORT=502
MB_TX_CODE=fnct_15_write_multiple_coils
FIRST_ELEMENT=1702
NELEMENTS=1
HAL_TX_NAME=axis.1.in-position
MAX_UPDATE_RATE=0.0
DEBUG=1
[TRANSACTION_02]
MB_TX_CODE=fnct_15_write_multiple_coils
FIRST_ELEMENT=1703
NELEMENTS=1
HAL_TX_NAME=axis.0.in-position
MAX_UPDATE_RATE=0.0
DEBUG=1
[TRANSACTION_03]
MB_TX_CODE=fnct_15_write_multiple_coils
FIRST_ELEMENT=1704
NELEMENTS=128
HAL_TX_NAME=axis.2.homed
MAX_UPDATE_RATE=0.0
DEBUG=1
[TRANSACTION_04]
MB_TX_CODE=fnct_15_write_multiple_coils
FIRST_ELEMENT=1705
NELEMENTS=1
HAL_TX_NAME=axis.1.homed
MAX_UPDATE_RATE=0.0
DEBUG=1
[TRANSACTION_05]
MB_TX_CODE=fnct_15_write_multiple_coils
FIRST_ELEMENT=1706
NELEMENTS=1
HAL_TX_NAME=axis.2.homing
MAX_UPDATE_RATE=0.0
DEBUG=1
[TRANSACTION_06]
MB_TX_CODE=fnct_15_write_multiple_coils
FIRST_ELEMENT=1707
NELEMENTS=1
HAL_TX_NAME=axis.1.homing
MAX_UPDATE_RATE=0.0
DEBUG=1
[TRANSACTION_07]
MB_TX_CODE=fnct_15_write_multiple_coils
FIRST_ELEMENT=1708
NELEMENTS=1
HAL_TX_NAME=axis.0.homing
MAX_UPDATE_RATE=0.0
DEBUG=1
[TRANSACTION_08]
MB_TX_CODE=fnct_15_write_multiple_coils
FIRST_ELEMENT=1709
NELEMENTS=1
HAL_TX_NAME=axis.0.homed
MAX_UPDATE_RATE=0.0
DEBUG=1
Last edit: 05 Jun 2017 08:42 by zhcong.
Please Log in or Create an account to join the conversation.
- Todd Zuercher
-
- Away
- Platinum Member
-
Less
More
- Posts: 4978
- Thank you received: 1377
05 Jun 2017 11:42 #94081
by Todd Zuercher
Replied by Todd Zuercher on topic The mapping of pins in MB2HAL
No, You would connect the pin created by Mb2hal, to the pin axis.1.homed in (one of) your hal file(s). (With a signal name of course.)
The string that you put beside the HAL_TX_NAME= only becomes part of the pin name that Mb2hal creates.
Example: mb2hal._____.NN (where the underscore I placed in the example)
and NN equals the element number in the transaction.
HAL_TX_NAME= only replaces the default transaction number that would be used as part of the pin name, if nothing is specified for it. I would avoid using periods in the HAL_TX_NAME as it will confuse the normal hal pin naming scheme.
So in your example for the all of your transactions are sending data to the PLC. (Is that what you want to do?)
And since they are all similar boolean writes to contiguous registers, they could actually all be accomplished with a single transaction with 9 elements. Doing this should improve your processing times.
The string that you put beside the HAL_TX_NAME= only becomes part of the pin name that Mb2hal creates.
Example: mb2hal._____.NN (where the underscore I placed in the example)
and NN equals the element number in the transaction.
HAL_TX_NAME= only replaces the default transaction number that would be used as part of the pin name, if nothing is specified for it. I would avoid using periods in the HAL_TX_NAME as it will confuse the normal hal pin naming scheme.
So in your example for the all of your transactions are sending data to the PLC. (Is that what you want to do?)
And since they are all similar boolean writes to contiguous registers, they could actually all be accomplished with a single transaction with 9 elements. Doing this should improve your processing times.
Please Log in or Create an account to join the conversation.
05 Jun 2017 13:34 - 05 Jun 2017 15:00 #94091
by zhcong
Replied by zhcong on topic The mapping of pins in MB2HAL
I am wrong. But the pin created by Mb2hal is this used to do what? Can I get or change CNC status by modbus? For example, the status of pin "axis.1.homed", can I put it to PLC by MB2HAL?
can I use HAL command "net"?
can I use HAL command "net"?
Last edit: 05 Jun 2017 15:00 by zhcong.
Please Log in or Create an account to join the conversation.
- Todd Zuercher
-
- Away
- Platinum Member
-
Less
More
- Posts: 4978
- Thank you received: 1377
05 Jun 2017 15:01 #94099
by Todd Zuercher
Replied by Todd Zuercher on topic The mapping of pins in MB2HAL
Yes, by connecting pins in the hal file.
For example to connect the pin "axis.1.homed" to the 2nd transaction 3rd element pin created by Mb2hal (assuming default pin names) you could use a line like this in your hal file.
net y-homed <= axis.1.homed => mb2hal.01.02
This would create a "signal" in hal named "y-homed" and connect the output pin "axis.1.homed" and the input pin "mb2hal.01.02" to it and setting the value of any input pins connected to "y-homed" in this line or any other "net y-homed" line (in this hal file or any other) to the same value "axis.1.homed".
For example to connect the pin "axis.1.homed" to the 2nd transaction 3rd element pin created by Mb2hal (assuming default pin names) you could use a line like this in your hal file.
net y-homed <= axis.1.homed => mb2hal.01.02
This would create a "signal" in hal named "y-homed" and connect the output pin "axis.1.homed" and the input pin "mb2hal.01.02" to it and setting the value of any input pins connected to "y-homed" in this line or any other "net y-homed" line (in this hal file or any other) to the same value "axis.1.homed".
Please Log in or Create an account to join the conversation.
- Todd Zuercher
-
- Away
- Platinum Member
-
Less
More
- Posts: 4978
- Thank you received: 1377
05 Jun 2017 15:08 #94100
by Todd Zuercher
Replied by Todd Zuercher on topic The mapping of pins in MB2HAL
The pins created by Mb2hal are either input pins (if they are from a write function) or output pins (read function).
They are how data is exchanged with Linuxcnc via hal. Hal input pins receive data from hal, outputs give data to hal.
Reading the documentation for Linuxcnc can be very enlightening.
linuxcnc.org/docs/html/hal/intro.html
They are how data is exchanged with Linuxcnc via hal. Hal input pins receive data from hal, outputs give data to hal.
Reading the documentation for Linuxcnc can be very enlightening.
linuxcnc.org/docs/html/hal/intro.html
The following user(s) said Thank You: zhcong
Please Log in or Create an account to join the conversation.
06 Jun 2017 00:08 #94129
by zhcong
Replied by zhcong on topic The mapping of pins in MB2HAL
Thank you very much, you solved my big problem.
Please Log in or Create an account to join the conversation.
Time to create page: 0.590 seconds