Array and SCL in Step 7

BNA

Member
Join Date
Sep 2003
Location
Give
Posts
117
I have made a small FB in SCL, in this blok i have to transfer to an array in a certan position, but I can't get it to work.

It goes as follows.

Code:
    IF Step = 3 AND Timer_2_Q THEN
     Register1.Linie_1[0] := Afviser_Nr;
    ELSIF Step = 3 AND Timer_2_Q = False THEN
    Register1.Linie_1[0] := 0;
    END_IF;

I would like to make "Register1.Linie_1[0]" an output on my FB so that I can write the array adress on the output instead of inside my SCL code.

Regards
Brian
 
I'm not sure that I understand your question. Do you want to have your array "Register1.Linie_1[x]" external to the block? If this is the cast then you need to pass the array as a variable. The example below passes an array or Real to the function as an IN parameter.

Code:
FUNCTION fcTIR_Map : real

// Block Parameters
VAR_INPUT
    // Input Parameters
    TIR_Data : ARRAY [0..36] OF REAL;   // TIR Map
    rAngle : REAL; // Angular Position 0-359.999 degrees
    
END_VAR

VAR_TEMP
    // Temporary Variables
    rTemp: REAL;
    rTemp1: REAL;
    rAngle_Lim : REAL;
    iTemp : INT;
    dTemp : DINT;
    diIndex  : DINT;
    rVal1 : REAL;
    rVal2 : REAL;
END_VAR

    // Limit Check the Input Angle
    rAngle_Lim := fcRealClamp(rMax := 359.99 // IN: REAL
            ,rIn :=rAngle  // IN: REAL
            ,rMin := 0.0 // IN: REAL
            ); // REAL
    rTemp:= rAngle_Lim/10.0;
    diIndex:= trunc(rtemp);
    rval1:= TIR_data[diIndex];
    rval2:= tir_data[diIndex +1];
    
    rTemp1:= rangle_lim -(DINT_TO_REAL(diIndex)*10.0);
    rtemp:= rval1 + ((rval2 - rval1) * rTemp1 /10.0);

     ;
    fcTIR_Map := rTemp;
END_FUNCTION

Nick
 
I'm not sure that I understand your question. Do you want to have your array "Register1.Linie_1[x]" external to the block?
Nick

That is exactly what i mean, it works as an ouput, but when I try the same on the input side I cant compile.

Here I have to set "Register1.Linie_1" as an input, I added the variable as an input variable of type INT and as ARRAY, but I keep getting errors.

Code:
IF Register1.Linie_1[Afviser_Pos] = Afviser_nr AND Auto = True THEN
   Step := 4;
   END_IF;

Thanks
 
Last edited:
I would like to make "Register1.Linie_1[0]" an output on my FB so that I can write the array adress on the output instead of inside my SCL code.


That is exactly what i mean, it works as an ouput, but when I try the same on the input side I cant compile.
?

Copy a cut down version of the code to a library and post as an attachment including the SCL that does compile, and the SCL that does not compile.
 
Last edited:
?

Copy a cut down version of the code to a library and post as an attachment including the SCL that does compile, and the SCL that does not compile.

This compiles
Code:
VAR_OUTPUT
    // Output Variables
    Start_Linie : BOOL;     // Signal til start af bånd
    Linie_Klar : BOOL;
    Afviser : BOOL;
    Start_lift : BOOL;
    Timer1_Q : BOOL;
    Timer1_ET : TIME;
    Timer1_SP : TIME;
    Aktuel_Step : INT;
    Register : INT;
END_VAR
 
// Statement Section
    IF Step = 3 AND Timer_2_Q THEN
    Register := Afviser_Nr;
    ELSIF Step = 3 AND Timer_2_Q = False THEN
    Register := 0;
    END_IF;

This dosen't work

Code:
VAR_INPUT
    // Input Variables
    Emg_Stop : BOOL;        // Nødstop
    Auto : BOOL;            // Auto signal
    Linie_Foto : BOOL;      // Første fotocelle på linien
    Afviser_Foto : BOOL;    // Fotocell før afviser
    Afviser_Inde : BOOL;    // Signal for Afviser inde
    Lift_Startet : BOOL;    // Lift kører
    Bit_0 : BOOL;           // 
    Bit_1 : BOOL;
    Bit_2 : BOOL;
    Afviser_Nr : INT;
    Afviser_Pos : INT;
    Skifte_Register : INT;
    Delay_Linie_Klar : TIME;
 END_VAR
 
// Statement Section
3 :
   IF Skifte_Register[Afviser_Pos] = Afviser_nr AND Auto = True THEN
   Step := 4;
   END_IF;

Brian
 
In the code that does not compile, Skifte_Register is defined as an INT but you are using it as an array.
 
In the code that does not compile, Skifte_Register is defined as an INT but you are using it as an array.


The problem is that if I make the input "Skifte_Register" as an array, the array is put i the instance for this FB, and I need to point to an Array in another DB.

/Brian
 

Similar Topics

Help!! From reading previous threads, I know that the best way to index an array is using SCL. I have the SCL editor, I'm just not sure where to...
Replies
3
Views
4,249
Hello I wanna know if are some function to check what is the max value from an array or if I have to loop the array to compare all numbers to get...
Replies
4
Views
1,896
Hello, When you want compare values of an array to a range of numbers is it a right way to do that? FUNCTION ADD VAR_IN_OUT A:ARRAY[1..50]...
Replies
5
Views
2,073
Hi guys. I have a challenge that I'm struggling with and I can't help thinking there's a really easy solution. I want to move a series of...
Replies
18
Views
5,855
Hi, I just can't wrap my head around this one so all ideas and comments are more than welcome. My SCL programming skills are beginner level. What...
Replies
3
Views
1,941
Back
Top Bottom