S7 pointer to an array question

SCL fault log

Hi there
Same thing written in SCL, including creation of DB !
Code:
DATA_BLOCK DB23

//to log time of occuranc of fault.  

    STRUCT
fault_code: ARRAY[1..50] OF int;
iDate: ARRAY[1..50] OF DATE;
iTime: ARRAY[1..50] OF TOD;
    END_STRUCT
BEGIN

END_DATA_BLOCK

FUNCTION FC23 : void

VAR_input
fault_code:INT;
fault_trigger:BOOL;
END_VAR

var_in_out
x1:BOOL;
index: INT;  
END_VAR

VAR_TEMP
    x2:INT;
    x3:INT;
    
END_VAR

BEGIN


WHILE fault_trigger = 1 AND x1=0 DO
    
    x1:=1;
    x2:=100+index;   
    x3:=200+(index*2);
 
    db23.dbw[index]:=INT_TO_WORD(fault_code);
    db23.dbw[x2]:=DINT_TO_WORD((DATE_TO_DINT(mw200)));
    db23.dbd[x3]:=DINT_TO_dWORD((tod_TO_DINT(md202)));

 //increment the index at positive pulse of fault_trigger    
    index:=index+2;
       
       
END_WHILE;
    
 
 IF x1=1 AND fault_trigger=0 THEN
    x1:=0;
 END_IF;

IF INDEX >= 100 THEN
   INDEX:=0;
END_IF;

END_FUNCTION

Same thing attached also.
 
Sorry for the late reply. Been busy with another project.

Thanks everyone for the help, especially manmeet & L D[AR2,P#0.0] for the sample code.

The reason I have not used SCL is because I don't have a license. It would of been a 5 minute job if I could use structured text.
We had one SCL license floating around between a few engineers and somehow it got lost (don't ask me how).

Why SCL is a separate license is mystery to me.

Maybe 'Real' Siemens PLC Programmers only use STL and see no point to SCL since it just gets compiled into STL anyway.
Reminds me of the stereotypical Real Programmer in 'the story of Mel' - check it out some time all you wannabe programmers.

Alas, I could not wait and just gave up on the whole idea of UDT, arrays and pointers.
I just defined 10 sets of variables (FaultDate_0, FaultDate_1 ...) and programmed it 'statically' (don't know if that is the right term?).
 

Similar Topics

Not sure if this is possible but thought I would put it out there. Using Rockwell Studio 5000, is it possible to shift the address of an array...
Replies
7
Views
2,147
Hello, I'm still fresh in plc programming so I have still many questions to answer. I searched forum/web for similar topic but i didn't anything...
Replies
1
Views
2,680
Must modify / expand a program which is made with a many block move (SFC20) as shown in the attached image. It moves data between array of...
Replies
13
Views
14,005
Hi! I modified some code, probably from member LD, to make a function element := ReadFromArray(firstElement : ANY, offset : INT) It seems...
Replies
2
Views
4,159
Hi all....... someone knows if is possible in S7, using the indirect adressing by means of a pointer L P## to read a data struct defined as...
Replies
5
Views
3,737
Back
Top Bottom