08-05-2012 03:36 PM
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!
Solved! Go to Solution.
08-06-2012 01:12 AM
To answer your question, the correct syntax is:
Dim oMyAverGroup, i i = 3 Call ChnAverage("'/Temperature_1'-'/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("/Temperature_
1")) call oMyAverGroup.Add(Data.GetChannel("/Temperature_ 2")) call oMyAverGroup.Add(Data.GetChannel("/Temperature_ 3")) ' Option 2 - a wildcard (joker) set oMyAverGroup = Data.GetChannels("/Temperature_*") ' Option 3 - a loop for i = 1 to 3 call oMyAverGroup.Add(Data.GetChannel("/Temperature_ " & str(i))) next ' run calculation Call ChnAverage(oMyAverGroup, "mean")
10-24-2012 05:35 AM - edited 10-24-2012 05:57 AM
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
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
10-30-2012 05:10 PM
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?
DIAdem Product Support Engineer
11-06-2012 07:02 AM - edited 11-06-2012 07:04 AM
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
when I run the script stepwise through M$ script debugging via F8, even though
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...
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.
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
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.Name = oChnGrp.Name & "_Zykl_" & cstr(i) ' und einen "vernünftigen" Namen vergeben
iIndexEnd = PNo("/Zyklusnummer", i+1)-1
if iIndexEnd < iIndexStart then
iIndexEnd = CL(1)
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 & "/*")
iIndexStart = iIndexEnd + 1