DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamical Channel Selection

Solved!
Go to solution

Hi people,

 

I use DIAdem 2011. I have a question on channel selection. I am calculating the mean of channels using the function "Call ChnAverage("'temp1'-'temp3'","mean")" and the input-list varies which means "temp3" could be "temp4" or "temp5". So I want to control the last input with a variable like tempi. But in "" DIAdem doesn´t recognize "i" as an integer but a part of string "tempi". Does anyone have idees to manage this problem? Thanks a lot!

 

Andi

0 Kudos
Message 1 of 6
(5,698 Views)

Hi Andi,

 

To answer your question, the correct syntax is:

 

Dim oMyAverGroup, i
i = 3
Call ChnAverage("'[4]/Temperature_1'-'[4]/Temperature_" & str(i) & "'","mean")

 

But I would prefer the Data-API. With that you create an object which contains all the channels you would like to be calculated. Then you have several options to collect these channels like:

 

Dim oMyAverGroup, i
set oMyAverGroup = Data.CreateElementList

' Option 1 - adding several channels
call oMyAverGroup.Add(Data.GetChannel("[4]/Temperature_1"))
call oMyAverGroup.Add(Data.GetChannel("[4]/Temperature_2"))
call oMyAverGroup.Add(Data.GetChannel("[4]/Temperature_3"))

' Option 2 - a wildcard (joker)
set oMyAverGroup = Data.GetChannels("[4]/Temperature_*")

' Option 3 - a loop 
for i = 1 to 3
  call oMyAverGroup.Add(Data.GetChannel("[4]/Temperature_" & str(i)))
next

' run calculation
Call ChnAverage(oMyAverGroup, "mean")

 

Greetings

Walter

0 Kudos
Message 2 of 6
(5,693 Views)
Solution
Accepted by topic author A._Baumann

Thank you very much Walter. The ideas are brilliant

0 Kudos
Message 3 of 6
(5,680 Views)

I try to run the example but I'm graced with an error message "non permitted Channel names ??? in ChnAverage(???,"Mean"). Either of the 3 ways to add elements to the list 😞

 

simple check via

For Each oMyChn inoMyAverGroup

 

CallMsgBoxDisp(oMyChn.Name)

 

Next

 

shows that the names have been correctly added to the list. But ChnAverage (or other functions) do not work

 

Why would that be? Is it DIAdem2011 at fault?

Thanx for assistance

Michael

0 Kudos
Message 4 of 6
(5,524 Views)

Hi Michael,

 

It looks to me like DIAdem found no channels with the right name in the Data Portal and you are trying to loop over an empty collection.  The For Each construct unfortunately executes even if there aren't any elements in the stated collection.  Try "MsgBox oMyAverGroup.Count" before the loop.

 

Another possibility is that some of the channels you added might be string/text channels, which will not work in that average routine.  Could you please post your data set and the VBScript you're running?

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 5 of 6
(5,474 Views)

Hello, Brad

 

I think that I have found if not the solution, but at least the cause for the weird behavior: When running my script via F5 (or equivalent), the Channels collected via

                   Data.GetChannels(oMyChnGroup.name & "/*")

will be passed correctly to subsequent commands like

                 chnAverage

or

                DataBlDel(oMyElementList,....)

BUT

when I run the script stepwise through M$ script debugging via F8, even though

                msgbox(oMyElementList.Count)

shows the correct number of listed elements, the following commands will not receive correct channel lists, giving the "???" error message.

 

So, in a way, problem solved. Whether to pursue the issue of VBScript debugging, DIAdem2011 and win7 - I don't really mind...

Thank you.

Michael

 

 

I attach the script anyway. It's purpose is to separate different test stages, which are identified by integers in channel "Zyklusnummer", into a bunch of channel groups, one for each test stage. Unfortunately, the test stand supplier was unwillling to forsake his proprietary file format to change to TDM. Otoh, his file format supports more levels of hierarchy, i.e. subgroups, which makes it easier for him.

 

Option Explicit

dim i, iIndexstart, iIndexEnd, iNumZyklen

Dim oChnGrp, oNewChnGrp, oChannel,oMyWorkGroup, oMyChn

 

set oChnGrp = data.Root.ChannelGroups(1

set oMyWorkGroup = Data.CreateElementList

iNumZyklen = oChnGrp.Channels("Zyklusnummer").Properties("maximum").Value - _

             oChnGrp.Channels("Zyklusnummer").Properties("minimum").Value + 1

'msgbox(cstr(iNumZyklen))

 

iIndexStart = 1'Beim Aufspalten in Zyklen fangen wir "vorne" an

iIndexEnd = 1'und gehen davon aus, dass der erste Zyklus schlimmstenfalls 1 Wert enthält

for i = 1 to iNumZyklen

 

   set oNewChnGrp = data.Root.ChannelGroups.AddChannelGroup(oChnGrp) 'Kopiere die Originaldaten in eine neue Kanalgruppe

   oNewChnGrp.activate()

   oNewChnGrp.Name = oChnGrp.Name & "_Zykl_" & cstr(i) ' und einen "vernünftigen" Namen vergeben

   iIndexEnd = PNo("[1]/Zyklusnummer", i+1)-1

   if iIndexEnd < iIndexStart then

       iIndexEnd = CL(1)

   endif

 

   msgbox(" Zyklus: " & cstr(i) & vbCrLF & "Startindex: " & iIndexStart & vbCRLF & "Endindex: " & iIndexEnd)

' Jetzt kopieren wir die Kanalnamen aus der aktuellen Gruppe in die Elementliste

   set oMyWorkGroup = Data.GetChannels(oNewChnGrp.Name & "/*")

   CallDatablDel(oMyWorkGroup,iIndexEnd,CL(1)) 

   CallDatablDel(oMyWorkGroup,1,iIndexStart) 

   iIndexStart = iIndexEnd + 1

next

0 Kudos
Message 6 of 6
(5,437 Views)