Hello!
I'm beginner in SCL Programming And, I want to make a FB with SCL which can convert each byte of a DB (that we give it as an input) from Ascii code to Hex!
I wrote program below but when i compile it there are several error and doesnt work:
FUNCTION_BLOCK FB200
VAR_INPUT//*****************
x: INT; // Number of input Data block
y: INT; // Number of byte that must be converted
z: INT; // Number of Output Data block
END_VAR
VAR_OUTPUT//*******************
Status: BOOL:=0;
END_VAR
//*****************************************
FOR y:=0 TO 10 DO
IF db[x].db[y]='A' THEN
db[z].db[y]:=41;
ELSE
IF db[x].db[y]='B' THEN
db[z].db[y]:=42;
ELSE
IF db[x].db[y]='C' THEN
db[z].db[y]:=43;
ELSE
IF db[x].db[y]='D' THEN
db[z].db[y]:=44;
ELSE
Status:=1;
END_IF;
END_IF;
END_IF;
END_IF;
END_FOR;
END_FUNCTION_BLOCK
FUNCTION_BLOCK FB202
// Take care this block do no check, if DB number is correct or if protected, or enough long...
VAR_INPUT
size: INT; // Number of byte that must be converted
ptDB_In : POINTER;// POINTER DB IN => FOR EXAMPLE P#DB22.DBB0
_pt AT ptDB_In : STRUCT
DBNr: WORD;
Adr: DWORD;
END_STRUCT;
ptDB_out : POINTER;// POINTER DB OUT => FOR EXAMPLE P#DB5.DBB10
_pt2 AT ptDB_out : STRUCT
DBNr2: WORD;
Adr2: DWORD;
END_STRUCT;
END_VAR
VAR
Adr: INT;//INTEGER Adress for byte number of data block
Adr2: INT;//INTEGER Adress FOR BYTE number OF data block
y:INT;//iNDEX
END_VAR
VAR_OUTPUT
Status: BOOL:=0;
END_VAR
BEGIN
Adr := DWORD_TO_INT(SHR(IN:=SHL(IN:=_pt.Adr,N:=8),N:=11));//Convert number of beginning byte into integer
Adr2 := DWORD_TO_INT(SHR(IN:=SHL(IN:=_pt2.Adr2,N:=8),N:=11));//Convert number of beginning byte into integer
FOR y:=0 TO size DO
IF WORD_TO_BLOCK_DB(_pt.DBNr).DB[Adr+y]= CHAR_TO_BYTE('A') THEN
WORD_TO_BLOCK_DB(_pt2.DBNr2).DB[Adr2+y]:=41;
END_IF;
IF WORD_TO_BLOCK_DB(_pt.DBNr).DB[Adr+y]=CHAR_TO_BYTE('B') THEN
WORD_TO_BLOCK_DB(_pt2.DBNr2).DB[Adr2+y]:=42;
END_IF;
IF WORD_TO_BLOCK_DB(_pt.DBNr).DB[Adr+y]=CHAR_TO_BYTE('C') THEN
WORD_TO_BLOCK_DB(_pt2.DBNr2).DB[Adr2+y]:=43;
END_IF;
IF WORD_TO_BLOCK_DB(_pt.DBNr).DB[Adr+y]=CHAR_TO_BYTE('D') THEN
WORD_TO_BLOCK_DB(_pt2.DBNr2).DB[Adr2+y]:=44;
END_IF;
Status:=1;
END_FOR;
END_FUNCTION_BLOCK