ShowStats Submodule
Required to draw a Show Stats widget for your driver.
The following template provides a generic dialog. Yours may differ.
<
{================================= ShowStats ===============================}
{ This module displays a window showing current driver statistics for the }
{ main driver. }
{===========================================================================}
ShowStats
(
Enable { Set true to display window };
)
[
PROTECTED Info { Driver info };
PROTECTED Stats { Driver stats };
]
Init [
If 1 Show;
[
Info = Dictionary();
Stats = Dictionary();
{ Declare the labels in the order we want them displayed }
Info["DriverNameLabel"] = Name;
Info["DriverTypeLabel"] = Invalid;
Info["VersionLabel"] = DriverVersion;
Stats["CountsLabel"] =
Stats["TimeStampLabel"] =
Stats["DateStampLabel"] =
Stats["DtLabel"] =
Stats["MaxDtLabel"] =
Stats["MinDtLabel"] =
Stats["ErrorLabel"] =
Stats["ErrorMessLabel"] =
Stats["LastErrorLabel"] =
Stats["LastErrMessLabel"] =
Stats["ErrorCountLabel"] =
Stats["ErrorTimeLabel"] =
Stats["ErrorDateLabel"] =
Stats["ErrorMemAddrLabel"] = Invalid;
]
]
Show [
\ShowStatsDialog(Enable, Info, Stats, HelpID {If F1 help is available});
Info["DriverTypeLabel"] = \GetPhrase(\GetDrawLabel(Root));
Stats["CountsLabel"] = Counts;
Stats["TimeStampLabel"] = GetTimePhrase(\CommStatsTimeStamp, "TimeFmtHMS24Hour");
Stats["DateStampLabel"] = GetDatePhrase(\CommStatsTimeStamp / 86400, "DateFmtFullWritten");
Stats["DtLabel"] = Format(0, 3, dt);
Stats["MaxDtLabel"] = Format(0, 3, Maxdt);
Stats["MinDtLabel"] = Format(0, 3, Mindt);
Stats["ErrorLabel"] = Error;
Stats["ErrorMessLabel"] = ErrMessage(Error);
Stats["LastErrorLabel"] = LastError;
Stats["LastErrMessLabel"] = ErrMessage(LastError);
Stats["ErrorCountLabel"] = ErrorCounts;
Stats["ErrorTimeLabel"] = GetTimePhrase(ErrorTime, "TimeFmtHMS24Hour");;
Stats["ErrorDateLabel"] = GetDatePhrase(ErrorDate, "DateFmtFullWritten");
Stats["ErrorMemAddrLabel"] = ErrorMemAddr;
]
{ ShowStats }
>
Any values you want can be put in the Stats dictionary. The values need to be set somewhere, which is usually done in a post-read data-processing submodule or in a subroutine as follows.
<
{=================================== SetStats ================================}
{ This subroutine sets the driver stats }
{=============================================================================}
SetStats
(
Err;
ErrAddress;
)
Stats[
If Watch(1);
[
IfElse(!Err,
Execute(
{ Good Message }
Error = Err;
++Counts;
dt = Seconds() - TimeStamp;
{ Check for negative dt }
IfThen(dt <= 0,
dt = Invalid;
); { End IfThen }
Mindt = PickValid(Min(Mindt, dt), Mindt, dt);
Maxdt = PickValid(Max(Maxdt, dt), Maxdt, dt);
TimeStamp = Seconds();
DateStamp = Today();
) { Execute };
{ELSE}
Execute(
{ Bad Message }
LastError = Error;
Error = Err;
++ErrorCounts;
ErrorTime = Seconds();
ErrorDate = Today();
ErrorMemAddr = ErrAddress;
) { Execute };
) { IfElse };
Return();
]
]
{ SetStats }
>