DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling A Single Value From A Channel To Output To A Table Need Help

Solved!
Go to solution

I have populated a table that contains every value in every channel of my data set. I am now attempting to do channel calculations in order to come up with weighted averages and an overall average for the days worth of test. This data will be outputted to a new table called 'Total Table'. This Total Table is to only have one value per channel.

 

The issue I am running into is 2-fold. When doing channel arithmetic, primarily Channel Sums using 'ChnSum' DIAdem does not truncate the entire data set into a new data set. It retains all the values and appends the last block with the sum of the entire channel set. I need to either be able to pull that last value dynamically (as not all my data sets are of equal length) or I need to generate a new channel that only has the sum value. Is there a way to do this?

 

Here is what I have been attempting to do but to little avail. Attached is a screenshot of what the table output looks like after this code is processed.

 

'Populate Total Table With Values From Above Calculations

 

For j = 1 to selectData.MultiSelection.Count

Counter = Counter + 1

length = ChnPropValGet("[" & selectData.MultiSelection(j).Index & "]/Cumulative Fuel Used", "Length")

    If Counter = 2 Then

  

   [ A Bunch Of Channel Calculations That Output New Channels ]

 

   Call View.Sheets("Total Table").Areas("Area : " & Counter).DisplayObj.Columns.Add(ChnFind("Ch("& selectData.MultiSelection(j).Index &") > 0 " , length - 1))

  End If

Next

 

Any help would be much appreciated.

 

Thanks,

 

~Nate

0 Kudos
Message 1 of 15
(5,829 Views)

In addition to this i've noticed theres a funciton called ArrayToChannel. If there is some way to take a channel and convert it to an array it would make my scripting a million times easier. Is there a solution to this?

0 Kudos
Message 2 of 15
(5,827 Views)

Call View.Sheets("Total Table").Areas("Area : " & Counter).DisplayObj.Columns.Add(ChnFind("Ch("& selectData.MultiSelection(j).Index & "/**bleep** Fuel Used) > 0", length))

 

Forgot the channel designation in the call line. I am now getting an error on this line stating: Expected ')'

 

I am not sure what that means or where the close parenthesis is expected the error message is not specific.

 

Thanks,

 

~Nate

0 Kudos
Message 3 of 15
(5,825 Views)

Hi Nate -

 

I may not be understanding you correctly, but for the sake of clarification, ChnSum() isn't really retaining all a channel's values and simply appending the sum of the channel to the end of the channel; it's more like a running summation where at index N of the resultant calculated channel, the value at index N is the sum of the values in the input channel up until index N, inclusive.  For example:

 

Sum.png

 

Now, this means that you're spot on that the "single value" it seems you're looking for - representing the input channel's overall sum - is always located in the last value of the reusltant channel, as indicated in the help.

 

Since your input channel lengths vary, just index the resultant channel by its own length to always ensure you're extracting the last value from the channel, no matter what its length may be.  Since the Data object is (by nature) OO, you can merely index the Values() property of the resultant channel, which functions like the "array of channel values" you're looking for:

 

' Example code assumes that the "Sum" channel exists in the first Channel Group
Call ChnSum(1, "[1]/Sum") ' Notice: Parameters can be Channel Index, Channel Name, or Channel Reference
MsgBox("Sum is: " & Data.GetChannel("[1]/Sum").Values(Data.GetChannel("[1]/Sum").Size))

As for the missing parenthesis error you're now receiving, at a quick glance it seems your error is a missing close-parenthesis in the string input you're building for the ChnFind() function. 

 

Note that since it seems you're trying to reference the "**bleep** Fuel Used" channel by the index of its channel group (using selectData.MultiSelection(j).Index), you'll need to use open and close square-brackets. Check out this help document for more information on referencing Channels.

 

........ChnFind("Ch(""[" & selectData.MultiSelection(j).Index & "]/**bleep** Fuel Used"") > 0", length))

 

Derrick S.
Product Manager
NI DIAdem
National Instruments
0 Kudos
Message 4 of 15
(5,800 Views)

