From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
06-21-2017 02:11 PM
I have a data structure like
[1]/DateTime
[2]/AlarmTime
I would like to determine location (row index) of each timestamp of [2]/AlarmTime in [1]/DateTime. My code is like:
Alarm_Start_Time = Data.Root.ChannelGroups(2).Channels("AlarmTime").GetValuesBlock
AlarmTime = Alarm_Start_Time(1)
ind = ChnFind("Ch(""[1]/DateTime"") >= AlarmTime", 1)
The process seems never end unless I manually hit ESC button.
I have checked type of AlarmTime and it showed "Date".
I also tried:
AlarmTime = CDbl(Alarm_Start_Time(1))
but it does not work.
Do I miss something?
Thank you
Solved! Go to Solution.
06-22-2017 03:28 AM - edited 06-22-2017 03:29 AM
Hi,
You have to make sure that your DateTime channel really has values bigger than the current AlarmTime.
Also is AlarmTime a global or script local variable in your example? It has to be global to use its name directly in the equation like you did (use globaldim("AlarmTime") command for that).
You can simplify your code a little bit like this without using a global variable:
dim AlarmTime, ind AlarmTime = Data.Root.ChannelGroups(2).Channels("AlarmTime").Values(1) ind = ChnFind("Ch(""[1]/DateTime"") >= " & AlarmTime, 1)
Or use another approach like this (using the attached data file):
dim i, AlarmTimeChn, sFormula, aSymbol, aValues(1) set AlarmTimeChn = Data.GetChannel("[1]/AlarmTime") sFormula = "A >= B" aSymbol = Array("A", "B") Set aValues(0) = Data.GetChannel("[1]/DateTime") for i=1 to AlarmTimeChn.Size aValues(1) = AlarmTimeChn(i) Call LogfileWrite(ChnFind(sFormula,,aSymbol, aValues)) next
Regards
06-22-2017 08:22 AM
Hello Christian,
AlarmTime is not a global variable. I create Alarm_Start_Time array GetValuesBlock. AlarmTime stores individual data of Alarm_Start_Time as:
Alarm_Start_Time = Data.Root.ChannelGroups(2).Channels("AlarmTime").GetValuesBlock AlarmTime = Alarm_Start_Time(1)
Actually, I use a For loop to go through all values of Alarm_Start_Time array. The reason I have to use an additional AlarmTime variable is that I am not sure if the index works for the condition string of ChnFind as:
ind = ChnFind("Ch(""[1]/DateTime"") >= Alarm_Start_Time(1)", 1)
However using AlarmTime does not work either.
I actually have solved this issue by instead of using ChnFind, I load DateTime and AlarmTime channels into variables by GetValuesBlock and use "if " to find index of individual values of AlarmTime array in DateTime array. Data in AlarmTime and DateTime is in the format "mm/dd/yyyy hh:mm:ss".
This is not convenient; but because finding index directly on Channel does not work, this is just a workaround solution. I still want to try a more direct channel handling method.
06-22-2017 08:22 AM
Hello Christian,
AlarmTime is not a global variable. I create Alarm_Start_Time array GetValuesBlock. AlarmTime stores individual data of Alarm_Start_Time as:
Alarm_Start_Time = Data.Root.ChannelGroups(2).Channels("AlarmTime").GetValuesBlock AlarmTime = Alarm_Start_Time(1)
Actually, I use a For loop to go through all values of Alarm_Start_Time array. The reason I have to use an additional AlarmTime variable is that I am not sure if the index works for the condition string of ChnFind as:
ind = ChnFind("Ch(""[1]/DateTime"") >= Alarm_Start_Time(1)", 1)
However using AlarmTime does not work either.
I actually have solved this issue by instead of using ChnFind, I load DateTime and AlarmTime channels into variables by GetValuesBlock and use "if " to find index of individual values of AlarmTime array in DateTime array. Data in AlarmTime and DateTime is in the format "mm/dd/yyyy hh:mm:ss".
This is not convenient; but because finding index directly on Channel does not work, this is just a workaround solution. I still want to try a more direct channel handling method.
06-22-2017 08:40 AM
Hi,
Like shown in my example before, you don't necessarily need GetValuesBlock as you can directly access channel data with the Values property.
Also in your example you are using AlarmStartTime(1) in the equation string which only works if AlarmStartTime is a global array variable.
I recommend to use it outside the equation string and concatenate equation and resolved Start Time string like this:
dim i, ind, AlarmTimeChn set AlarmTimeChn = Data.Root.ChannelGroups(2).Channels("AlarmTime") for i=1 to AlarmTimeChn.Size ind = ChnFind("Ch(""[1]/DateTime"") >= " & AlarmTimeChn.Values(i), 1) call LogfileWrite(ind) next
06-22-2017 09:16 AM
Thank you for your suggestion. I have changed to use GetChannel.Values instead of GetValuesBlock; other loop and if components are kept the same. The code works perfectly now.
I guess when I read channel data into array variables and do comparison and ChnFind between timestamp variables and TimeStamp Channel, conversion of timestamp values become undesired and unexpected.
This issue is solved now.