S7 array element copy pointer problem

spaderkung

Member
Join Date
Aug 2007
Location
South Sweden
Posts
389
Hi!

I modified some code, probably from member LD, to make a function

element := ReadFromArray(firstElement : ANY, offset : INT)

It seems to work fine as long as the array is an array of complex UDTs (the reason I wrote it). But for elementary arrays ([0..10] : INT) or ([0..10] : UdtWithOnlyIntMembers) it fails. The reason is that although the ANY.TYPE = 5 (INT) the ANY.NUM (repetition factor, size) = 1 where it should be 2 (bytes).

I had to modify the code to check for any elemental type, but I wonder why I did not get it to work the first time.

I run it on ACControls soft PLC, but I think I have also tried it on a 317.

Code:
FUNCTION FC547 : VOID
VAR_INPUT
//  BaseAddress : ANY ; 
  SrcElementFirst : ANY ; 
  SrcElementIndex : INT ; 
//  DstElement : INT ; 
  DstArea : ANY;
END_VAR
VAr_output
    srcNUM, dstNUM, retVal : INT;
    srcTYP, dstTYP : BYTE;
END_VAR
VAR_TEMP
    iSFC20Return : INT ; 
    pSrc:ANY;
    pDst:ANY;
 
ViewSrc AT pSrc:STRUCT
    // This order is the S7 pointer format of 10B
    ID:BYTE;
    TYP:BYTE;
    NUM:INT;
    DBN:INT;
    PTR:DINT;
    END_STRUCT;    
ViewDst AT pDst:STRUCT
    ID:BYTE;
    TYP:BYTE;
    NUM:INT;
    DBN:INT;
    PTR:DINT;
    END_STRUCT;    
END_VAR
    pDst:=DstArea;
    pSrc:=SrcElementFirst;
 
    // Problem with elementary types? Or just soft-plc?
    // But an INT, with type 5 gets NUM 1 == only 1 byte size?
 
 
    IF ViewDst.TYP = 5 OR ViewDst.TYP = 4 THEN
        ViewDst.NUM := 2;
    END_IF;
    IF ViewDst.TYP = 6 OR ViewDst.TYP = 7 OR ViewDst.TYP = 8 THEN
        ViewDst.NUM := 4;
    END_IF;
 
 
 
    // No modification to pDest
    // Add offset TO pSrc
    ViewSrc.PTR:= ViewSrc.PTR + ViewDst.NUM * 8 * SrcElementIndex;
    ViewSrc.NUM:= ViewDst.NUM;
 
    iSFC20Return:=BLKMOV(SRCBLK := pSrc, DSTBLK :=  pDst);
 
    srcNUM := ViewSrc.NUM;
    dstNUM := ViewDst.NUM;
    srcTYP := ViewSrc.TYP;
    dstTYP := ViewDst.TYP;
    retVal := iSFC20Return;
    //dbg out
END_FUNCTION
 
The number in the Any pointer is always the number of elements and this is not necessarily the number of bytes.

Code:
FUNCTION FC547 : VOID
VAR_INPUT
//  BaseAddress : ANY ; 
  SrcElementFirst : ANY ; 
  SrcElementIndex : INT ; 
//  DstElement : INT ; 
  DstArea : ANY;
END_VAR
VAr_output
    srcNUM, dstNUM, retVal : INT;
    srcTYP, dstTYP : BYTE;
END_VAR
VAR_TEMP
    iSFC20Return : INT ; 
    pSrc:ANY;
    pDst:ANY;
    iByteCount:INT;
 
ViewSrc AT pSrc:STRUCT
    // This order is the S7 pointer format of 10B
    ID:BYTE;
    TYP:BYTE;
    NUM:INT;
    DBN:INT;
    PTR:DINT;
    END_STRUCT;    
ViewDst AT pDst:STRUCT
    ID:BYTE;
    TYP:BYTE;
    NUM:INT;
    DBN:INT;
    PTR:DINT;
    END_STRUCT;    
END_VAR
    pDst:=DstArea;
    pSrc:=SrcElementFirst;
 
    CASE BYTE_TO_INT(ViewSrc.TYP) OF
        2,3:iByteCount:=1;
        4,5:iByteCount:=2;
        6,7,8:iByteCount:=4;        
    END_CASE;
 
 
 
    // No modification to pDest
    // Add offset TO pSrc
    ViewSrc.PTR:= ViewSrc.PTR + ViewDst.NUM * (8 * iByteCount) * SrcElementIndex;
    ViewSrc.NUM:= ViewDst.NUM;
 
    iSFC20Return:=BLKMOV(SRCBLK := pSrc, DSTBLK :=  pDst);
 
    srcNUM := ViewSrc.NUM;
    dstNUM := ViewDst.NUM;
    srcTYP := ViewSrc.TYP;
    dstTYP := ViewDst.TYP;
    retVal := iSFC20Return;
    //dbg out
END_FUNCTION
 
Last edited:
Thanks. Ofc on the repetition factor...
But with arrays of complex UDTs (mixed elementary types) the TYPE shows as 2 (and NUM is correct as the total size in bytes), so I need to stick with my original modification.
 

Similar Topics

Hello all, I apologize for the lack of code here. This is more of a basic idea I would like to try. This is my first time dealing with SCL and...
Replies
22
Views
13,089
Hello, first time poster here! A belated "thank you" for the direction I've already received from this forum! So, can I do this? Move value 1...
Replies
6
Views
709
I received the following message via PM, and am posting here publicly to help others. ============================================ I had a...
Replies
10
Views
1,012
Hi Folks, I am trying to trend in Logix Designer an element of an INT[223] input data array. For some reason, the "add" button is greyed out. I...
Replies
7
Views
2,183
I have 23 Micrologix 1400s and I want to take the same register, N100:99, out of each one and put in a single array in a CompactLogix L18ER. From...
Replies
18
Views
6,997
Back
Top Bottom