DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get precise value of `wf_start_time` in Python script?

Solved!
Go to solution

Under the Data Portal, my channel has a precise timestamp. Extended Properties > Waveform > Waveform x-start time shows "11/16/2020 15:01:08.558525521"

 

How do I get get this value or its components in Python? This is what I tried, but it loses precision:

 

t0 = ch.Properties['wf_start_time'].Value

dd.MsgBoxDisp(t0.hour) # Shows '15' -- Correct
dd.MsgBoxDisp(t0.minute) # Shows '1' -- Correct
dd.MsgBoxDisp(t0.second) # Shows '9' -- WRONG
dd.MsgBoxDisp(t0.microsecond) # Shows '0' -- WRONG
dd.MsgBoxDisp(str(t0.resolution)) # Shows '0:00:00.000001' -- Inconsistent?
Certified LabVIEW Developer
0 Kudos
Message 1 of 4
(1,801 Views)
Solution
Accepted by topic author JKSH

Hi JKSH,

 

You were really close.  There is a datetime object in DIAdem that has most of those properties, but you have to explicitly request the "OValue" property instead of the "Value" property in order to return that object and not return the usual variant of subtype date.  This is NOT a python datetime object, and it knows nothing about a t0.resolution property, but the other property reads work correctly for me with that one change:

 

t0 = ch.Properties['wf_start_time'].OValue

 

Brad Turpin

Principal Technical Support Engineer

National Instruments

Message 2 of 4
(1,754 Views)

Thanks Brad, that worked!

 

From your hint, I was able to find some documentation about getting date/time values via "OValue": https://zone.ni.com/reference/en-XX/help/370858P-01/inavidata/properties/diacmpnt_property_value_idi...

 

The "Property" object documentation doesn't mention "OValue" though: https://zone.ni.com/reference/en-XX/help/370858P-01/inavidata/objects/diacmpnt_objects_idiademproper...

 

Where else should we use "OValue"? Does it make sense to replace all instances of "Value" with "OValue", even for other datatypes? (I'm thinking of this for code consistency, rather than using "Value" for some items but "OValue" for others)

Certified LabVIEW Developer
0 Kudos
Message 3 of 4
(1,742 Views)

Hi JKSH,

 

No, the reason the OValue property is missing from the documentation is that it's only appropriate for datetime properties, which are the only properties that can be returned as a variant or an object.  All other properties are returned only as a variant with the Value request.  Unlike python, DIAdem does not consider all variables objects.  In VBScript, all variables are variants, and only some variants are of subtype object.  But the variant of subtype date doesn't have enough resolution (it's based loosely on Excel's datetime), so in that one situation the OValue request works to return the DIAdem datetime object (which is how it's actually stored in memory).

 

Brad Turpin

Principal Technical Support Engineer

NI

Message 4 of 4
(1,726 Views)