I am looking for some advice on this FC I just wrote. I have trace numbers that are constantly moved and want to verify that they match. They are always 10 bytes long stored as CHAR. This is my first attempt at using AR1 and AR2. Is this the most efficient way to do this? Also do I need to save AR1 and AR2 and the restore them at the end of the FC? I remeber hearing this but can't remeber how or why.
Here it is, what do you think?
Here it is, what do you think?
Code:
FUNCTION "CompareTraceNum" : BOOL
TITLE =Copy block with a block move
{ S7_language := '7(1) Deutsch (Deutschland) 28.05.2007 14:31:12' }
NAME : CopyByte
VERSION : 0.1
VAR_INPUT
DB_Src_1 : INT ;
ByteSrc_1 : INT ;
DB_Src_2 : INT ;
ByteSrc_2 : INT ;
Bytes : INT ;
END_VAR
VAR_TEMP
tempDB_Src_1 : INT ;
tempDB_Src_2 : INT ;
tempSrc_1_pntr : DWORD ;
tempSrc_2_pntr : DWORD ;
END_VAR
BEGIN
NETWORK
TITLE =Copy data
//Create Temp DB numbers so they can be used with the OPN command
L #DB_Src_1;
T #tempDB_Src_1;
L #DB_Src_2;
T #tempDB_Src_2;
//Create pointers for base of compare
L P#DBX 0.0; //Create pointer for source 1 byte
L #ByteSrc_1;
SLD 3;
+D ;
LAR1 ;
L P#DBX 0.0; //Create pointer for source 2 byte
L #ByteSrc_2;
SLD 3;
+D ;
LAR2 ;
//compare 1st DWord of Trace
OPN DB [#tempDB_Src_1];
L D [AR1,P#0.0];
OPN DB [#tempDB_Src_2];
L D [AR2,P#0.0];
==D ;
JCN NOK;
//compare 2nd DWord of Trace
OPN DB [#tempDB_Src_1];
L D [AR1,P#4.0];
OPN DB [#tempDB_Src_2];
L D [AR2,P#4.0];
==D ;
JCN NOK;
//compare last Word of Trace
OPN DB [#tempDB_Src_1];
L W [AR1,P#8.0];
OPN DB [#tempDB_Src_2];
L W [AR2,P#8.0];
==D ;
JCN NOK;
//If trace matches set the return value TRUE
SET ;
= #RET_VAL;
BEU ;
NOK: CLR ;
= #RET_VAL;
//SET and SAVE so ENO is always enabled
SET ;
SAVE ;
END_FUNCTION