# FileOpen(FileName, Mode) hash function
Valid for use with hash command: HMI_Log
This function serves multiple purposes:
- Selecting the base of a file name to be used for subsequent logging operations.
- Creating an initial file with the given name.
- Setting the mode to use with the file name.
- 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:.
Mode | Description | Behaviour when SimpleHMI is first started | Effect 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 |
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 |
2 | Numbered. A sequence number is automatically included in the file name. The form is | On the next | On the next |
3 | Dated and numbered, for example | If the existing file of the same base name has today's date, then on the next | If the existing file of the same base name has today's date, then on the next |
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.