From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using external timestamp for write to measurement file

Solved!
Go to solution

Hi,

 

Im having an issue with the Write to measurment file .vi  .. 

 

My data comes into this machine via a network stream.  About every 5 seconds it arrives and is processed.  See. attached .vi.

 

I want to use the first element of my array (Epoch time, 1/1/1904) for the timestamp on each line of the data file in a Human readable format.

 

I think I have it set correctly but the actual timestamp is from the computer running this vi.  When I load the data in Excel, I make a column that calculates the date and time from the Epoch column and I can see the difference varying slightly over time.

 

Can I use the Write to measurement file for this?  Any help and/or suggestions are appreciated.

 

Thanks,

 

Dave

0 Kudos
Message 1 of 7
(4,869 Views)

I'm not sure I understand your question.  I believe that you can have Write to Measurement File write out a TimeStamp column when it writes data.  Are you saying you want the time when the remote PC acquires the data, as opposed to when the Host receives it via Network Streams (and writes it)?  If so, you can create a cluster in your Remote that includes both the Data Array (Data) and a TimeStamp which you set when you acquire the data (on the Remote).  Change the Network Stream to be a Stream of your Cluster instead of just your Data.

 

Bob Schor

0 Kudos
Message 2 of 7
(4,822 Views)

Bob,

 

The data that comes from the remote system has the time of acquisition as element 0 of the array. It is the epoch time (number of seconds since 1/1/1904).  I want to convert this to "readable time" and have it as the first column in my data file.

 

I was hoping that the write to measurement file would let me do this, rather, it writes it's own readable date and time but it is seconds different from when the data was acuatlly acquired.  I want it to use the epoch time in the data to derive the date and time stamp.

 

 

0 Kudos
Message 3 of 7
(4,799 Views)

@zener3 wrote:

 

The data that comes from the remote system has the time of acquisition as element 0 of the array. It is the epoch time (number of seconds since 1/1/1904).  I want to convert this to "readable time" and have it as the first column in my data file.

 

I was hoping that the write to measurement file would let me do this, rather, it writes it's own readable date and time but it is seconds different from when the data was acuatlly acquired.  I want it to use the epoch time in the data to derive the date and time stamp.

  


The key question is precisely what form is the "Epoch Time", and precisely what do you mean by "Readable Time".  Generally, LabVIEW TimeStamps represent the number of seconds after 1/1/1904 UTC.  If you have an actual LabVIEW TimeStamp, there are a number of ways to express this as a string, including (one of my favorites) Format Into String (on the String Palette) as well as functions on the Timing Palette.  On the other hand, if you actually have a Float representing "Seconds past 1/1/1904 UTC", you can convert this into a TimeStamp that will display "12:00:01 AM, 1/1/1904" with the following code:

Time Conversion.png

The first function makes it a TimeStamp, but it is in UTC (so the time will be wrong unless you live near Greenwich, England).  The back-to-back Seconds to Date/Time and Date/Time to Seconds is an easy way to handle UTC adjustment.

 

If you need something different and these aren't sufficient "clues", give more examples of "what you have" and "what you want".

 

Bob Schor 

0 Kudos
Message 4 of 7
(4,793 Views)

Bob, Thanks for the replies.

 

I know how to convert this to a timestamp and get a string out of it.  What I want to do is force the "Write to measurement file" function to use this time as its timestamp inside the file instead of the local computers time.

 

By readable time date I mean

5/1/2016 01:06:10

Instead of

3544909570

 

This way, someone opening the data file can see the time the data was acquired rather than having to do some math in Excel or Spotfire.

0 Kudos
Message 5 of 7
(4,788 Views)

I don't use Write to Measurement File, myself, but doesn't it allow you to put your own Time Entry (it may call it X Column) in?  You could, in principle, create a "Time Column" consisting of the Time Stamps from your device, converted to an appropriate String representation.  The easiest way to do the String conversion is to use the Format Date/Time String function.

Time Stamp to String.png

Bob Schor

0 Kudos
Message 6 of 7
(4,780 Views)
Solution
Accepted by topic author zener3

Hi zener3,

 

The fundamental problem is the format of the Excel file cells. By default they are formatted as numbers.

The simple LabVIEW functions that write to “xlsx” files don’t provide options to format cells.

 

You *could* use the Report Generator Toolkit (RGT) or ActiveX controls to format your Timestamp cells.

This would be the best way, but takes a little bit of programming (RGT is not difficult).

 

Or you could cheat.

 

 If all you care about is opening the file in Excel and seeing the correct times, you could save the file as a “.csv” type with a slight change to the timestamp string. If you add a leading space to the timestamp, Excel will treat it as a string instead of a number (picked up from a post by Hooovahh).

 

If you use the chart tools to look at the data, the X axis will display the “literal string” time stamps (not very well, actually). For X/Y charts - numbers are shown on the X axis.

 

This snippet (drag onto blank diagram to run) saves data that can be opened with Excel (Set save file before running):

 

csv for excel p_BD.png

steve

--------------------------------------------------------------------------------------------------------------------------
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
--------------------------------------------------------------------------------------------------------------------------
Message 7 of 7
(4,746 Views)