FUNCTION FC 1 : VOID
TITLE =chars packed into dword example
VERSION : 0.1
VAR_INPUT
cChar1 : CHAR ;
cChar2 : CHAR ;
cChar3 : CHAR ;
cChar4 : CHAR ;
cChar5 : CHAR ;
cChar6 : CHAR ;
cChar7 : CHAR ;
cChar8 : CHAR ;
iMethod : INT ;
END_VAR
VAR_OUTPUT
dwOutput1 : DWORD ;
dwOutput2 : DWORD ;
END_VAR
VAR_TEMP
acTempChars : ARRAY [1 .. 8 ] OF CHAR ;
adwTempDwords : ARRAY [1 .. 2 ] OF DWORD ;
iSFC20Return : INT ;
END_VAR
BEGIN
NETWORK
TITLE =pack chars from input into temp array of chars
L #cChar1;
T #acTempChars[1];
L #cChar2;
T #acTempChars[2];
L #cChar3;
T #acTempChars[3];
L #cChar4;
T #acTempChars[4];
L #cChar5;
T #acTempChars[5];
L #cChar6;
T #acTempChars[6];
L #cChar7;
T #acTempChars[7];
L #cChar8;
T #acTempChars[8];
NETWORK
TITLE =select method required, default to method 1
L #iMethod;
JL list;
JU m1;
JU m1;
JU m2;
JU m3;
JU m4;
list: JU m1;
NETWORK
TITLE =method 1 - read 4 chars as dwords and copy to temp dwords
m1: LAR1 P##acTempChars;
L D [AR1,P#0.0];
T #adwTempDwords[1];
L D [AR1,P#4.0];
T #adwTempDwords[2];
JU exit;
NETWORK
TITLE =method 2 - read chars and copy into successive bytes of dwords
m2: LAR1 P##adwTempDwords;
L #acTempChars[1];
T B [AR1,P#0.0];
L #acTempChars[2];
T B [AR1,P#1.0];
L #acTempChars[3];
T B [AR1,P#2.0];
L #acTempChars[4];
T B [AR1,P#3.0];
L #acTempChars[5];
T B [AR1,P#4.0];
L #acTempChars[6];
T B [AR1,P#5.0];
L #acTempChars[7];
T B [AR1,P#6.0];
L #acTempChars[8];
T B [AR1,P#7.0];
JU exit;
NETWORK
TITLE =method 3 - read chars into the accumulator and shift
m3: L #acTempChars[1];
SLD 8;
L #acTempChars[2];
OD ;
SLD 8;
L #acTempChars[3];
OD ;
SLD 8;
L #acTempChars[4];
OD ;
T #adwTempDwords[1];
L #acTempChars[5];
SLD 8;
L #acTempChars[6];
OD ;
SLD 8;
L #acTempChars[7];
OD ;
SLD 8;
L #acTempChars[8];
OD ;
T #adwTempDwords[2];
JU exit;
NETWORK
TITLE =method 4 - use block copy
m4: CALL SFC20 (
SRCBLK := #acTempChars,
RET_VAL := #iSFC20Return,
DSTBLK := #adwTempDwords);
JU exit;
NETWORK
TITLE =output the result
exit: L #adwTempDwords[1];
T #dwOutput1;
L #adwTempDwords[2];
T #dwOutput2;
SET ;
SAVE ;
END_FUNCTION