Monday, February 24, 2014

Log an Event

Here is a function to log a single event:

(* Datetime is a udint (uin32) that reads the system clock 0.9.0 as an ISaGRAF I/O *)
EVENT_LOG FUNCTION (Code, Input, Value)

(* CODE - an integer to describe the event (hosts like integers) *)
(* Input - which input caused the event *)
(* Value - the value of the input that caused the event *)
(* Stamp - Date/Time stamp of when the event occured *)

(* Move all data down by one row – start at bottom, filling from above *)
  FOR pos := ANY_TO_DINT(Event_Log_Size) TO 2 BY -1 DO
    Event_Code[pos]  := Event_Code[pos - 1];
    Event_Input[pos] := Event_Input[pos - 1];
    Event_Value[pos] := Event_Value[pos - 1];
    Event_Stamp[pos] := Event_Stamp[pos - 1];
  END_FOR;

(* place new log in first row *)
  Event_Code[1]  := Code;
  Event_Input[1] := Input;
  Event_Value[1] := Value;
  Event_Stamp[1] := DateTime;
  Event_Log := TRUE;    (* all functions must return a value *)

Here is the initialization code for cold boot

(* ************ at cold boot - clear the log ************** *)
  FOR pos := 1 TO ANY_TO_DINT(Event_Log_Size) DO
    Event_Code[pos]  := 0;
    Event_Input[pos] := 0;
    Event_Value[pos] := 0.0;
    Event_Stamp[pos] := 0;
  END_FOR;

No comments:

Post a Comment