DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Use of CreateTime - missing millseconds .....

Hi Brad,

Thanks to you and Andreas, I am able to have my time data in a time channel.  My problems start when I want to use that data.  I find that I cannot just read milliseconds or smaller like with a property.  This script works for me: -

Dim oTime

dim TimeObj

Set TimeObj = CreateTime(2004,6,17,10,20,30,900,500,9)

Data.Root.Properties.Add "Hope", TimeObj

Call MsgBoxDisp("Microsecond: " & TimeObj.year)

Set oTime = Data.Root.Properties("Hope").oValue

call MsgBox(oTime.nanosecond)

but I cannot get an 'equivalent' script that allows me to read values from a channel.  For example, this script returns a false value for milliseconds:-

data.Root.Clear

dim chTime

set chTime = data.root.ChannelGroups.Add("group").Channels.Add("Time",DataTypeChnDate)

chTime.Values(1) = createTime(2017,6,6,10,23,45,800)

MsgBox chTime.oValues(1).Millisecond

It returns 500 for any input (in CreateTime) > 500...

 

I would like to be able to use Time channels just like I do numeric or text channels, but I can't even read and write values.  I am missing something fundamental in my understanding about how it should work, but I don't know what.  Why for instance, do I get a value of 500 instead of 800 ms for the script above?

 

Again, Thanks for the help and patience,

Thomas

 

 

 

 

 

 

0 Kudos
Message 11 of 14
(768 Views)

Because DIAdem Time channel is internally represented by a double I would create seperate channels for

milli and nanoseconds. The resolution of a time channel is reached at this point.

 

An alternative is storing the start time in a property and using a float64 channel storing the offset to the start time.

 

I am sorry but there is no easy solution at the moment if you need high precission.

0 Kudos
Message 12 of 14
(753 Views)

Hi Thomas,

 

When I copy and paste your 5 line script into my DIAdems, here are the results I get:

DIAdem 2015 SP2 32bit .... returns 500

DIAdem 2015 SP2 64bit .... returns 800

DIAdem 2017 SP2 64bit .... returns 800

 

This suggests to me that there is a bug in DIAdem 2015 32bit.  Do you have the option of installing the 64bit version instead?

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 13 of 14
(742 Views)

I tested with DIAdem 2010 32bit and I could reproduce the behavior you describe.

It is fixed in all newer versions.

However if you can not upgrade there is a workaround

Option Explicit

data.Root.Clear

dim chTime 

dim timeVal : set timeVal = createTime(2017,6,6,10,23,45,800,600)
set chTime = data.root.ChannelGroups.Add("group").Channels.Add("Time",DataTypeChnDate)
chTime.Values(1) = timeVal

' call woraround method
dim millisecond, Microsecond
call GetTimeFraction(chTime.Values(1), millisecond, Microsecond)


MsgBox millisecond & " - " & Microsecond & VBCRLF &_
       chTime.oValues(1).millisecond & " - " & chTime.oValues(1).Microsecond




sub GetTimeFraction(byVal timeVal, byref milliSecond, byRef Microsecond)

  ' does not work in DIAdem 2012
  'milliSecond = diaChn.oValues(index).millisecond
  'Microsecond = diaChn.oValues(index).Nanosecond

  ' workaround using R1 double value with direct double access
  R1 = timeVal
  dim fraction : fraction = R1 - fix(R1)
  fraction = fraction * 1000 
  milliSecond = fix(fraction) ' fix part of double contains milliseconds
  fraction = fraction - milliSecond ' remove fix part
  fraction = fraction * 1000 ' now fix part contains mi
  Microsecond = fix(fraction) 
  
end Sub

using an explicit cast of the channel value to 'R1' which is a build in variable.

GetTimeFraction

just makes use of this and calculates the fractions by double arithmetic.

P.S.: This will also work in future DIAdem version. So a script including it will not break on upgrade

0 Kudos
Message 14 of 14
(724 Views)