SCL FB Local Variable Access for BlkMov

Join Date
Jun 2007
Location
Oxford, UK
Posts
163
Hi All,

It has been a long, long time. But in times of crisis this is somewhere I hold in the highest regard for accurate and swift responses.

I have searched but I am struggling to find an answer.

I am working on a program to sequence some data, I want to seperate up some strings I have built up in local data and put them into a DB one character at a time ready for processing. I thought about using the MID function to individually split up every char in the string but this seemed a little clunky to do 400 times.

So I thought about using a blockmov for the strings but skipping the first 2 bytes of header into the array of chars. This means that I can just get the LEN of the string and do it once per string (about 40) in a loop of all the data.

However I have hit a knowledge wall.

I am using SCL for the first time in anger and it is a learning curve. Programming in Step 7 rather than TIA also means none of the nice stuff. So perhaps this is easy, perhaps not.

I have built up all my strings in my local FB and they are ready to transport with the BLKMOV, however how to I address a pointer to the local FB variables? Essentially to the iDB. I need to be able to strip off the first 2 bytes of the string by dynamically addressing the source pointer for the BLKMOV. I understand how to construct pointers but when it comes to iDB/local variables is there any way to address them rather than symbolically so as to strip off the header data?

Declared the pointer here:

Code:
pDST, : ANY; // DB address ANY pointer - used for accessing DB data

pAnyDST AT pDST :
STRUCT // Diassembled ANY pointer structure
bS7Code         : BYTE; // Code for S7 (fixed at 16#10)
bDataType       : BYTE; // Code for data type
iLength         : INT; // Repetition factor = Send/receive length
iDBNumber       : INT; // Data block Number
bMemoryArea     : BYTE; // Specified memory area
bByteAddressMSB : BYTE; // Byte address most significant bits
wByteAddressLSB : WORD; // Byte address least significant bits
END_STRUCT;

This is the code, in essence, that will address the pointer. My issue is the section in bold. For a "regular" DB or data I can just calculate it. What about for the iDB of this FB instance?

Code:
(*Contruct the pointers for the move destination*)
pAnyDT.bS7Code := 16#10;
pAnyDT.bDataType := 16#02;
pAnyDT.iLength := 8;
pAnyDT.iDBNumber := iGlobalDBNumber;
pAnyDT.bMemoryArea := 16#84;
pAnyDT.bByteAddressMSB := 0;
pAnyDT.wByteAddressLSB := INT_TO_WORD(CManagementDataLength*8);

I understand that I can address local variables to a block move, but what about if I want to change that source data? Essentially outside of it's data type.

Code:
iDateTime:=BLKMOV(srcblk:= dtSFC1DateTime, dstblk:= pDT);

I hope this makes sense...
 
Here's an example of copying an array of strings to an array of char arrays. The string data gets copied to the char arrays using SFC20.

Code:
FUNCTION_BLOCK fb89
CONST 
 iNoOfStrings:=40;
 iNoOfChars:=20;
END_CONST

VAR  
tString:STRING[iNoOfChars];     
Data: ARRAY[1..iNoOfStrings] OF STRING[20];
CharData:ARRAY[1..iNoOfStrings] OF STRUCT
    Strg:ARRAY[1..iNoOfChars] OF CHAR;
  END_STRUCT;  
END_VAR    
VAR_TEMP
    i,j,sfc20RET:INT;
END_VAR;
FOR i:=1 TO iNoOfStrings DO
 tString:=INT_TO_STRING(i);   
 Data[i]:=CONCAT(In1:='String',in2:=tString); 
 sfc20Ret:=SFC20(srcblk:=Data[i],dstblk:=CharData[i]);
END_FOR;

END_FUNCTION_BLOCK;
 
Here's an example of copying an array of strings to an array of char arrays. The string data gets copied to the char arrays using SFC20.

Code:
FUNCTION_BLOCK fb89
CONST 
 iNoOfStrings:=40;
 iNoOfChars:=20;
END_CONST

VAR  
tString:STRING[iNoOfChars];     
Data: ARRAY[1..iNoOfStrings] OF STRING[20];
CharData:ARRAY[1..iNoOfStrings] OF STRUCT
    Strg:ARRAY[1..iNoOfChars] OF CHAR;
  END_STRUCT;  
END_VAR    
VAR_TEMP
    i,j,sfc20RET:INT;
END_VAR;
FOR i:=1 TO iNoOfStrings DO
 tString:=INT_TO_STRING(i);   
 Data[i]:=CONCAT(In1:='String',in2:=tString); 
 sfc20Ret:=SFC20(srcblk:=Data[i],dstblk:=CharData[i]);
END_FOR;

END_FUNCTION_BLOCK;
Nice. That is a nice compact piece of code.

What if the strings vary in length? Does the BlkMov know the length of the string?

Basically what you are saying is you can address it directly from the local variables and then send it to the array. If that array happened to be a DB of chars would it react the same?

I realise that I should probably just go and try these things...
 

Similar Topics

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
HI i would like to know how to get a variable that will store the amount of times a program has been executed. The issue is I have 3 DBs for 1 FB...
Replies
2
Views
82
Hi, I have an intermediate-advance knowledge of programming with TIA Porta in Ladder, would you recommend me to start learning SCL for it to...
Replies
11
Views
559
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 everyone, I am new to this amazing world of PLC, well... I mean, in practice, since I already knew electronics, programming languages, IT, and...
Replies
7
Views
654
Back
Top Bottom