Siemens Step 7 Convert

RheinhardtP

Lifetime Supporting Member + Moderator
Join Date
Oct 2004
Location
Perth
Posts
562
Hi All,

I'm currently busy on a project where i must take a number of char type objects and convert them to a decimal number for comparison reasons.

i tried the standarD Step 7 STRNG to INT conversion with no good values.

I understand the string concept like following.

Variable type STRING[5]

STRING[ABCDE]

byte 0 Max No of Char
byte 1 Actual amount in String
byte 2 A
byte 3 B
byte 4 C
byte 5 D
byte 6 E

Is there any tip or trick to getting this conversion going

I would really appreciate any help.

If there are any requests i'll post my code on this topic.

Kind Regards

Rheinhardt
 
Last edited:
Hi Rheinhardt

What values do you have in Bytes 0 and 1? You may have to load these with something between 1 and 6 (or in your case 1 and 5) to ensure the STRING variable is correctly recognised. For example if these bytes contain 0 then no conversion will take place.

Are you sure the STRING value can be represented as an INTEGER? Is it within the bounds for an INTEGER data type?

Regards

Ken
 
I haven't used FC38 before, but here's the code I ran and checked in the simulator. In the first example I used a string variable in temp local data and fill the string in using the program, the second example uses a string defined in a DB. Note that the DB has to be in the symbol table.

Code:
	 LAR1 P##sValue				 //string data type in temp area
	 L	 5
	 T	 B [AR1,P#0.0]
	 L	 4
	 T	 B [AR1,P#1.0]
	 L	 '1'
	 T	 B [AR1,P#2.0]
	 L	 '2'
	 T	 B [AR1,P#3.0]
	 L	 '3'
	 T	 B [AR1,P#4.0]
	 L	 '4'
	 T	 B [AR1,P#5.0]
	 CALL FC	38
	 S	 :=#sValue
	 RET_VAL:=#iValue
 
	 CALL FC	38					//string declared in a DB
	 S	 :="dbStrings".String1
	 RET_VAL:=#iValue
 
Structure

Dear Ken,Simon

Thanks for your replies.
Ken,
I load the values into my 1st and second byte . Since my string is defined in a data block as value == string[5] it loads the first byte automatically. I have loaded the value 5 into my second byte, but even with a value of '00000' i get INT 20000.

My STRING VALUE is defined as follow.

VALUE String[5]

byte 1 2 3 4 5 6 7
16#05 16#05 '1' '9' '4' '6' '3'

My return out of FC38 os then 20000. strange I will try your tips when i get to the office and post my code.

Simon you never said your result in the similator was it sucesfull??

Thanks again

Rheinhardt
 
Last edited:

Similar Topics

Good Morning, Hoping someone with some Siemens experience can give me a hand with this one. Customer has a S7-200 cpu, which has a 6GK7...
Replies
0
Views
249
I'm just trying to figure out the right method of adding a DO card to an existing rack. It's not the *next* open slot, but I have to move the AO...
Replies
5
Views
547
Hi Siemens Experts, I am hoping someone can shed some light on my issue. I have uploaded the code from a S7-300 (317-2PN/DP) using Step 7...
Replies
9
Views
676
Hello, We monitor the temperature of a pipe via a 4-20mA temperature transducer. This goes into DB135(Read Analog Inputs). The issue I have is the...
Replies
0
Views
626
Please excuse the basic question, but I've never worked on Step 7 before (until now, only dealt with Mitsubishi Q-series PLCs)... What is the...
Replies
16
Views
3,334
Back
Top Bottom