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.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

cannot search timestamp channel with chnfind

Solved!
Go to solution

We're trying to build a script that will cut up our data sets into days. At the moment we're building a function that uses ChnFind to locate the channel position of the first entry whose date is higher than midnight of each day, and use that to divide up the dates. However, we can't get the chnfind function to work.

 

Initially we tried searching for the date as a timestamp, but the chnfind seemed unable to process it - it kept saying it was expecting a ), but nothing seemed to be missing.

 

 

Ch("0R1R1W0FResults/hitsTimestamp")> 2016/03/18 00:00:00.0000

 

Is the evaluated result that's getting fed into the function (after double quotation marks are parsed), but it's throwing an error.

 

We then tried convert it using TTR for the comparison, but that threw a type mismatch.

Finally, we tried using instr to locate the first value which contained the correct date, but that also threw a type mismatch.

 

Is it possible to run these comparisons on a timestamp channel? If so, how?

0 Kudos
Message 1 of 5
(4,459 Views)

Hello PGribble,

 

The following script is working fine on my DIAdem 2015 SP1:

 

Data.Root.Clear
Call ChnGenTime("/Time","hour",now,,1,"StartStepNo",100)
msgbox chnFind("ch(""/Time"") >= "  & TTR("27.04.2016 20:00:00"))

Greetings

Walter

0 Kudos
Message 2 of 5
(4,443 Views)

Hi Walter,

 

We've used similar commands in other scripts, and they've worked fine. I think it's something to do with the fact we're passing it variables to construct the channel names, or something...

 

 argument = "Ch(""" & group & "/" & x & """)> " & TTR(i) & ""


 datepointer(x) = (chnFind(argument,0))

 

That's what we're actually using - the string I posted before is the value of argument we're taking in. It throws an error saying there's a type mismatch - presumably because we're comparing a timestamp to a number - but if we try it without the TTR, it can't parse the string, presumably because it has spaces in it...

0 Kudos
Message 3 of 5
(4,353 Views)

A little further research:

 

We've removed all the variables, and reduced it to a single, hardcoded expression, including making a new copy of the channel that's in number format rather than timestamp format.

 

datepointer(x) =  chnfind("ch(""0R1R5W0FResults/hitsTimestamp1"")>= 63625392000")

 

This is still throwing a type mismatch, but it works perfectly in calculator. Any idea why it would be working there but not in a script?

0 Kudos
Message 4 of 5
(4,347 Views)
Solution
Accepted by topic author PGribble

It turns out we were accessing our array incorrectly, so the system is working fine now.

0 Kudos
Message 5 of 5
(4,323 Views)