Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

SINT to STRING to REAL

Status
Not open for further replies.

thebard3

Chemical
May 4, 2018
723
If anyone is up to a challenge, I have been working all day to figure out a good way to convert data retrieved from some legacy devices from ASCII format via SINT array to floating point. Putty returns the following;
putty_screenshot_bg7f4t.png

My communication module returns each individual character as a SINT data type in an array (SINT[4000]). I need to pick out the 5 digits of data, apply the appropriate sign and exponent to create the floating point number. I have a few ways to do that but none of them are very pretty, because each digit is a separate SINT register. ControlLogix version 30 is the platform I'm using. Any good ideas out there? I hate working with ASCII data to begin with, but when it's reall SINT data to begin with it's even worse.

Brad Waybright

It's all okay as long as it's okay.
 
Replies continue below

Recommended for you

Sorry about the small screenshot. It was late in the day and I had to go to an appointment.
putty_screenshot_utcoou.png

To clarify my situation, each character, including space, is returned as ASCII code in a single SINT in an array. The data shown here is actually 710 characters.
SO-- I have to capture each digit, rebuild it into an integer, apply the exponent and modify the sign if necessary. I can do this with ladder code but in all there are 110 data points I have to log so that's a lot of work for a PLC that has other jobs to do too. I find references to this problem in other places but they mostly explain how the ASCII/DINT conversion works which isn't applicable.

Brad Waybright

It's all okay as long as it's okay.
 
Is there anyway to change the format coming out of the asc2 device? better to work with a real than an exponent. Even if you could have a whole number where the decimal place is understood to be at a certain position.

Otherwise your building a look up table with exponents to put the decimal place at a certain position in the string that represents the number. Then convert the string to real or dint.

I remember there is a feature I thought where if you use real that some of the precision is lost in the conversion. This might be a past bug in there conversion blocks, only way to see if when you test the data.

Process
1st thing is how you bring the data in. Some methods are slow and some are faster, you choose.
1 character at a time​
or a large string in a holding register​
2nd is convert the string to whole or real numbers
3rd is how do you store it for easy retrieval maybe in an array to be used in some other process in PLC.




 
You might be better off using some type of programmable gateway. I believe the the AnyBus line has the ability to decode custom protocols.
 
My comm module returns data in a 4000 element array of SINT format. There are no options for that. Each character in the string is an ASCII code in a single SINT element. There are 709 SINT elements in the example shown above. If I try to copy SINT elements into a string data type, I get an excessively long STRING type length and cannot extract the wanted characters (I really only need the 5 value digits). If I search the PLC forums there are numerous instances of this question without any good answers. I think I'm going to have to convert each character one by one and do conversion math to make it work.

Brad Waybright

It's all okay as long as it's okay.
 
djs-
I am using ProSoft MVI56-GEC generic ASCII module.

Brad Waybright

It's all okay as long as it's okay.
 
I thought I had it, and was using the copy COP object to move array data into a STRING tag and then use the MID instruction to remove the desired characters. This has the unfortunate effect of making the string tag length LEN 168645424! Atomic STRING tags are limited to 82 characters so I don't know how that doesn't fault the processor or something, but the COP instruction isn't meant to work with STRING data type anyway.
I have created a way to generate the floating point tags from the SINT[4000] array, but it isn't really pretty. As with my past experiences, I'll just declare that ASCII sucks, at least to me.

Brad Waybright

It's all okay as long as it's okay.
 
COP instruction sometimes you have to put length in from the string.len or really look at data to see what you are coping in that variable if coping from one data type to another. Its not straight forward as you see. When you copy to one different variable its inconsistent on what it copies.

I agree ASC instructions have a lot to be desired.
I always thought servers or pc did a better job of bringing in asc data.

Asc data programming is convoluted especially now that a lot of interfaces have gone to string data messaging. Makes PLC programmers job harder.
 
> If I search the PLC forums there are numerous instances

Have you actually posed the question on PLCs.net?


Posting requires registration; it's instantaneous after replying to their email (no moderator review), as I recall.
 
Danw2- I did check those and found similar questions but no snswers so I thought I'd try this forum. No worries, it is up and running, I was just hoping I could find a better way.

Brad Waybright

It's all okay as long as it's okay.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor