Knowledge Base

SimpleHMI lets you do logging of data from the host device (SPLat or other). The logging facility features:

  • Up to 20 separate log files can be written with different data.
  • File names can be automatically date stamped and sequence numbered, or both
  • You can control the file name extension, for example .txt.csv or .log
  • In Android, the log file directory is pre-determined. Your Enduser can find it easily when connecting via USB
  • Individual records can be date and/or time stamped

Logging uses the HMI_Log hash command. Please click that link and read up.

Note that in SPLat/PC the SIO/SimpleHMI window must be active for logging to take place. A file path (folder name) must be specified for the log file, in the Settings tab of the SIO window. The file name itself is embedded in the SPLat program.

Example 1:

This is a simple example. It uses an MS120, but you could easily convert it to an MMi202 by re-defining the input buttons. The program simply logs button presses.

When one of the buttons, named iStart is pressed, the program opens the log file and records the date. When subsequently another button, iLogOne is pressed, it logs the time. Finally, a 3rd button, iAllDone, halts the program by brutally crashing it. This allows SPLat/PC to connect to the controller.

(Click here for some tips for working around problems with copy and paste out of Internet Explorer and HTML-help (.chm) files)

;Input definitions to suit MS120
iStart          iEQU    12
iLogOne         iEQU    13
iAllDone        iEQU    16

        ON              20      ;LCD backlight on MS120
        OBCA_Mode       2
;                        0123456789123456
        OBLCD_Text      "Starting serial "
        OBLCD_Text      "(10S pause) "

#       Open_Serial User(38400,8,N)         ;Initialise the serial port
        LaunchTask      Capture
        LaunchTask      HeartBeat      ;Blink an output to show we are alive
        RunTasksForever

;----- Capture task -----
Capture:
        OBLCD_Cls
;                        0123456789123456
        OBLCD_Text      "Push Start"
        WaitOnK         iStart           ;Wait for user start command
        OBLCD_Cls
        OBLCD_Text      "Push LogOne or"
        OBLCD_SetCur    1,0
        OBLCD_Text      "AllDone button"

#       HMI_Log         FileOpen(mylog.txt,0)
#       HMI_Log         Print("Log opened ") YYMMDD() LogWrite()
Loop1:
        YieldTask
        GoIfInK         iLogOne,LogOne   ;Test LogOne button
        GoIfInK         iAllDone,AllDone ; Quit?
        GoTo            Loop1

LogOne:
#       HMI_Log         Print("LogOne pressed at ") HHMMSS() LogWrite()
        GoTo Loop1

AllDone:
        OBLCD_Cls
        OBLCD_Text      "All done"

#       HMI_Log         Print("Shut down ") YYMMDD() Print("at ") HHMMSS() LogWrite()

;Deliberately crash so SPLat/PC can get back control and connect
Here:   GoSub           Here

;Blink an output to signal the program is running
HeartBeat:
        On              8
        Pause           1
        Off             8
        Pause           25
        GoTo            HeartBeat
Example 2:

This is a more elaborate example, maintaining several logs in different modes.

The following program maintains 3 separate logs:

  1. A log of inputs 0 to 3, sampled once every 10 seconds. The file name is date stamped. Each record is time stamped.
  2. A log of each change of state on input 4. The file name is numbered. Turning input 3 on increments the file number. Each record is time stamped.
  3. A log of user presses on a button on the SimpleHMI screen. Uses a simple file name (no date or numbering). Each record is date and time stamped.
***************** SimpleHMI logging example *****************************
# Open_Serial User(38400,8,N)
GoSub HMI_Connect ;Paint the initial screen
# HMI ConnectEvent(HMI_Connect) ;Declare the handler for the Connected event
LaunchTask Watch4Inputs ;Log inputs 0-3 every 10s
LaunchTask WatchInput4 ;Log all changes on input 4
LaunchTask WatchInput3 ;Task to create new files for Input 4 log
LaunchTask HeartBeat ;Blink an output to show we are alive
LaunchTask Crash ;Catch input, crash to get back control of serial port
RunTasksForever

;Connected event: Paint the screen
HMI_Connect:
# HMI Reset() Cls() HideAllButtons()
# HMI_Log FileOpen(Watch4Inputs.csv, 1) ;Mode 1 = Dated file
# HMI_Log FileOpen(WatchInput4.log, 2) ;Create/initial open. Mode 2 = numbered file
# HMI_Log FileOpen(UserInputs.txt, 0)
# HMI Cursor(1, C-7) Print("Logging example")
# HMI ButtonEvent(, C-3, 0.3, 6, 0.4, "Enduser event", evEnduser)
return

;==================================================================================================================
;A log of inputs 0 to 3, sampled once every 10 seconds. The file name is date stamped. Each record is time stamped.
bInput0to3: defBYTE
Watch4Inputs: ;Log inputs 03 every 10s
InputFM 0 ;Sample inputs 0-7
LoadX 'F ;Select lower 4 bits
AndM ;Mask off top 4 bits
Store bInput0to3 ;Save so HexVar can get hold of it
# HMI_Log FileOpen(Watch4Inputs.csv, 1) ;Mode 1 = Dated file
# HMI_Log HHMMSS() Print(",") HexVar(bInput0to3) LogWrite()
Pause 1000 ;10 seconds
GoTo Watch4Inputs

;==================================================================================================================
;A log of each change of state on input 4. The file name is numbered.
;Turning input 3 on increments the file number. Each record is time stamped.
;This uses two tasks. One watches for and logs changes. The other takes care of the new-file behaviour

WatchInput4: ;Log all changes on input 4
# HMI_Log FileOpen(WatchInput4.log, 2)
# HMI_Log Print("Monitor started at ") hhmmss() LogWrite()
Input 4
GoIfT WI4onA
WI4off:
WaitOn 4
WI4onA:
# HMI_Log FileOpen(WatchInput4.log, 2) ;Switch to the file
# HMI_Log Print("Input 4 on at ") hhmmss() LogWrite()
WI4on:
WaitOff 4
# HMI_Log FileOpen(WatchInput4.log, 2) ;Switch to the file
# HMI_Log Print("Input 4 off at ") hhmmss() LogWrite()
GoTo WI4off

;------------------------------------------
WatchInput3: ;New file for Input 4 log
WaitOnK 3
# HMI_Log NewFile(WatchInput4.log) ;Signal new file creation on the next record write
GoTo WatchInput3

;==================================================================================================================
;A log of user presses on a button on the SimpleHMI screen. Uses a simple file name (no date or numbering).
;Each record is date and time stamped.
;Apart from the initial FileOpen in the ConnectEvent handler, this is the the whole thing.
evEnduser:
# HMI_Log FileOpen(UserInputs.txt, 0) Print("Pressed at ") hhmmss() Print(" on date:") yymmdd() LogWrite()
Return

********************* Minor stuff ***************************************************
;Blink an output to signal the program is running
HeartBeat:
On 0
Pause 1
Off 0
Pause 25
GoTo HeartBeat

;Deliberately crash the program to get back control of the serial port, so SPLat/PC can connect.
Crash: WaitOnK 0
Here GoSub Here