11-30-2020 05:06 PM
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?
Solved! Go to Solution.
12-02-2020 04:35 PM - edited 12-02-2020 04:36 PM
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
12-02-2020 09:54 PM
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)
12-03-2020 04:45 PM
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