SPLat Logo

# FileOpen(FileName, Mode) hash function

NOTICE: We are updating our website. For product enquiries and orders please contact us directly.
NOTICE: SPLat Controls has moved. We are now at 1/85 Brunel Rd, Seaford, 3198. map

# FileOpen(FileName, Mode) hash function

Valid for use with hash command: HMI_Log

This function serves multiple purposes:

  1. Selecting the base of a file name to be used for subsequent logging operations.
  2. Creating an initial file with the given name.
  3. Setting the mode to use with the file name.
  4. Subsequently, switching between log files.

The first time a file is to be opened in a session of SimpleHMI, the Mode must be specified. Any subsequent uses of the Mode argument are unnecessary, and ignored. You can have up to 20 log files on the go at once. Any log data from the SPLat (host) will be saved to the file last mentioned in a FileOpen, thus the FileOpen function serves to switch between files. You may for example use one file to log temperature every second and another to log manual interventions by an Enduser.

The safest policy is to do a FileOpen just before each write to a file, and also during the Connect event handler, and to include the mode every time.

FileName

The FileName should be a simple file name, without a directory/folder path. It may optionally contain a file name extension. Examples are:

MyFile.txt

MyFile

The first of those includes an extension, which will be used when the file is written. The second contains no extension. SimpleHMI will default it to .log.

Note: Windows is insensitive to case, so MyFile, myfile and MYfIle are all equivalent. The Android file system is case sensitive. The SimpleHMI shares code between Windows and Android, and is internally case-insensitive. If you vary the case between references, the results in Android could be unpredictable.

Mode

The mode controls the automatic generation of date codes and sequence numbers as part of the file name written to disk/SD card according to the following table:.

ModeDescriptionBehaviour when SimpleHMI is first startedEffect of NewFile(FileName) hash function
0 Plain. The base name is used as-is. The base name may not include the character pairs Data is appended to any existing file with this name.

The existing file will be overwritten on the next LogWrite to this file.

1 Dated. A date stamp is automatically included in the file name. The form is Data is appended to any existing file with this name.

If an existing file of the same base name has today's date, it will be overwritten on the next LogWrite to this file, and old data will be lost. Otherwise a new file will be created with today's date.

2 Numbered. A sequence number is automatically included in the file name. The form is

On the next LogWrite to this file base name the number will be incremented.

On the next LogWrite to this file base name the number will be incremented.

3 Dated and numbered, for example

If the existing file of the same base name has today's date, then on the next LogWrite to this file base name the number will be incremented.

If the existing file of the same base name has today's date, then on the next LogWrite to this file base name the number will be incremented.

The logging directory/folder

The folder used to save log files is not controller from the SPLat.

In Android the log files are always written to a default directory. When you plug the Android device into a computer via USB the files will be in a directory named SimpleHMI/logging. No user action, short of removing the SD card from the device, can stop logging.

In Windows the enduser must select a folder for log files to be stored in. If no folder has been selected, SimpleHMI will prompt the enduser for one, just once. The selected folder is remembered between sessions, and may be changed in the Settings tab. If none has been selected the system will ask the enduser to select a folder. If no folder is selected, logging is impossible and log data is ignored.