5/03 ASCII to real number

dogbarx

Member
Join Date
Mar 2003
Posts
2
I am recieving an ascii string into ST14:0. I get the entire number, including the decimals. I can only find a way to convert it to an integer. I need to get the real number into F8:0

Rick
 
If you know where the decimal point is then you can use AEX instructions to separate the integer and fractional parts into separate strings.

Convert the string to integers using AIC instructions.

Divide the fractional part integer by the proper factor of 10 and store that in a float.

Add the integer part to the float.

If you don't know where the decimal point is then you first have to search the string with the ASC instruction to find it.

String manipulation in a SLC is possible but a real PITA!!.

nOrM
 
deja vu all over again ...

take a look at this:

recent thread on the same subject

if I understand your problem correctly, then the approach used in the PARSE program should take care of just about everything you'll need ... I'd skip over the FORMAT program ... the PARSE code is a lot more flexible ...

let me know if you need more details or if you have any questions about the code ...
 
and for the SLC-5/03 ...

and just in case all you have available is RSLogix500, here is a version of PARSE.RSS which you should be able to open ... basically the program follows the same ideas that Norm mentioned ... look for a space so that you'll know that you've found the end of a parameter ... extract that parameter from the string ... look for a decimal point in the parameter ... if there's a decimal point then break the parameter up into a "whole number" part and a "fractional part" ... turn those parts into integers ... handle any negative number issues ... turn the integers into floating point (real) numbers ... add the parts ... continue on ...

I put in what I THINK is enough documentation ... the rung comments should be all you'll need ... let me know if you need more ...

finally ... I'm doing this RSLogix5 to RSLogix500 conversion under the gun ... I haven't really run this on an SLC but the PLC-5 version works fine ...
 
There are a few questions that you'll have to answer before we can proceed.

1) Is the number an ASCII fp number (ie. 123.345) or is the number
part of a string comming in the serial port?

2) Is the number always in the same location in the string?

3) Is the number preceeded by an identifying character?

4) If the number is in ASCII format is it's format consistant? (eg. do small numbers appear as 1.2E-10 and "normal" numbers appear as 2.345)

If the number is a string then you'll have to convert it by looping through the characters in the string. If you have an easy way of locating the 1st character of the string (see questions 2 and 3 above) then you'll have to locate the 1st character and convert.

What I usually do in the above situation is find the 1st character of the string and then use the copy instruction to copy the data to an integer file. You can then easily step through the file with standard instructions.

The important thing is to let us know the string format, then I can be a little more specific.

Good Luck,

(8{)} ( .)
 

Similar Topics

Hello all, We need to convert ASCII data into Real Raw data, here we use Trimble GPS and need to get the position data. We use SCADAPack 357...
Replies
4
Views
2,814
I have a SINT[500] array that is pulling data from a scale. The maximum number of characters that can be sent by the scale is 6, and there are two...
Replies
7
Views
1,594
Dear Experts. I have a CPU 315-2dp Siemens PLC which is communication between mistubishi fX-3U Series mistubishi is giving me AScii String data...
Replies
2
Views
5,937
Hi guys I have a big work cell that has 2 turntables and 4 fixtures, we have the Alpha signs(like you see in the restaurants the scrolling ones)...
Replies
8
Views
6,477
Hello, can you tell me please how i can convert REAL to ASCII? with an example if it is possible. Thank you
Replies
25
Views
8,865
Back
Top Bottom