AB Real (F) to ASCII (ST) Conversion

grish05

Member
Join Date
Mar 2007
Location
Independence, MO
Posts
6
Has anyone had any experience or written any code to convert a real (F file) to an ASCII (ST file) for a AB SLC/Micro, in this case I am using a 1100. The F register will contain a 6 digit number with a 3 position decmial point (XXX.XXX).



Thanks

Jeff
 
This works in an emulated 5/04...can't be sure it will work in a ML1100 since I don't have one and can't emulate one...

SLC_Float_To_String.JPG


I get each half of the float into two integers, convert them to strings, and concatenate the strings together including one with a manually inserted period (ST9:2).
 
Last edited:
Thanks for the response,
I have some similar code but when I have a decimal less than .100 the conversion is off by a digit. For example when X.063 is entered (1/16” = .063), the conversion puts the decimal at .630 instead of .063.

Will your code convert over in this situation OK?

Thanks, Jeff
 
OkiePC's code will suffer from the same <0.1 issue you have. To the best of my knowledge there is no way to make the conversion pad with zeros. You need to insert the leading zeros on your own. How dificult that will be will depend on how many places after the decimal point you need to display.


Keith
 
Here's a slightly improved version...note that the float must be less than 32767 and that the output string is to 4 places past the decimal point, but that could be changed:

SLC_Float_To_StringR01_sh1.JPG


SLC_Float_To_StringR01_sh2.JPG
 
Good one, OkiePC. That will do it.

But we now see why we all hate to mess with string conversions in most plcs. They just weren't intended to do that very smoothly. This would be a one-line deal in C.

Keith
 
I ran across this same issue while working with one of AB's InView displays that I wanted to use to display some statistical data from a SLC 5/03. The InView doesn't support decimal variables, so I had to do something very similar for my floating point values. This was several years ago, so I hope they've rectified this by now.
 
Yeah, it would be "much improved" if it handled longer floats...

If the ML1100 supports long integers and the AIC instruction does too then it should be simple to make that little nugget of code even better...
 
Thanks, I did not know about the AEX command nor would I thought to use it in that way. I am looking forward to putting that in next week.

One thought for your first line of code, if you use a ABS - absolute value command and set the destination for your integer file you don't have to worry about the rounding up. Plus it is a little cleaner.

Thank you, Jeff
 
Here's my version...

It's a bit messy (I'd prefer to reorder the string file), but it works pretty well.

It does handle input up to 999999.999, after that you start to get roundoff in the float.

It also handles negative numbers.


A surprisingly ugly little problem, didn't expect it to be this difficult. I'd definitely like to hear from anyone that has a more elegant solution.

One last thing... What's up with the discussion around the ABS instruction? Looks to me like it rounds off just like a MOV.
 
mellis said:
Here's my version...

One last thing... What's up with the discussion around the ABS instruction? Looks to me like it rounds off just like a MOV.

ABS outputs the absolute value, say if the input is a negative value, it turns the output to positive. If the input is positive value, ABS just output it as it is.

____________
 

Similar Topics

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,942
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,841
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,595
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,481
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,871
Back
Top Bottom