Hard @ Work

PLC-5 - String to Floating Conversion

5 posts in this topic

Hi guys,

I think I know the answer to this question, but would like to ask it just in case there is some miraculous logic out there.  What I need to do is read a string from an ASCII device and convert it to a floating register.  This is not the difficult part, my dilemma is, the HEX value that I am reading from the ASCII device is 4 bytes in length, so "#### ####".  The highest possible value would be "FFFF FFFF" hex.  How can i convert this to a floating register while in the process of doing this conversion need to convert it to an integer first where even just FFFF(hex) = 65535(dec). 

The application is a measuring device that measures only in (mm) and will be measuring long distances up to 152,400 mm.  There will be no decimals.

Share this post


Link to post
Share on other sites

Forgive me, but you stated that the ACSII value comes in HEX and represents a whole number value in mm, so why do you need a floating value?

Either way, you can create some test code in the PLC and find the right combination the yields the known value and works over the entire span/range of expected values.

Edited by pcmccartney1

Share this post


Link to post
Share on other sites

pcmaccartney1.....I would like it in a floating register, only for the simple reason that there is no DINT available in PLC-5 and it would be easier to work with than trying to use 2 INT to display the distance.  Even though it would be a floating register, I would not need to use the decimal values as there would be none.  If I could display the value in 1 INT register only, I would do this, but because an INT register is only capable of 32767, and the value/span would be greater than 32767, in this case 152, 400, I need to some how get it into a Floating register to work with.   When the value is smaller that 32767, it is ok, but anything higher than 32767 is the problem.  But the problem I am having is I am guessing I need to first get it to 2 INT from a string, before I can get it into a floating register.  Is there something I am missing??

Share this post


Link to post
Share on other sites

Sorry, missed the PLC5 and lack of DINT point.

I've got no bright ideas here, only a guesses.

Use the AEX to split the string into two (upper and lower) strings.

Convert both strings to INTs

I don't think the lower word will be the issue, rather the upper word.

Convert both INTs to Floats.  Do the two floats look like the upper and lower parts of the number?

Then experiment with BSL or MUL on the high word Float to another float.  Maybe add the two floats together.

Just spit-balling here.

Share this post


Link to post
Share on other sites

Can you provide an example of a real world measurement and its corresponding ASCII registers?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now