ASCII Conversion in Siemens

ieseng

Member
Join Date
Aug 2002
Location
Ireland
Posts
51
I have a Siemens CPU313C-2DP used in conjunction with card CP340 and I need to convert the ASCII word from the CP340 to an integer.

What is the best and simplest method?
 
A novice like me would suggest creating a DB and putting all ascii values and their relative numbers. Then try to lookup in the table for any Value ...
 
Hello ieseng;

Look in the program library (in the STL/LAD/LOG editor) and open the IEC functions folder. You will find a few string manipulation blocks, such as:

IEC_string.jpg


FC38 (or FC38 or FC39, depending on the data type you require to produce) should help you out.
Hope this helps,
Daniel Chartier
 
I'm going out on a limb and will assume that by ascii word you mean a two digit number, is that right? If so, you can use a standard function from the library, or you can make your own. All you would have to do is subtract 48 from each digit, and multiply the result by the correct power of ten. Give us more info, and we'll help you out.
 
Hi,
in our case we have a 5 digit word. The word is in data character format coming in from an Idesco identification sensor (IWH Reader).
The first character is a letter. So what is the best way to convert to an integer?
Any recomendations welcome?

Thanks for your help again.
 
The first character is a letter. So what is the best way to convert to an integer?



Not sure what you mean by that. On the assumption that you mean the first character is number rather than a sign, then FC37 - STRNG_DI sounds like your answer. You'll need to store the string in a DB first, because the Input parameter to FC37 must be declared symbolically. For FC37 the string can be a maximum of 11 characters long, (i.e. 10 digits plus sign, which the maximum you can hold in a DINT) so there is no problem with your five character string.

If you're certain that the number will never be greater than 65535, then you can use FC38 STRNG_I instead, there the maximum string length is six characters.

I can't really see that there should be any problem with this, but if you have any problems, then we'll need a few more details to sort them out.
 
ieseng,
If I understand you well, you receive from the sensor 5 ASCII characters and the first character is a letter. So to convert it you need to remove this letter first. You can do that with FC32 RIGHT (from Standard Library/IEC) then use FC38 on the result - as described by RMA (I assume there are always 4 digits to be converted).
BTW, you can define string variable in the TEMP part of FB/FC interface (however you must initialize it by yourself prior to use - see online help on STRING Data Type in Step7).
 

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,939
Im trying to use a MSG instruction to get the serial numbers of all addon cards and display the serials on a HMI interface. I have the logic done...
Replies
2
Views
552
I know there's the DTOS Function, but I have a value of "35" that is really "0035", and that's how I want it converted. Looks like the function...
Replies
2
Views
1,521
Hi All, have a quick one new enough to this type of programming, I am using a Allen Bradley point IO with 1734-232ASC card to send out data, I...
Replies
5
Views
2,592
Hi there everyone! Long time lurker, first time poster. I am doing an SLC-5/03 to CompactLogix migration and am having an issue with a barcode...
Replies
1
Views
1,051
Back
Top Bottom