Experts! Help Me Convert decimal to ASCII string!!

wlemst88

Member
Join Date
Apr 2003
Posts
39
Hey guys, I've had some really good experiences here in the past, so I thought I'd present you with a little problem I've been having trouble solving myself.

Hardware: Allen-Bradley PLC 5/40 and Panelview 600

In concept its actually quite simple. I have a word, N42:54 that has a decimal value in it. The panelview views this word as a character array of size two and it shows up as a ASCII value. EX: N42:54 has the value "17224" which when converted to ASCII is "CH"

What I need is to somehow convert this word to ASCII and store it into a string, Call it ST15:7. I need this because I am trying to pull this value out of the datatable with OPC/DDE through MS Excel, and it pulls the value out as a decimal value instead of the ASCII. I have tried all I know, and I can't seem to get it to work.

Examples of what I have tried:
I used a TOD (to BCD) to convert N42:54 to BCD, then an AIC(Integer to ASCII string) to convert the value to a string. The BCD part worked, but the AIC just moved the result of the TOD into the string address.

I tried variations of the above, tried taking out the TOD, etc.

I am at a loss guys. Any ideas? Is it even possible?

Wes Lemstra
 
Wes-
Unfortunately I don't have a PLC5 here to try this on. But what you are doing with the AIC instruction should work if you don't use the TOD.
When you look in ST15:7 after you run the AIC, do you see 'CH' or do you see '17224'? If ST15:7 displays '17224' it is converted correctly.
One way you can look at the result is to use a copy (COP) and copy the contents of ST15:7 into an integer file. Something like
COP (#ST15:7 #N7:0 10).
This will copy the first ten words of ST15:7, which should contain your length as well as your data. View N7 in BCD format and you will see the actual ASCII codes. But note that the length is the first field in the string.
Also, before every conversion, clear the contents of ST15:7. I think you can use the CLR instruction to do this. If you don't you could end up with shrapnal at the end of your new string if the new converted string is shorter than the old string.

I hope this helps.
Keith
 
Yeah, when I do the AIC, I get the value of whatever is in N42:54 placed in the ST15:7.

I don't want it to display "17224" in ST15:7, I want it to display the "CH" because when I grab something from the Datatable from Excel, it just copies the value. IE 17224 instead of CH.

Or am I wrong?

Wes
 
Hi Wes-
I'm weak on the OPC/DDE thing so I may be off base here.
So you run the AIC and get 17224 in ST15:7. You read ST15:7 through your OPC/DDE link and it comes in as 17224. Correct so far?
What you need to do is get the value 17224 correctly loaded into ST15:7.
Now, I'm making some assumptions here that will need to be checked but here goes. You should be able to create an integer data file that is 50 words long. In word 0, enter '2', which should be your string length. Move 17224 from wherever you got it into word 1 in the integer file. All other words will be zero.
Copy the integer contents into the string (COP (#N7:0 #ST15:7 1)) and you should get what you need.
I don't know much about Excel but I would have to guess that you could convert the raw number into ASCII in Excel. You might want to try that approach.

Keith
 
Well, I got it to work without the AIC. I don't know why it didn't work before. Basically, I have 9 words of data in decimal that I wanted concatonated into one string 18 elements long. So I found a spare 10 consecutive words in my integer file N42 at n42:90 - n42:100. In n42:90 I put 18, the number of elements I needed. I then copied my 9 data words into n42:91 - n42:100. I then wrote a second copy command copying n42:90 to st15:7 with length 1. That seemed to work.

Thanks alot for your help. If you have any questions or anything, let me knwo.

Wes Lemstra
 
Man, I'm banging my head against the wall. Like I said, I got it to work perfectly in my test setup. When I try to make the IDENTICAL edits to the machine out on the floor, I get an error "Unable to create data table". I don't understand it. It doesn't need to create a datatable, it already exists. Let me show you a few screen shots.

st_datatable.jpg
 
Back in the good old days with the classic PLC5 (5/15, 5/25, etc.) a copy would cross file boundries to get the number of words it needed to complete a copy. For example, assume I have a data file N20:0 - N20:9 and a data file N21:0 - N21:9. I also have a data file F30:0 - F30:9. I then enter the instruction:
COP (#N20:0, #F30:0, 10)
When you specify a number of elements in a copy you are specifying destination elements. A floating point element takes up two words. So to copy the 10 floating point elements I need to copy 20 integer elements. A classic PLC5 would copy everything from N20 and then move on and copy everything from N21. The new platform processors (5/20, 5/40, 5/60) will require that the source file be big enough to supply all the data.
A string data type is 41 words long, 1 length/position word and 40 character words (80 characters). The element size is fixed whether you use the characters or not. So your second copy is trying to copy 41 words from a file that doesn't have 40 words to give (I'm guessing). The programming software wants to create the extra elements but a PLC5 won't let you create data table elements online. So you're stuck.
Your only recourse as far as I know is to upload the program, increase the data table size offline then download the program.

Hope this helps.
Keith
 
Last edited:
Keith,

Well, thankfully I did have an integer file with 41 consecutive unsued words, so I didn't need to do an upload. (What a pain in the a$$ that would have been). Worked like a charm. I had no idea about the 41 words thing, didn't see anything like that in the help files.

You get a beer! 🍺

Thanks again,
Wes
 
I learned all about that one from another guy at my previous employer. The machine was originally designed with the classic PLC5 and they INTENTIONALLY copied across a file boundary taking advantage of the copy 'feature'. When they switched to the new platform PLC5 they had to do some massaging to make that work. That's what you get for trying to be clever.
By the way, if you ever use ControlLogix processors, the copy can be a bit dangerous in there, too. There is no data file structure in the CLX processor. If you copy a small array to a large array, for example, the CLX processor will keep on taking data from memory locations after the small array is done until the large array is full. The problem is you have no idea what is behind the small array so you may get a pile of junk in your large array.

Keith
 
For a complete Ladder logic example of ASCII to Integer and Integer to ASCII conversion go to www.tomantron.com (downloads)
You can download a fully commented example and use it in your program
 
Creating data table space

kamenges said:
Your only recourse as far as I know is to upload the program, increase the data table size offline then download the program.

Keith

Just for the record, in the PLC-5's, you need 'only' go to program mode to create files/data table space. Uploading and then downloading is not required.
 
Yeah, but the problem with any of those modes is you need to take it out of Run Mode, something you can't do if the machine needs to keep running.
 
wlemst88 said:
Yeah, but the problem with any of those modes is you need to take it out of Run Mode, something you can't do if the machine needs to keep running.

I know that. Since I'm also familiar with the PLC-3, boy, do I know that!

I was merely pointing out that it's not necessary to go completely off line to create memory.
 
I have to do the same but with excel

I've found this post in looking for answers to the same exact problem. I want to "suck" the string values out of a decimal value which my dde/opc link in excel has generated from a SLC5/04.

Same as Wlemstr88 - I've got N20:101 - N20:104 - Each "word"? contains two characters. These characters represent a product description. My DDE/OPC link in excel also return a decimal value. Since my unfaithful employer has absolutely forbidden me to change the logic in any way - I HAVE TO make the conversion within Excel. Now there has got to be some type of add-in or formula to use. Anyone have any info here?????
 

Similar Topics

I have two different GE PLC's - a Versa Max and a 90-30 - at the same customer's site, that when power is lost or cycled off then on, the PLC's do...
Replies
4
Views
1,801
Hi, When i try to backup my existing proface touch screen, it will show error " no upload data in GP " . what is the cause ? how to solve ? Pls...
Replies
6
Views
2,612
I am a complete newbie with Omron plc’s. I have the software and leads (bought for another project but never used) but last week I was dragged...
Replies
1
Views
2,229
Dear Experts, I have five Display (PM4BC) which return ASCII string on their RS485 port (two wire), each Display can be marked up with address. I...
Replies
0
Views
2,719
I have a PLC-5 running system with one local and 3 remote chassis. There are few digital Input(1771-ICD) and Digital output(1771-OW16) modules in...
Replies
3
Views
5,475
Back
Top Bottom