03-09-2014 11:34 AM
Hello Together,
I am new to Diadem and VBS and have a question regarding changing the data types. I am reading data from a CSV-file. So far its working good, but I am not able to get the time right.
The input file is in this format:
T, 1380723715680 '1380723715680 = Start time in ms (Computer Time) H, Name1, Name2, Name3 ' First column time in ms after the Start Time H, REAL, REAL, REAL 0, 0, 0, 0 ' First data line 200, 20, 50, 100 ' second data line 200 ms after the first one
I can read out and convert the start time by:
File.SkipValue() 'Skip "T," TimestampMS = File.GetNextStringValue(eString) StartTimeDate = DateAdd("s", TimestampMS / 1000, "01/01/1970 00:00:00")
This gives me the right time and date information. In this example 02.10.2013 14:21:55 I can also easyly setandreadoutthechannelinformationandcontainingdata.
But I don't manage to get the time information in a way of Offset + ms value and convert it to Time and Date information. I only manage to sum up the ms value with the offset as an eR64 value. How can I convert this than to eTime?
Any help or better idea?
03-10-2014 09:12 AM
Hi BenniL,
I don't exactly get, what you are doing.
There is a vbs function "createTime" which returns a Time Object.
Does this helps?
Kind Regards,
Philipp K.
AE | NI Germany
03-11-2014 12:20 PM
Hi BenniL,
The VBScript datetime functions only work down to the second level. Try instead the DataPlugin command:
Set DateTime = File.Formatter.ParseString(StringVariable, eTime)
DateTime.Millisecond = TimestampMS
Brad Turpin
DIAdem Product Support Engineer
National Instruments
03-12-2014 04:13 AM
Thanks for the replies!
Unfortunately I don't understand the answers or get anything working by trial and error. Maybe I try it again with minimal input file to clarify my goal. I guess my question is just too simple.
With this as the input file
1314117549640 'Start time in ms Timer, MeasuredValue 'Description of the measured values 0,11 'Data Line 1 200,22 'Data Line 2 400,35 '... 600,65 '...
Sub ReadStore(File) 'Dateiformatierung File.Formatter.LineFeeds = vbLf File.Formatter.IgnoreEmptyLines = true File.Formatter.TrimCharacters = " " File.Formatter.Delimiters = "," File.Formatter.DecimalPoint = "." '1314117549640 Dim StartTimeMs, StartTimeDate StartTimeMs = File.GetNextStringValue(eString) StartTimeDate = DateAdd("s", StartTimeMs / 1000, "01/01/1970 00:00:00") Call Root.Properties.Add("Start of Measurement", StartTimeDate) Call File.SkipLine() 'Create group with file name as description Dim Gruppe : Set Gruppe = Root.ChannelGroups.Add(File.Info.FileName) Dim Block : Set Block = File.GetStringBlock() 'Time, MeasuredValue Dim Kanalname, Kanal Set Kanal = Block.Channels.Add("Datum und Zeit", eR64) Kanal.Offset = StartTimeMs 'Works even StartTime is a String. Why? Gruppe.Channels.AddDirectAccessChannel(Kanal) Kanalname = File.GetNextStringValue(eString) Set Kanal = Block.Channels.Add(Kanalname,eR64) Call Kanal.Properties.Add("unit_string","%") Gruppe.Channels.AddDirectAccessChannel(Kanal) Call File.SkipLine() 'Ab hier die Daten Block.Position = File.Position End Sub
And this as the DataPlugin I get two channels with the results as I expect.
How can I now change the first channel to eTime and represent it in Minutes, hours, seconds, milliseconds or whatevere?
Any help or recommendations?
03-15-2014 09:23 AM
Hi BenniL,
Your file snippet shows a first line where the start time = 1314117549640 ms. What is the reference date-- since 1900, or 1904 or 1970? Is the first channel in your data file always the relative time? Is the first channel also measured in ms?
There is a trick in the DataPlugin API to turn a numeric channel into a DateTime channel, but we have to get the numbers of seconds to be relative to 0 AD first. Luckily there's a Channel.Offset property we can use.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
04-09-2014 07:24 AM
Hello Brad,
thank your for your response and sorry for my late answer. The start time is 01.01.1970 0:0:0 as indicated in my first post.
How can I change the formats of the channels?
Regards,
Benjamin
04-10-2014 12:24 PM
Hi Benjamin,
I'm sorry, I should have seen in your first post that you're referencing the standard Fortran time zero from 1970. DIAdem uses instead 0 AD, so we need to add the number of seconds between 0 AD and 1970. Plus, you need to add a property to tell DIAdem to interpret this numeric value as the number of seconds since 0 AD.
Kanal.Offset = 62167132800 + StartTimeMs
Kanal.Properties.Add "displaytype", "Time"
Brad Turpin
DIAdem Product Support Engineer
National Instruments
04-11-2014 12:47 AM
Hello Brad,
this was very helpful! I would have never gotten to the line
Kanal.Properties.Add "displaytype", "Time"
by myself.
I am still stuck on the way of adding ms (milliseconds) to the Time format. The values from the file I am reading are in ms. Is there even a way to go downt to ms in the Time format, or is this limited to s (seconds)?
04-11-2014 09:42 AM
Hi Benjamin,
The numeric channel can contain fractional second values. If the value in the StartTimeMS variable is in milliseconds, then you need to divide it by 1000 to convert it to seconds before adding it to the recorded values.
Kanal.Offset = 62167132800 + StartTimeMs/1000 Kanal.Properties.Add "displaytype", "Time"
Brad Turpin
DIAdem Product Support Engineer
National Instruments
04-14-2014 01:39 AM
Full ACK for that, but this only works for the offset. How do I tell Diadem, that each value, that is read is in ms? One possiblity would be to change the values afterwards, but the Values Attribute is read only.