question about MB2HAL send float data.
10 Jun 2017 07:50 #94386
by zhcong
question about MB2HAL send float data. was created by zhcong
I use MB2HAL send data to my PLC, and It's good when I send boolean data, but I can't get good effect when with float data. Like this: PLC will get "6" when MB2HAL send "6.347893". How can I get the real num by MB2HAL?
Thanks.
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
10 Jun 2017 11:56 #94388
by Todd Zuercher
Replied by Todd Zuercher on topic question about MB2HAL send float data.
What is the mb2hal hall pin called that you are using to send your float?
Please Log in or Create an account to join the conversation.
10 Jun 2017 13:43 - 10 Jun 2017 13:44 #94390
by zhcong
Replied by zhcong on topic question about MB2HAL send float data.
I don't know what is it, here is my .ini file:and this is net command:I need send those three float numbers to PLC.
Thanks again.
[TRANSACTION_05]
LINK_TYPE=tcp
TCP_IP=192.168.0.1
TCP_PORT=502
MB_SLAVE_ID=1
FIRST_ELEMENT=1
NELEMENTS=3
MB_TX_CODE=fnct_16_write_multiple_registers
HAL_TX_NAME=aixs-step
MAX_UPDATE_RATE=0.0
DEBUG=0
net xstep-en mb2hal.aixs-step.00 <= axis.0.joint-vel-cmd
net ystep-en mb2hal.aixs-step.01 <= axis.1.joint-vel-cmd
net zstep-en mb2hal.aixs-step.02 <= axis.2.joint-vel-cmd
Thanks again.
Last edit: 10 Jun 2017 13:44 by zhcong.
Please Log in or Create an account to join the conversation.
13 Jun 2017 15:36 #94447
by Simpson36
Replied by Simpson36 on topic question about MB2HAL send float data.
Modbus is defined with 16 bit registers , so unless you have a custom made Modbus, you cannot send floats.
Mb2hal stuck float types I guess for convenience in having the correct data type that LinuxCNC is picky about, but that does not mean you can send or receive floats, it just means LinuxCNC will consider the number to be a float.
There are numerous ways to split up a float into multiple registers, but whatever method is used must be the same on both ends and there is no standard (to my knowledge) way of doing this.
For small numbers that do not require more than say 4 decimal places of accuracy, the 'down and dirty' way to get the float across is to multiply the float by say 1000 so that 6.347893 becomes 6347. On the receiving end, once you have the number pulled out of the Modbus register, just divide by 1,000.
There are slightly more complex 'cheats' and then there are proper ways to do it, but what you can do depends on whether you have access to any programming on the PLC end to rebuild the float.
Mb2hal stuck float types I guess for convenience in having the correct data type that LinuxCNC is picky about, but that does not mean you can send or receive floats, it just means LinuxCNC will consider the number to be a float.
There are numerous ways to split up a float into multiple registers, but whatever method is used must be the same on both ends and there is no standard (to my knowledge) way of doing this.
For small numbers that do not require more than say 4 decimal places of accuracy, the 'down and dirty' way to get the float across is to multiply the float by say 1000 so that 6.347893 becomes 6347. On the receiving end, once you have the number pulled out of the Modbus register, just divide by 1,000.
There are slightly more complex 'cheats' and then there are proper ways to do it, but what you can do depends on whether you have access to any programming on the PLC end to rebuild the float.
Please Log in or Create an account to join the conversation.
15 Jun 2017 02:15 #94519
by zhcong
Replied by zhcong on topic question about MB2HAL send float data.
Thanks!
Please Log in or Create an account to join the conversation.
16 Jun 2017 17:13 #94602
by Simpson36
Replied by Simpson36 on topic question about MB2HAL send float data.
If you want to thank me , you need to click the 'thank you' button. Otherwise, no gold star to stick on my lunch box . . . ![:-) :-)](/media/kunena/emoticons/smile.png)
Anyway, if anyone needs to move more accurate floats across the Jurassic Modbus Highway, just post what kind of processing you have on the PLC side, if any. I would be surprised if you have bit shifting, but there are some tricks that can be accomplished with simple math. You need a way to split the float into its integer and fractional components.
Conversion functions are needed. For example say your float is in a variable named 'jack', you need Integer_of_jack and fraction_of_jack which you can get thus:
integer_of_jack = int(jack)
to get the fractional is then simply: fraction_of_jack = jack - integer_of_jack.
Multiply the fractional as described in the previous 'down and dirty' and send the two components in two Modbus registers.
You need to accommodate leading zeros in the fractional, but you can send a pretty good sized float using this 'down and semi-dirty' method.
Hope this helps.
![:-) :-)](/media/kunena/emoticons/smile.png)
Anyway, if anyone needs to move more accurate floats across the Jurassic Modbus Highway, just post what kind of processing you have on the PLC side, if any. I would be surprised if you have bit shifting, but there are some tricks that can be accomplished with simple math. You need a way to split the float into its integer and fractional components.
Conversion functions are needed. For example say your float is in a variable named 'jack', you need Integer_of_jack and fraction_of_jack which you can get thus:
integer_of_jack = int(jack)
to get the fractional is then simply: fraction_of_jack = jack - integer_of_jack.
Multiply the fractional as described in the previous 'down and dirty' and send the two components in two Modbus registers.
You need to accommodate leading zeros in the fractional, but you can send a pretty good sized float using this 'down and semi-dirty' method.
Hope this helps.
The following user(s) said Thank You: tommylight
Please Log in or Create an account to join the conversation.
Time to create page: 0.096 seconds