Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: RBPLC on August 11, 2021, 02:05:18 PM
-
Would it be easy to add a tickbox option to the FILELOG command to disable the time stamp? Or better, an option for custom formatting for the timestamp.
-
FILELOG is meant to be simple, minimal options.
It is not too hard create your own completely customizable log mechanism in its own PROGRAM code block using FILEOPEN, STRPRINT, FILEWRITE, FILECLOSE. Stick whatever you want in your STRPRINT.
I would recommend using Stage
Name the PROGRAM codeblock MyFileLog
SG S0
FILEOPEN (append) OnSuccess JMP S1, OnError JMP S3 // always try to close the file
SG S1
STRPRINT
JMP S2
SG S2
FILEWRITE OnSuccess JMP S3, OnError JMP S3 // always try to close the file
SG S3
FILECLOSE OnSuccess JMP S4, OnError JMP S4
SG S4
EXIT
Then RUN that code block at whatever interval (e.g. SP4 for once a second, your own auto-resetting timer at whatever interval you want T42.Done)
// somewhere in $Main
STR T42.Done
AND C99 // completely disable it by turning off C99
RUN MyFileLog
-
You might need a little more logic if you want a header the first time the file is written to - let me know if you want/need help with that.
-
What does the header logic look like? The reason I'm asking these questions is I'm working with a data analysis software that is expecting data formatting in a certain way with certain headers. The default time stamp is formatted to work with excel, but I need to be able to format it for unix. I'm currently logging unix time in the column adjacent to the timestamp. Short of building a custom logging Program, it looks like I'll have to open the .csv and make a few tweaks before importing to the data analysis software if I want to continue to use the FILELOG instruction.
-
What does the header logic look like?
Hmmm, after thinking about it, you could just do the following. The FileHandle (output of OPENFILE) has a .FileSize member. So then in SG S1 where you are generating the output text (say to SL0), see if the FH.FileSize is 0. If it is, do a STRPRINT of the header text w/CR/LF, then APPEND the actual data:
SG S1
// SL0 is where we are putting the data, but possibly prepend the header
STRCLEAR SL0
STRE FH.FileSize 0 // file is empty? prepend the header text to SL0
STRPRINT SL0 "TimeStamp, MyDataA, MyDataB$0D$0A"
STR ST1 ($On)
STRPRINT SL0 APPEND DST21 "," R10 "," R49 "$0D$0A"
-
DST21 is UTC Unix Time
DST22 is Local Unix Time
-
I'm using the built in Unix memory but I'm having to modify it with STRPRINT to get sub-second resolution.
-
Would it be easy to add a tickbox option to the FILELOG command to disable the time stamp? Or better, an option for custom formatting for the timestamp.
I figured somebody had to ask for this at some point. Thanks franji1 for the simple solution. Sometimes I cannot see the forest for the trees...