cancel
Showing results for
Did you mean:

Solved!
Go to solution
Highlighted

## Determining time at a given channel value

I have a simple DIAdem script question.  I have a dataset with two channels: 1.) Time and 2.) Switch_1.  "Switch_1" has boolean values (0 or 1... off or on).  Throughout the file, the "Switch_1" changes from 0 to 1 many times.  I want to wrtie a script to determine the time period that "Switch_1" is equal to 1.  Can anyone help me do this?

Message 1 of 7
(3,153 Views)

## Re: Determining time at a given channel value

Hi Dan,

If I had a sample of your data, I could send you a more functional script, but here are the main components I'd recommend:

1) Create a "Delta Time" channel that shows the time elapsed between each point, using the ChnDeltaCalc() command

2) Set to zero all values in the "Delta Time" channel where the "Switch_1" channel = 0, using the Calculate() command

3) Return the sum of all the values in the edited "Delta Time" channel, using the CCh(Channel, 4) command

National Instruments

Message 2 of 7
(3,127 Views)

## Re: Determining time at a given channel value

Attached is an example of some data that I am working with.  Can you help me with a more functional script?

-Dan

Message 3 of 7
(3,048 Views)
Solution
Accepted by topic author Dan_TestENGR
08-27-2015 04:09 PM

## Re: Determining time at a given channel value

Hi Dan,

Sorry for the delay.  Please put the two attached scripts in the same folder somewhere, then run the "Count State Duration.VBS" in the DIAdem SCRIPT panel.  It will pop up a file dialog-- select the TDMS file you sent me.  It loads the file, calculates the delta times, splits the values by switch state into a "0" group and a "1" group, then calculates the sum of all the delta times for each group.  You can find the result in each group's "Description" property and each "Duration" channel's "Description" property.

National Instruments

Message 4 of 7
(2,986 Views)

## Re: Determining time at a given channel value

I am interested in a similar calculation, but with a few variations.  I am interested in determining the delta time from when “Aliases\OUTPUTS\CHOPPER_ENGAGE” [turquoise waveform] switches from 1 to 0 [BLACK arrow] and “[2]/Targets\cRIO9081-150HP\Hardware\Chassis\NI-XNET\CAN\AF9230\Incoming\Single-Point\UCM1_STATUS10 (419389568)\SpreaderSpeed” [violet waveform] reaches 0 [RED arrow].

The performed operation occurs in 3000 cycles so I would like this analyzed for each cycle.

What would be most helpful is a table with the following columns that I could analyze in Excel:

• Column 1:  [1]/Targets\cRIO9081-150HP\User Channels\Counters\CycleCounter_Ctr
• Column 2:  System or Absolute Time when CHOPPER_ENGAGE switches from 1 to 0
• Column 3:  System or Absolute Time when SpreaderSpeed reaches 0

We started and stopped the test a few times so I have approximately [10] files to analyze but I can copy the table output to Excel each time I perform the calculation.

Can you please point me in the right direction for this analysis?

Thank you very much.

Message 5 of 7
(266 Views)

## Re: Determining time at a given channel value

I am interested in a similar calculation, but with a few variations.  I am interested in determining the delta time from when “Aliases\OUTPUTS\CHOPPER_ENGAGE” [turquoise waveform] switches from 1 to 0 [BLACK arrow] and “[2]/Targets\cRIO9081-150HP\Hardware\Chassis\NI-XNET\CAN\AF9230\Incoming\Single-Point\UCM1_STATUS10 (419389568)\SpreaderSpeed” [violet waveform] reaches 0 [RED arrow].

The performed operation occurs in 3000 cycles so I would like this analyzed for each cycle.

What would be most helpful is a table with the following columns that I could analyze in Excel:

• Column 1:  [1]/Targets\cRIO9081-150HP\User Channels\Counters\CycleCounter_Ctr
• Column 2:  System or Absolute Time when CHOPPER_ENGAGE switches from 1 to 0
• Column 3:  System or Absolute Time when SpreaderSpeed reaches 0

We started and stopped the test a few times so I have approximately [10] files to analyze but I can copy the table output to Excel each time I perform the calculation.

Can you please point me in the right direction as to how to analyze this?

Thank you very much.

Message 6 of 7
(266 Views)

## Re: Determining time at a given channel value

Hi ATarman,

First I would recommend making a new post as this one already has a solution marked, this will lead to higher visibility!

As a good place to start:

1.  Create a "Delta Time" channel that shows the time elapsed between each point, using the ChnDeltaCalc() command
2. Some initial thoughts that I had were to utilize something like this function to determine when the value goes to 1 or zero:
1. Then you can use the difference between where the points hit zero and one to calculate dt

It sounds like this will be similar to what was done on this post which may provide some insight: https://forums.ni.com/t5/DIAdem/Formula-for-finding-channel-value/td-p/1234321

Message 7 of 7
(248 Views)