DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Determining time at a given channel value

Solved!
Go to solution
Highlighted

I'm new to DIAdem so I apologize if this is a stupid question.

 

I am collecting TDMS data from a test stand, with each "cycle" being a different group. I need to determine the amount of time a channel stays within range (actually two ranges, one high and one low) for each group. I need to do this automatically as there are hundreds of thousands of cycles that this operation needs to be performed on. There are a couple more operations I need to do, but they are simple enough that I think I can figure them out if I can get this one done. Anyone have any examples/advice? A sample of my data is attached if that helps...

 

Thanks in advance

0 Kudos
Message 1 of 5
(790 Views)

Since DIAdem 2017 there is the Event find methods.

 

ANALYSIS->Channel Functions->Event Search (Free Formula)

 

You can play with the dialog.

If you found the requested result press Ctrl+Shift+C which will fill the script code needed to clipboard. Now you can create a script based on your needs.

 

Option Explicit

dim result : result = ChnEventFind("A > 40", Array("A"), Array(Data.GetChannel("[1]/Speed")))
Call ChnEventCreateFilteredTrueChn("[1]/EventStatus", result, "[1]/Speed", 0)

 

0 Kudos
Message 2 of 5
(765 Views)

so... that's not actually the data I was trying to upload. I'll try again...

I thought I almost had it figured out using a windowed event search, but I need to know the longest consecutive time that it stays within the range, as in if it leaves the range and comes back in I would need to account for that

0 Kudos
Message 3 of 5
(741 Views)

There is an example

"Searching for Events in Channels"

that might help to show how the event search result can be used in script.

 

P.S.: The data file always must be tdm + tdx file. To attach an example file you have to zip them.

 

0 Kudos
Message 4 of 5
(732 Views)
Solution
Accepted by topic author kmdewey
09-15-2017 01:53 AM

I'm going to share the solution I found, not sure if it's correct but hopefully it helps someone out...

 

 

Code is bellow. Basically, do a window event detection, store as a event list, check if there is anything in the list, and take the longest duration event. Store that duration as a property of the group (aka cycle) along with all other important numbers (mins/maxs, pass/fail, etc)

 

Other things I found useful... ChnCharacterAll() calulates the characteristics of all channels, you can dynamically call groups and channels by replacing the normal "[1]/[2]" with "["&str(i)&"]/Channel_Name" so you can index through loops. You can write to group properties via Call Data.Root.ChannelGroups(n).Properties.Add("Pass", PSS). Saving the data as an ExcelTDMS allows you to open the file quickly and gives you all the info you saved for every group on one page in consecutive rows

 

'-Initialize channels and get cycle count
ChnCharacterAll()
nMax = CLng(Data.Root.ChannelGroups.Count) 
FOR n = 1 TO nMax   'Iterate over every group

'-High Pressure  
  ChnEventList1 = ChnEventDetectionWindow("["&str(n)&"]/Timestamp", "["&str(n)&"]/PT-102", MinHP, MaxHP)
  If ChnEventCount(ChnEventList1) > 0 then    'Determine high pressure dwell
    HPD = ChnEventDuration(ChnEventList1,1)
    If ChnEventCount(ChnEventList1) > 1 then    'find max hpd if multiple
    lMax = ChnEventCount(ChnEventList1)
      For m = 2 TO mMax
        If ChnEventDuration(ChnEventList1,m) > HPD then
          HPD = ChnEventDuration(ChnEventList1,m)
        End If
      Next 'm
    End If  'max hpd
  Else
    HPD = 0
  End If    'hpd

'-Store data as group properties
  
  Call Data.Root.ChannelGroups(n).Properties.Add("HP_Dwell_Time", HPD)

 

Message 5 of 5
(669 Views)