Hi Nate,

 

I'm not sure if I understand what you're doing either, but it looks to me like a main source of trouble is that you are using the return of the ChnFind() function in the View.Sheet.Area.Columns.Add() method.  The ChnFind() function will return a row number from a particular channel.  The Columns.Add() method expects a reference to a single channel in the Data Portal, usually a string channel path of the form "GroupName/ChannelName".  If you pass the ChnFind() return value value of, say, 5-- this means add a column to your report which points to the 5th channel down in your Data Portal.  I doubt that's what you want.  If it is what you want, you should at least break those commands apart to aid in debugging.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 5 of 15
(5,780 Views)

Thanks Derrick and Brad for the quick responses,

 

Brad you are correct I am not trying to pull in the entire column for populating the table. The Cumulative Fuel Used channel has the total fuel used for the entire test populated in the last data cell. I am trying to pull that last value into the new table for summary purposes so we will not have to go searching for that specific data block manually. This methodology will extend into my other calculations also. I need to do some weighted averages of the other channels and those will succumb to a final ChnSum which will leave me with the same prediciment as the Cumulative Fuel Used (specifically I will need to pull the final value from the respective channels to populate the table). I think Derrick's methodology should work I just need to sit down and play with it some more. I've had to put off coding for the last 2 days due to some other priorities. Hopefully, I will have some time over the weekend to tinker some more. I'll keep you guys posted.

 

Thanks Again,

 

~Nate

0 Kudos
Message 6 of 15
(5,777 Views)

With a little further investigation, I believe you're correct Brad. I need to stay away from the ChnFind as Im not trying to return a row value. Is there a way to pull out just one value from a specific channel? And how can I reference that specific value dynamically based on channel length? The value I am trying to pull will always be the final value in the data channel.

 

Thanks,

 

~Nathan

0 Kudos
Message 7 of 15
(5,752 Views)

This is my latest version of the code and it sort of works but its referencing my "Fan Speed" channel for some reason rather than my "Cumulative Fuel Used" channel. Im a little stumped

 

 

For j = 1 to selectData.MultiSelection.Count

Counter = Counter + 1

 

length = ChnPropValGet("[" & selectData.MultiSelection(j).Index & "]/**bleep** Fuel Used", "length")

 

If Counter = 2 Then

 

Call View.Sheets("Total Table").Areas("Area : " & Counter).DisplayObj.Columns.Add(Data.Root.ChannelGroups("[" & selectData.MultiSelection(j).Index & "]").Channels("**bleep** Fuel Used").Values(length))

 

End If

 

Thanks,

 

~Nate

0 Kudos
Message 8 of 15
(5,750 Views)

Ok so it's referencing my "Fan Speed" channel because the final value in the "Cumulative Fuel Used" channel is 60. Ironically, my "Fan Speed" channel index is also 60. This means my methodology is flawed for pulling in the final data value so once again I am stumped.

 

Any help would be much appreciated.

 

Thanks,

 

~Nate

 

Sorry for the continuous posts.

0 Kudos
Message 9 of 15
(5,748 Views)

Hi Nate,

 

I still think you're tripping yourself up with large nested commands.  Also, if you've already got the Group or Channel object, you don't need to use the ChnPropValGet() command to read off the Channel property.  This is what I think you want your code to do:

 

ChanName = "**bleep** Fuel Used"
Set Selection = Portal.Structure.Selection
For j = 1 to Selection.Count
  If Selection(j).IsKindOf(eDataChannelGroup) THEN
    IF Selection(j).Channels.Exists(ChanName) THEN
      Counter = Counter + 1
      Set Channel = Selection(j).Channels(ChanName)
      Length = Channel.Properties("Length").Value
      If Counter = 2 Then
        Set Area = View.Sheets("Total Table").Areas("Area : " & Counter)
        Call Area.DisplayObj.Columns.Add(Length)
      End If
    End If
  End If
Next
Call WndShow("VIEW")

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 10 of 15
(5,739 Views)