News:

  • October 16, 2026, 08:04:44 AM

Login with username, password and session length

Author Topic: Option for FILELOG  (Read 11463 times)

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Option for FILELOG
« 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.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: Option for FILELOG
« Reply #1 on: August 11, 2021, 02:15:41 PM »
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

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: Option for FILELOG
« Reply #2 on: August 11, 2021, 02:19:16 PM »
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.

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Re: Option for FILELOG
« Reply #3 on: August 11, 2021, 02:50:51 PM »
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.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: Option for FILELOG
« Reply #4 on: August 11, 2021, 04:09:41 PM »
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:


Code: [Select]
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"

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3850
    • Host Engineering
Re: Option for FILELOG
« Reply #5 on: August 11, 2021, 04:10:57 PM »
DST21 is UTC Unix Time
DST22 is Local Unix Time

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Re: Option for FILELOG
« Reply #6 on: August 11, 2021, 04:49:49 PM »
I'm using the built in Unix memory but I'm having to modify it with STRPRINT to get sub-second resolution.

Scooter

  • Jr. Member
  • **
  • Posts: 14
Re: Option for FILELOG
« Reply #7 on: October 22, 2021, 03:00:34 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.

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...