Move DWORD S7 in SCL

cjd1965

Lifetime Supporting Member
Join Date
Apr 2007
Location
UK
Posts
1,659
Hi
I am trying to move a DWord but it doesnt seen to work.

I have created an FC in SCL


Code:
FUNCTION FC2 : VOID
VAR_INPUT
iStep : INT ; //Step Number
END_VAR
VAR_OUTPUT
wOUTPUT : DWORD ; // Sequence Output Word
END_VAR
 
 
    CASE iStep OF
  0:  wOUTPUT := "TEST".OUTPUTS.STEP_00;
  1:  wOUTPUT := "TEST".OUTPUTS.STEP_01;
  2:  wOUTPUT := "TEST".OUTPUTS.STEP_02;
  3:  wOUTPUT := "TEST".OUTPUTS.STEP_03;
  4:  wOUTPUT := "TEST".OUTPUTS.STEP_04;
  5:  wOUTPUT := "TEST".OUTPUTS.STEP_05;
  6:  wOUTPUT := "TEST".OUTPUTS.STEP_06;
  7:  wOUTPUT := "TEST".OUTPUTS.STEP_07;
  8:  wOUTPUT := "TEST".OUTPUTS.STEP_08;
  9:  wOUTPUT := "TEST".OUTPUTS.STEP_09;
  10:  wOUTPUT := "TEST".OUTPUTS.STEP_10;
  11:  wOUTPUT := "TEST".OUTPUTS.STEP_11;
  12:  wOUTPUT := "TEST".OUTPUTS.STEP_12;
  13:  wOUTPUT := "TEST".OUTPUTS.STEP_13 ;
  14:  wOUTPUT := "TEST".OUTPUTS.STEP_14;
  15:  wOUTPUT := "TEST".OUTPUTS.STEP_15;
 
 
 
    END_CASE    
 
 
    ;
 
END_FUNCTION
DATA_BLOCK DB200
    STRUCT
MASK : STRUCT  
   STEP_00 : DWORD ;    
   STEP_01 : DWORD ;    
   STEP_02 : DWORD ;    
   STEP_03 : DWORD ;    
   STEP_04 : DWORD ;
   STEP_05 : DWORD ;
   STEP_06 : DWORD ;
   STEP_07 : DWORD ;
   STEP_08 : DWORD ;
   STEP_09 : DWORD ;
   STEP_10 : DWORD ;
   STEP_11 : DWORD ;
   STEP_12 : DWORD ;
   STEP_13 : DWORD ;
   STEP_14 : DWORD ;
   STEP_15 : DWORD ;
    END_STRUCT ;
COMPARE : STRUCT  
   STEP_00 : DWORD ;    
   STEP_01 : DWORD ;    
   STEP_02 : DWORD ;    
   STEP_03 : DWORD ;    
   STEP_04 : DWORD ;
   STEP_05 : DWORD ;
   STEP_06 : DWORD ;
   STEP_07 : DWORD ;
   STEP_08 : DWORD ;
   STEP_09 : DWORD ;
   STEP_10 : DWORD ;
   STEP_11 : DWORD ;
   STEP_12 : DWORD ;
   STEP_13 : DWORD ;
   STEP_14 : DWORD ;
   STEP_15 : DWORD ;
    END_STRUCT ;
OUTPUTS : STRUCT  
   STEP_00 : DWORD ;    
   STEP_01 : DWORD ;    
   STEP_02 : DWORD ;    
   STEP_03 : DWORD ;    
   STEP_04 : DWORD ;
   STEP_05 : DWORD ;
   STEP_06 : DWORD ;
   STEP_07 : DWORD ;
   STEP_08 : DWORD ;
   STEP_09 : DWORD ;
   STEP_10 : DWORD ;
   STEP_11 : DWORD ;
   STEP_12 : DWORD ;
   STEP_13 : DWORD ;
   STEP_14 : DWORD ;
   STEP_15 : DWORD ;
    END_STRUCT ;
 
    END_STRUCT ;
