Hello guys!
I have a question about efficient plc code.
I have created a simple block for converting a double integer to a string (array of chars not a true string) but I still think the code is inefficient.
I know the code are repeating so I could use a loop insted of rewriting the same code 7 times but I figured that the extra code needed to create the loop would add even more code being executed each scan.
So do anyone in here have any ideas about what I could do to make this more efficient?
Here's the code:
I have a question about efficient plc code.
I have created a simple block for converting a double integer to a string (array of chars not a true string) but I still think the code is inefficient.
I know the code are repeating so I could use a loop insted of rewriting the same code 7 times but I figured that the extra code needed to create the loop would add even more code being executed each scan.
So do anyone in here have any ideas about what I could do to make this more efficient?
Here's the code:
Code:
FUNCTION FC 6 : VOID
TITLE = TestBlock
STANDARD
VERSION : 1.0
VAR_INPUT
Integer : DINT ;
END_VAR
VAR_OUTPUT
Text : ARRAY [1 .. 7 ] OF CHAR ;
END_VAR
VAR_TEMP
BCD : DWORD ;
END_VAR
BEGIN
NETWORK
TITLE =
// Create BCD Code
LAR1 P##BCD;
L #Integer;
DTB ;
T #BCD;
LAR1 P##BCD;
// Transfer character
LAR1 P##BCD;
L LB [AR1,P#0.0];
L B#16#F;
AD ;
L B#16#30;
OW ;
T #Text[1];
// Transfer character
LAR1 P##BCD;
L LB [AR1,P#1.0];
L B#16#F0;
AD ;
SRW 4;
L B#16#30;
OW ;
T #Text[2];
// Transfer character
LAR1 P##BCD;
L LB [AR1,P#1.0];
L B#16#F;
AD ;
L B#16#30;
OW ;
T #Text[3];
// Transfer character
LAR1 P##BCD;
L LB [AR1,P#2.0];
L B#16#F0;
AD ;
SRW 4;
L B#16#30;
OW ;
T #Text[4];
// Transfer character
LAR1 P##BCD;
L LB [AR1,P#2.0];
L B#16#F;
AD ;
L B#16#30;
OW ;
T #Text[5];
// Transfer character
LAR1 P##BCD;
L LB [AR1,P#3.0];
L B#16#F0;
AD ;
SRW 4;
L B#16#30;
OW ;
T #Text[6];
// Transfer character
LAR1 P##BCD;
L LB [AR1,P#3.0];
L B#16#F;
AD ;
L B#16#30;
OW ;
T #Text[7];
SET ;
SAVE ;
END_FUNCTION