Sign in to follow this  
Followers 0
TPCTJ

ASCII Floating Point Conversion

6 posts in this topic

OK, so I have a CL L61 and am communicating with a Veeder-Root 350+. I have established the comm and am getting valid data. The problem I am having is the data I am receiving comes in as a string of 8 SINTs which when the “Style” of the data format for each SINT is changed to ASCII, is when I get the character I need. For example: From the first word to the last in DECIMAL – 52 , 49 , 70 , 70 , 68 , 49 , 54 , 48 these are 16 bit SINTs that translate in ASCII to – 4 , 1 , F , F , D , 1 , 6 , 0. Now, each one of these characters can be translated into 4 bit nibbles because in HEX they need only 4 bits…. With a piece of paper, I can take the 0100 0001 1111 1111 1101 0001 0110 0000 and make that the floating point number I need. It’s easier to see like this: 4 1 F F D 1 6 0 0100 0001 1111 1111 1101 0001 0110 0000 The formula to break this down is quite cumbersome and I am not sure if the PLC is up to the challenge. First, you take the very first bit, if it is 0 the number is positive 1 is negative. Then the next eight bits is called the exponent, subtract 127 from that number (131 in this case) and you take 2^(131-127) to get 16. The last 23 bits are called the mantissa. Take this number, 8,376,672 and divide it by 8,338,608 and add 1 to get 1.99857711. Multiply this by 16 from earlier to get 31.98. I am looking into some bit shifting and bit pulling instructions to maybe get what I need. If you know of a better way to do this, I would greatly appreciate your help. Thank you, T.J.

Share this post


Link to post
Share on other sites
The string is a HEX ASCII string basically HEX ASCII is taking the nibbles of a Hex data packet and transmitting thing in Human Readable form. I did a quick Google search and although the available documentation is limited I did find some good information on one of my Linked-In groups. There are 2 instructions to do this. They are STOD (String to DINT) or DTOS (Dint to string. You must first create an string data type(If it is not already in string form) and copy your data into the SINT's then assign a length to the string. ControlLogix string data is already in ASCII format. Look at your string tag and expand it. The data you are looking for is in "TestString.Data" which is an array of SINTs (SINT[82]). Expand this array and you will see each character in the string. The default "style" for viewing this data is ASCII. Chose something else and you will see the corresponding representation. For our example, assume the value of "test_string" is "Testing 1-2-3". Viewing the array in "HEX" mode yields test_string.DATA[0] = 16#54 test_string.DATA[1] = 16#65 test_string.DATA[2] = 16#73 test_string.DATA[3] = 16#74 test_string.DATA[4] = 16#69 test_string.DATA[5] = 16#6e test_string.DATA[6] = 16#67 and so forth The string functions mentioned previously convert a DINT to a string. For example DToS(54321) converts the single DINT to a series of concatenated ASCII characters ("5" & "4" & "3" & "2" & "1") SToD reverses the operation, converting a string (array of characters) into a single equivalent DINT. Hope this helps you out. Perhaps someone in this group can expand upon this if you have additional questions.

Share this post


Link to post
Share on other sites
The string is a HEX ASCII string basically HEX ASCII is taking the nibbles of a Hex data packet and transmitting thing in Human Readable form. I did a quick Google search and although the available documentation is limited I did find some good information on one of my Linked-In groups. There are 2 instructions to do this. They are STOD (String to DINT) or DTOS (Dint to string. You must first create an string data type(If it is not already in string form) and copy your data into the SINT's then assign a length to the string. ControlLogix string data is already in ASCII format. Look at your string tag and expand it. The data you are looking for is in "TestString.Data" which is an array of SINTs (SINT[82]). Expand this array and you will see each character in the string. The default "style" for viewing this data is ASCII. Chose something else and you will see the corresponding representation. For our example, assume the value of "test_string" is "Testing 1-2-3". Viewing the array in "HEX" mode yields test_string.DATA[0] = 16#54 test_string.DATA[1] = 16#65 test_string.DATA[2] = 16#73 test_string.DATA[3] = 16#74 test_string.DATA[4] = 16#69 test_string.DATA[5] = 16#6e test_string.DATA[6] = 16#67 and so forth The string functions mentioned previously convert a DINT to a string. For example DToS(54321) converts the single DINT to a series of concatenated ASCII characters ("5" & "4" & "3" & "2" & "1") SToD reverses the operation, converting a string (array of characters) into a single equivalent DINT. Hope this helps you out. Perhaps someone in this group can expand upon this if you have additional questions.

Share this post


Link to post
Share on other sites
This is also discussed and solved in this thread at PLCTALK.net

Share this post


Link to post
Share on other sites
You are the MAN, Mr. Carlton!

Share this post


Link to post
Share on other sites
Not Quite Sure of your math my calculator finds errors, but this V19 Program for L64 {all I had to test with} works and comes close to what you describe. Hope it spawns an idea. HexAscii.ACD

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
Sign in to follow this  
Followers 0