Hi all! im a two week old TwinCAT newby and im having some problems to measure the time that a BOOL is TRUE, for exmple a machine thats turned on.
I first tried getting the systemtime and tried some math on that but it didnt work.
so i tried the following, but for some reason the string remains empty, or at least '???'.
If there is a more simple or easy way to sole this, im all ears!
thanks guys/girls! (code below)
(*CODE*)
VAR
fbFormat : FB_FormatString;
bError : BOOL;
nErrID : UDINT;
sOut : T_MaxString;
iSecond : INT;
iMinute : INT;
iHour : INT;
Teller_NSA_OFF : TON;
Teller_NSA_ON : TON;
bTeller_NSA : BOOL := TRUE;
stNSA_bedrijfstijd : STRING;
END_VAR
(*The format for the string i use*)
fbFormat( sFormat := '%.2d:%.2d:%.2d', arg1 := F_INT( iHour ),
arg2 := F_INT( iMinute ),
arg3 := F_INT( iSecond ),
sOut => stNSA_bedrijfstijd, bError => bError, nErrID => nErrID );
(*Here i use two Timer on-delay's to make a BOOL high every second*)
Teller_NSA_ON (IN:= bTeller_NSA, PT:= T#500ms);
Teller_NSA_OFF(IN:= NOT bTeller_NSA, PT:= T#500ms);
IF (Teller_NSA_ON.Q = TRUE) THEN
bTeller_NSA := FALSE;
END_IF
IF (Teller_NSA_OFF.Q = TRUE) THEN
bTeller_NSA := TRUE;
END_IF
(*Seconds become minutes and minutes become hours, this is displayed in VIS_NSA_bedrijfstijd.stTextisplay*)
IF (IN_NSA_bedrijf = TRUE AND bTeller_NSA = TRUE) THEN
iSecond := iSecond + 1;
VIS_NSA_bedrijfstijd.stTextDisplay := stNSA_bedrijfstijd;
IF ( iSecond = 60 ) THEN
iMinute := iMinute + 1;
ELSIF ( iMinute = 60) THEN
iHour := iHour + 1;
iMinute := 0;
END_IF
END_IF
I first tried getting the systemtime and tried some math on that but it didnt work.
so i tried the following, but for some reason the string remains empty, or at least '???'.
If there is a more simple or easy way to sole this, im all ears!
thanks guys/girls! (code below)
(*CODE*)
VAR
fbFormat : FB_FormatString;
bError : BOOL;
nErrID : UDINT;
sOut : T_MaxString;
iSecond : INT;
iMinute : INT;
iHour : INT;
Teller_NSA_OFF : TON;
Teller_NSA_ON : TON;
bTeller_NSA : BOOL := TRUE;
stNSA_bedrijfstijd : STRING;
END_VAR
(*The format for the string i use*)
fbFormat( sFormat := '%.2d:%.2d:%.2d', arg1 := F_INT( iHour ),
arg2 := F_INT( iMinute ),
arg3 := F_INT( iSecond ),
sOut => stNSA_bedrijfstijd, bError => bError, nErrID => nErrID );
(*Here i use two Timer on-delay's to make a BOOL high every second*)
Teller_NSA_ON (IN:= bTeller_NSA, PT:= T#500ms);
Teller_NSA_OFF(IN:= NOT bTeller_NSA, PT:= T#500ms);
IF (Teller_NSA_ON.Q = TRUE) THEN
bTeller_NSA := FALSE;
END_IF
IF (Teller_NSA_OFF.Q = TRUE) THEN
bTeller_NSA := TRUE;
END_IF
(*Seconds become minutes and minutes become hours, this is displayed in VIS_NSA_bedrijfstijd.stTextisplay*)
IF (IN_NSA_bedrijf = TRUE AND bTeller_NSA = TRUE) THEN
iSecond := iSecond + 1;
VIS_NSA_bedrijfstijd.stTextDisplay := stNSA_bedrijfstijd;
IF ( iSecond = 60 ) THEN
iMinute := iMinute + 1;
ELSIF ( iMinute = 60) THEN
iHour := iHour + 1;
iMinute := 0;
END_IF
END_IF