HELP with SCL code..

mad@imap

Member
Join Date
Apr 2008
Location
Columbus, Ohio
Posts
25
Hello All,
I have a little code in an FB that I'm trying to figure out the only problem is I don't know SCL. can someone help me and tell me what this means. and is there a book I could get that would help me understand SCL?
Here is the code.
SET

SAVE

= L 10.1

L #i_TESTED_D

T #t_DWORD1_D

L #i_TESTER_FLAGS_D

T #t_DWORD2_D

= #o_TRUE_B

L 0

T #t_SCRATCH_I

A7d0: L #t_SCRATCH_I

L 31

<=I

JCN A7d1

A #o_TRUE_B

NOT

JCN A7d2

JU A7d1

JU A7d4

A7d2: L #t_SCRATCH_I

ITD

L L#0

+D

L L#1

*D

LAR1

CLR

A L [AR1,P#4.0]

L #t_SCRATCH_I

ITD

L L#0

+D

L L#1

*D

LAR1

= L 10.2

A L [AR1,P#0.0]

NOT

A L 10.2

JCN A7d4

CLR

= #o_TRUE_B

A7d4: L #t_SCRATCH_I

L 1

+I

T #t_SCRATCH_I

JU A7d0

A7d1: CLR

A L 10.1

SAVE

BE


The name of the block is D word test if that helps. there are also 5 pins on the block EN, ENO, I_TESTED_D, I_TESTER_FLAGS_D, AND O_TRUE_B.

THANKS FOR THE HELP
MAD@IMAP
 
The code is in STL, not SCL. Not sure if it is made with SCL as the source.
The constant 31 seems to indicate that it has something to do with ASCII characters. ASCII characters from 0 to 31 are control codes, from 32 and up are the letters, numbers, etc.

edit: It cannot be generated from SCL. There are two unconditional jumps after each other in the middle of the code. The SCL compiler would never do that. It looks more like the original programmer didnt care to tidy up (I would NEVER forget to tidy up my own code *cough*).
 
Last edited:
I'd say this was originally generated by the SCL compiler (but then maybe edited using the STL editor)
The 31 is being in a loop to scan through the 32 bits of the double words passed in after they have been transferred to the temp area.
Here's the pseudo code:

o_TRUE_B=1;
For i=0 to 31 Do
if I_TESTER_FLAGS_D AND (NOT I_TESTED_D) then o_TRUE_B=0;
END_FOR

(where x means bit i of x)
 
Here's some SCL that compiles to the almost the same logic as the original post. I had to use GOTO's to get the compiler to produce two JU's after each other.

Code:
FUNCTION FC111: void
VAR_INPUT
i_TESTED_D:DWORD;
i_TESTER_FLAGS_D:DWORD;	
END_VAR
 
VAR_OUTPUT
	o_TRUE_B:BOOL;
END_VAR
 
VAR_TEMP
	T_DWORD1_D:DWORD;
	T_DWORD2_D:DWORD;
t_SCRATCH_I:INT;
dw1Array AT t_DWORD1_D:struct
dwa: ARRAY[0..31] OF BOOL;
END_STRUCT;
 
dw2Array AT t_DWORD2_D:struct
dwb: ARRAY[0..31] OF BOOL;
END_STRUCT;
 
END_VAR
 
LABEL
	Di,F,G;
END_LABEL;
 
t_DWORD1_D:=I_TESTED_D;
t_DWORD2_D:=I_TESTER_FLAGS_D;
o_TRUE_B:=True;
t_SCRATCH_I:=0;
Di:IF t_SCRATCH_I <= 31 THEN GOTO F; END_IF;
GOTO G;	
F: IF dw2Array.dwb[t_SCRATCH_I]=1 AND NOT dw1array.dwa[t_SCRATCH_I] THEN O_TRUE_B:=False; END_IF;
t_SCRATCH_I:=t_SCRATCH_I + 1;
GOTO Di;
G:;
END_FUNCTION

and here's the compiled STL:

Code:
	 SET 
	 SAVE 
	 =	 L	 10.1
	 L	 #i_TESTED_D
	 T	 #T_DWORD1_D
	 L	 #i_TESTER_FLAGS_D
	 T	 #T_DWORD2_D
	 =	 #o_TRUE_B
	 L	 0
	 T	 #t_SCRATCH_I
A002: L	 #t_SCRATCH_I
	 L	 31
	 <=I 
	 JCN A7d0
	 JU	A001
A7d0: JU	A000
A001: L	 #t_SCRATCH_I
	 ITD 
	 L	 L#0
	 +D	
	 L	 L#1
	 *D	
	 L	 L#0
	 +D	
	 LAR1 
	 CLR 
	 A	 L [AR1,P#4.0]
	 L	 #t_SCRATCH_I
	 ITD 
	 L	 L#0
	 +D	
	 L	 L#1
	 *D	
	 L	 L#0
	 +D	
	 LAR1 
	 =	 L	 10.2
	 A	 L [AR1,P#0.0]
	 NOT 
	 A	 L	 10.2
	 JCN A7d1
	 CLR 
	 =	 #o_TRUE_B
A7d1: L	 #t_SCRATCH_I
	 L	 1
	 +I	
	 T	 #t_SCRATCH_I
	 JU	A002
A000: CLR 
	 A	 L	 10.1
	 SAVE 
	 BE
 
Such thoroughness !

But about the double JU's, then in your code the difference is that there is a jump label before the second JU. In the original code there is no way that the second JU can be executed.
 
True. I've just coded two goto's after each other and then you get the situation you describe in the compiled code.

Code:
GOTO Di;
GOTO Di;
 
ok guys. I'm glad you understand it.. Now help me..lol
What does it do?
What I think it does. it is looking at a double word. they are photo eyes inputs. what I'm trying to do is but in my d-word (PE-stat) then only pull out one inout (pe-eye. To triger a counter..
what valu should I put where.
 
Can we assume you do not have the SCL source code for this ? If so, then dump it and write something new that you understand for your process.
 

Similar Topics

Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
318
Hi! I am working on a project were we will be replacing an 300 CPU with a 1500 CPU and we are working on migrating / converting code. There is a...
Replies
9
Views
1,076
Hi, Can someone translate this for me please, or at least help to explain what the instructions mean? SET SAVE =...
Replies
17
Views
4,622
Hi guys Its been some time since I worked with SCL and have a few lines of code I need some help with, I have the SCL raw code and am currently...
Replies
1
Views
1,508
Working with a SCL instruction and need a little help. The logic is a Heat / Cool circuit controlled by a PID. The PID Zone_4.CVEU tag is coming...
Replies
3
Views
3,164
Back
Top Bottom