Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

CRBASIC TableFile timestamp file name


capmon Dec 6, 2016 02:38 PM

Has anyone been able to timestamp a file name when using the TableFile function?

I tried implementing this but always ended up with a static value in the file name.  I think it is the exact date time of when the program compiled on the datalogger (CR1000 running OS30.01).

Every few minutes, I would plug in a SC115 and end up with file names like:

  • 2016120609371234_0.dat
  • 2016120609371234_1.dat
  • 2016120609371234_2.dat
  • 2016120609371234_3.dat
  • ...

But according to the file attribues, they each have different creation date times (minutes apart).

Public DateTime(6) As String * 32
Dim iTimeStamp

DataTable(logData, True, -1)
  TableFile("USB:"&DateTime(5),8,-1,Sec,0,0)
  DataInterval(0,1,Min,10)
...
EndTable

Begin Prog
Scan (5, Sec,3,0)
For iTimeStamp = 6 to 1 Step -1
  DateTime(iTimeStamp) = Public.Timestamp(iTimeStamp, 1)
Next iTimeStamp
CallTable logData
EndScan


nsw Dec 9, 2016 04:16 PM

Think that is probably due to the "TableFile" instruction parameter "FileName" must be a constant and enclosed in quotes. I guess it is creating the constant first time through from your variable and then using that from then on.

You may end up having to sue the "LastFileName" parameter string variable to manipulate that and then use the "FileRename". I have not tried it, but I guess this should work.


Dana Dec 9, 2016 05:15 PM

I ran a couple of quick tests, and I think the only way around this would be to rename the file after it is written using FileRename. Keep in mind that you will need to parse characters from the timestamp string, since / and : are not valid characters for filenames. I used the Mid instruction to do this, though I'm sure there are more eloquent ways:

     TSTamp=Public.Timestamp(1,1)
     TStampParse=Mid (TStamp,12,2)+Mid (TStamp,15,2)+Mid(TStamp,18,2)

Returns a Time in the format: 

     TStamp: 12/09/2016 10:13:07     

     TStampParse: 101307

I hope this helps get you started in the right direction.

Best, Dana


mb Mar 8, 2017 09:01 AM

Hello,

can you please detail how to code the renaming of the last file created by 

CallTable logData

Would you write something like:

...
CallTable logData
TStamp=Public.Timestamp(1,1)
TStampParse=Mid (TStamp,12,2)+Mid (TStamp,15,2)+Mid(TStamp,18,2)
FileRename(???, "USB:"&TStampParse)

How can I call the last file created?

Thanks!

Log in or register to post/reply in the forum.