spaderkung
Member
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.
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