ASCII String Advice

Hey all.

Firstly, I thank you for assistance in this matter. And the answer to your question is yes, this is an L35E version 20.13 controller.

I need to read these posts a little more carefully right now.. I appreciate any advice one can give me with this.

These are values coming from a vendor device. SINT is the type.

There was one other question regarding the string position.. The decimal will always be in the same place with the same number of digits on both sides.

Thankyou

I must correct this statement. I had two projects open when writing this and I accidentally put the wrong processor here. Its actually an L45 with V20.18.

Thanks
 
Your SINT array is holding the ASCII character codes for the characters 0 thru 9 and d.p.

d.p. is 2E (hex), or 46 decimal
0 - 9 are 30 to 39 (hex), or 48 to 58 decimal

The CONCAT function will only work with STRING data-types, not SINTs containing ASCII codes.
 
Firstly, what PLC are you using ? Answered

Secondly, is the string data always consistent, i.e. numbers of digits before and after the decimal point ? Answered

Your data...........The numbers

I[16] = '1' ASCII = 16#31, or 49 decimal
I[17] = '.' ASCII = 16#2E, or 46 decimal
I[18] = '1' ASCII = 16#31, or 49 decimal
I[19] = '9' ASCII = 16#39, or 57 decimal
I[20] = '5' ASCII = 16#35, or 53 decimal

to get this into a STRING tag

CPS I[16] StringTag.Data[0] 5
MOV 5 StringTag.LEN

Then use STOR to convert the ASCII representation to a REAL tag

STOR StringTag RealTag
 
OK,, This was IFMs solution. Viewing this as ASCII. Perhaps I should abandon this avenue altogether.

I'm not sure what to do at this point... I simply wish they could support what they have sold me. I know that I'm supposed to do some of the leg work here but.... it would be nice if they could provide me with a working solution, an example or anything to help me get this going... all I want is a process value.

I have another thread started on this topic before IFM had me change this to ASCII values. I see that somebody has offered me a solution to that avenue of possibility with BTD instructions. I did have Rockwell tech support on this for more than a couple hours last week and they were unable to make it work reliably. They kept getting negative results from the BTD instructions. I will revisit that thread.

Thankyou
 
Tried it, it works as expected.....

EDIT : attached a bigger picture of the code

2017-11-27_160508.jpg
 
Last edited:
THANK YOU MR.DABA.

That did work. Like a charm! The CPS instruction is doing the SINT to ASCII conversion for us?? SO the sensor PV goes out as a ASCII value in an 8 bit integer. The CPS makes the SINT a readable ASCII character again and does so for 5 SINT values. The STOR is self explanatory.

I have a lot to learn about the mixing and refining of the different data types. Its not something that I normally have to do.

Thank you again for the help... Iv been struggling with this one for some time now.

:geek:
 
That did work. Like a charm!

The CPS instruction is doing the SINT to ASCII conversion for us??

Not really, there's no "conversion" going on at all, CPS is just a fast data-copying instruction. The CPS is simply populating the STRING tag's .DATA elements with the ASCII characters received from the IFM. Five ASCII characters embedded in a SINT array is not a "STRING".

The STOR instruction has to have a STRING data-typed tag as its Source parameter, so we have to create it, by copying the ASCII characters into the STRING tag. Then we have to specify the length of the string, hence the MOV.

The real "conversion" is performed in the STOR instruction, which most likely works (internally) along the lines of the method I suggested in my first post on this thread
 
This works great for one number... How would you do this for multiple ASCII values you want to turn into real numbers. I'm kind of new to this whole ASCII thing.....


I would probably make the code into an AOI (Add-On Instruction), and call it for each number to be converted. Unfortunately, though, CPS will not allow a tag to be used as its .LEN parameter, so this would only work as an AOI if all the STRING lengths were the same.

Without any "elegance", I would just repeat the code above for each number, and this would allow me to create the STRING tag of any length.
 
Haven't done a lot of AB so this may not be relevant, but I'd put conditions before you convert to a real number (I[16]>= Hex 30 and <= Hex 39 etc). I had a torque reader in operation for several years on a Mitsubishi PLC and one day it bit the dust and outputted "Error" which in turn shut down the PLC when it tried to convert.
 
i would probably make the code into an aoi (add-on instruction), and call it for each number to be converted. Unfortunately, though, cps will not allow a tag to be used as its .len parameter, so this would only work as an aoi if all the string lengths were the same.

Without any "elegance", i would just repeat the code above for each number, and this would allow me to create the string tag of any length.

cps?
 
I'm getting some odd information from this example.....

RT.DATA[97] = 0
RT.DATA[98] = 0
RT.DATA[99] = 3
RT.DATA[100] = 0
RT.DATA[101] = 0

My StringTag is getting bogus information that does not match the data above????
 
I'm getting some odd information from this example.....

RT.DATA[97] = 0
RT.DATA[98] = 0
RT.DATA[99] = 3
RT.DATA[100] = 0
RT.DATA[101] = 0

My StringTag is getting bogus information that does not match the data above????


One has to assume you have created a STRING data-type that is capable of holding your STRING data. The predefined STRING data-type can only hold strings up to 82 characters.

In your example above, RT would need to hold a minimum of 102 characters, 0 to 101.


You are able to create STRING data-types of any (character) length up to 65,535 characters.

So that there is no confusion, I would recommend you call the data-types "STRINGxx", where xx is the maximum number of characters the data-type will allow.

RecipeName could then be a STRING tag of datatype "STRINGxx", having previously constructed the data-type to hold a maximum of xx characters, reflecting the maximum length of your recipe or product names or numbers.

Get the numbers right, it all works....
 


CPS does not get interrupted by a higher priority task, or even the System Overhead Time Slice (SOTS).

COP can be, so it can "split" the data-set. Imagine you are partway through a COP when the SOTS handles comms, and in that SOTS slot, an external device reads your data. It has potentially read rubbish....

CPS ensures your data-set is always complete.
 

Similar Topics

I have a Horner PLC that is reading Ascii string from a device. When the device responds, it responds with the hex value in Ascii. I need to...
Replies
8
Views
2,372
HI Guys So i am trying to write a real SINt or DINT value into a string tag. If in string browser I write it manually, no problem. But how can I...
Replies
8
Views
5,912
Have an unusual one here, guys... I have a remote machine that is sending my 1769-L33ER five 16-bit integers that represent 10 ASCII characters...
Replies
4
Views
2,205
Hello gentlemen, A few days ago I was tasked with converting an old panelview 1400e to a panelview plus 7 application. Everything went well except...
Replies
1
Views
1,303
hi, i try to capture barcode data using UDT with SINT ascii array. i have all the data i need but it in array format, how can i convert to 1...
Replies
5
Views
3,044
Back
Top Bottom