BEGIN
 MASK.STEP_00 := DW#16#0 ; 
 MASK.STEP_01 := DW#16#0; 
 MASK.STEP_02 := DW#16#0; 
 MASK.STEP_03 := DW#16#0; 
 MASK.STEP_04 := DW#16#0; 
 MASK.STEP_05 := DW#16#0;
 MASK.STEP_06 := DW#16#0;
 MASK.STEP_07 := DW#16#0;
 MASK.STEP_08 := DW#16#0;
 MASK.STEP_09 := DW#16#0;
 MASK.STEP_10 := DW#16#0;
 MASK.STEP_11 := DW#16#0;
 MASK.STEP_12 := DW#16#0;
 MASK.STEP_13 := DW#16#0;
 MASK.STEP_14 := DW#16#0;
 MASK.STEP_15 := DW#16#0;
/////
 COMPARE_MASK.STEP_00 := DW#16#0 ; 
 COMPARE_MASK.STEP_01 := DW#16#0; 
 COMPARE_MASK.STEP_02 := DW#16#0; 
 COMPARE_MASK.STEP_03 := DW#16#0; 
 COMPARE_MASK.STEP_04 := DW#16#0; 
 COMPARE_MASK.STEP_05 := DW#16#0;
 COMPARE_MASK.STEP_06 := DW#16#0;
 COMPARE_MASK.STEP_07 := DW#16#0;
 COMPARE_MASK.STEP_08 := DW#16#0;
 COMPARE_MASK.STEP_09 := DW#16#0;
 COMPARE_MASK.STEP_10 := DW#16#0;
 COMPARE_MASK.STEP_11 := DW#16#0;
 COMPARE_MASK.STEP_12 := DW#16#0;
 COMPARE_MASK.STEP_13 := DW#16#0;
 COMPARE_MASK.STEP_14 := DW#16#0;
 COMPARE_MASK.STEP_15 := DW#16#0;
 //
 OUTPUTS.STEP_00 := DW#16#0 ; 
 OUTPUTS.STEP_01 := DW#16#1; 
 OUTPUTS.STEP_02 := DW#16#2; 
 OUTPUTS.STEP_03 := DW#16#3; 
 OUTPUTS.STEP_04 := DW#16#4; 
 OUTPUTS.STEP_05 := DW#16#5;
 OUTPUTS.STEP_06 := DW#16#6;
 OUTPUTS.STEP_07 := DW#16#7;
 OUTPUTS.STEP_08 := DW#16#8;
 OUTPUTS.STEP_09 := DW#16#9;
 OUTPUTS.STEP_10 := DW#16#A;
 OUTPUTS.STEP_11 := DW#16#B;
 OUTPUTS.STEP_12 := DW#16#C;
 OUTPUTS.STEP_13 := DW#16#D;
 OUTPUTS.STEP_14 := DW#16#E;
 OUTPUTS.STEP_15 := DW#16#F;
 END_DATA_BLOCK

I have assigned the output of FC2 to DBD100 .. is DBD100 the issue?

I have created a 1 seconds incrementing value for iStep of 0-15 and repeating.

When I monitor MW100 onwards in a VAT I dont see any changes to any bits. I would expect to see 0-F appearing

Cheers
 
Hi
Thanks for that I was having a bad hair day and couldnt remember MD....

Cheers
 
Maybe your CASE statement does not work.
When you write a CASE statement you should always include an ELSE in order to handle the abnormal situation.

Also, are there anything in the actual values of "TEST".OUTPUTS.STEP_xx ?
Check them in the VAT too.

As a test, you can also just try an immediate
wOUTPUT := "TEST".OUTPUTS.STEP_00 ;
 
Hi Jesper... yes wOUTPUT.

I am playing around looking to emualate a Allen Bradley MEQ type sequencer.

Cheers
 
Hi Jesper
I was originally passing the DB and Step number like this

Code:
 //Calcultate the required offset, each DWORD occupies 4.
    MASK_OFFSET :=iStep * 4 ;
    COMPARE_OFFSET := MASK_OFFSET +64 ;
    OUTPUT_OFFSET := MASK_OFFSET + 128 ;
 
    // Get data from the DB
    MASK_WORD := (WORD_TO_BLOCK_DB(INT_TO_WORD(iDB)).DW[MASK_OFFSET]);
    COMPARE_WORD := (WORD_TO_BLOCK_DB(INT_TO_WORD(iDB)).DW[COMPARE_OFFSET]);
    wOUTPUT := (WORD_TO_BLOCK_DB(INT_TO_WORD(iDB)).DW[OUTPUT_OFFSET]);

but when my block output wasnt working I went down the simple route first

Thanks for your input it is interesting to see different ideas
 
SCL is formidable for symbolic access to structured data.
Your last example is exactly how I would never do it.
By writing it like that it is more like a glorified STL than SCL.
 
Jesper...

OK. If I was to go down your route how would i pass a DB number into the function? I will have maybe 8 difference FC instances each with their own DB similar/same as to DB200 and was looking for a single FC and be able to pass in a FC number.

Your example is also good for increasing the number of steps easily

Cheers
 
Ah yes. That is exactly one of the limitations of SCL. You cannot index the DB number itself.
Consider to pack everything into one DB. You can make arrays of structs, including other arrays.
Also, try to structure everything via one or more UDTs. When you start to think symbolically, it all falls into place with SCL.
 
Ok Jesper.
Siemens S7 is very clever but their always seems to be a limitation somewhere :)

Thanks
 
UDT example.....

Code:
TYPE UDT8
    STRUCT
    Step:ARRAY[1..100] OF
     STRUCT
        MASK:DWORD;
        COMPARE:DWORD;
        OUTPUTS:DWORD;
     END_STRUCT;
    END_STRUCT
END_TYPE

DATA_BLOCK DB201
    STRUCT
    Bert:udt 8;
    END_STRUCT
BEGIN
END_DATA_BLOCK
DATA_BLOCK DB202
    STRUCT
    Fred:udt 8;
    END_STRUCT
BEGIN
END_DATA_BLOCK
 
FUNCTION FC8 : VOID
Var_input
iStep:INT;
end_var
VAR_IN_OUT
 Seq:udt8;    
end_var    
Seq.Step[iStep].OUTPUTS:=Seq.Step[iStep].MASK OR Seq.Step[iStep].COMPARE;
END_FUNCTION
ORGANIZATION_BLOCK OB1
VAR_TEMP
    // Reserved
    info : ARRAY[0..19] OF BYTE;
    // Temporary Variables
END_VAR
    FC8(iStep:=10,Seq:=DB201.Bert);
    FC8(iStep:=20,Seq:=Db202.Fred);
    ;
END_ORGANIZATION_BLOCK
 
Hi LD
That is pretty interesting stuff.. I need to study it a little .. thanks
 

Similar Topics

Hi' I have 8 input bytes containing an ASCII value, now I want to move the contents of the first byte into an double word on the first place...
Replies
14
Views
3,313
So I'm pretty green when it comes to troubleshooting in the field so bear with me. We have a Danfoss valve that opens/closes from an analog output...
Replies
23
Views
940
Hi. This is pretty basic but I'm struggling to find an efficient solution. I have a float value of let say 666.555 that I want to move / split...
Replies
3
Views
195
hi, I got a plc S7-1200 with SEW movitrac **** and i need to program something ridiculous if my application reaches sensor 1 then my SEW has to...
Replies
0
Views
185
Afternoon, I have a DB in TIA Portal V16 that is optimised. I cannot change this. There is an array inside that block which consists of 3000...
Replies
9
Views
1,107
Back
Top Bottom