08-10-2016 05:09 AM
Hi
I have following Channels Group names:
Max Freq Offset
Freq Drift
Freq Drift Rate
Max Freq Offset1
Freq Drift1
Freq Drift Rate2
And when I am using the Sort Channel script:
C:\PROGRAM FILES (X86)\NATIONAL INSTRUMENTS\DIADEM 2014\Examples\documents\SortChannelGroups.vbs
Then It doesnt sort it correctly.
But If i rename the test names instead from Freq Drift Rate to Freq DriftRate then it work properly.
Regards
René
Solved! Go to Solution.
08-10-2016 06:26 AM
Hi René
The sorting is correct, because it uses the ASCII code of a blank (32) is smaller then the ASCII code of "1" (49). So I am afraid that you have to rename you groups (temporary?). You may add a blank in front of the number or replace the blank with an other character.
You may use this small function to replace the blank temporary and add the call at the beginning and the end of the script:
Sub RenameGroups(sSearch,sReplace) Dim oChnGroup For each oChnGroup in Data.Root.ChannelGroups oChnGroup.Name =Replace(oChnGroup.Name,sSearch,sReplace) Next End Sub
if Data.Root.ChannelGroups.Count > 0 then Dim oGroups Call RenameGroups(" ","§") set oGroups = Data.Root.ChannelGroups Dim saGroupName() ReDim saGroupName(oGroups.Count) Dim iLoop for iLoop = 1 to oGroups.Count saGroupName(iLoop) = oGroups(iLoop).Name next call QuickSort(saGroupName) if oGroups.Count > 100 then call MsgBoxDisp("Kanalgruppen werden sortiert ...",,,,,1) for iLoop = 1 to oGroups.Count call Data.Move(oGroups(saGroupName(iLoop)), oGroups, iLoop) next Call RenameGroups("§"," ") call MsgBoxCancel end if
Hope this helps!
Winfried
02-05-2020 02:55 PM
I wish to use the "SortChannels.vbs" sort channel algorithm inside a plugin (source C:\Program Files\National Instruments\DIAdem 2017\Examples\Documents\SortChannels.vbs). I got an error at line 531 (line in RED below) when I use it inside my plugin.
Can you help me on this?
Regards, Eric.
Ref. :
(…)
Dim oChannelGroup
Set oChannelGroup = Root.ChannelGroups.Add("FromPlugin")
(…)
Dim saChnName()
ReDim saChnName(oChannelGroup.Channels.Count)
Dim iLoop
for iLoop = 1 to oChannelGroup.Channels.Count
saChnName(iLoop) = oChannelGroup.Channels(iLoop).Name
next
call QuickSort(saChnName)
for iLoop = 1 to oChannelGroup.Channels.Count
call oChannelGroup.Move(oChannelGroup.Channels(saChnName(iLoop)), oChannelGroup.Channels, iLoop)
next
(…)
02-06-2020 08:59 AM
Hi Adas,
The VBScript DataPlugins execute in an entirely different VBScript host as the DIAdem VBScripts. Each VBScript host has custom functions and variables added to it, but they are mostly distinct from each other. It is rarely the case that you can take a VBScript that runs in DIAdem and port it successfully to a VBScript DataPlugin, unless there are no red DIAdem commands or green DIAdem variables in it. The blue VBScript content transfers just fine, because they are from the baseline VBScript host from Microsoft that has the extra functions and variables added to it.
In the DataPlugin you typically declare a DirectAccessChannel for each column in an ASCII or Excel data file. If you assign each of these to an array of column objects, then you can add each to the Group.Channels collection in any order you want (not necessarily the order in the data file). So what you need to do is sort the columns virtually and determine the correct order to add each to the Group.Channels collection.
Let me know if you need more help with this,
Brad Turpin
Senior Technical Support Engineer
National Instruments
02-06-2020 09:15 AM - edited 02-06-2020 09:17 AM
That is what I was thinking about my behaviour (...) "different VBScript host".
About: (...) So what you need to do is sort the columns virtually (...)
I don't think it will work; the raw data are read from a binary file and the signals information (units, bit length, signals name, etc.) came from another file (text) which are always sent together.
So I have to add signals in the manner which is specified inside the text file, and the result gives the order in the Group.Channels collection.
Do I miss something?
Any other idea?
Thank you in advance...
Eric
02-07-2020 08:35 AM
Hi Eric,
You have to add the channels to the group in the order you want them to appear in the Data Portal. Are you creating channels with Group.Channels.Add() or with Group.Channels.AddDirectAccessChannel()? In the latter case you can create the DirectAccessChannels in any order you want-- typically in the order they appear in the data file. Then the order you Channels.AddDirectAccessChannel() is up to you. In the former case, you do have to Channels.Add() in the order you want in the Data Portal, but you DON'T have to add values with Channel.Values(i) in that order-- you can do that in the order that you find the data in the data file.
Brad Turpin
Senior Technical Support Engineer
National Instruments
02-07-2020 09:03 AM
It will be very complicate to do it.
I have DirectAccessChannel , ProcessedChannel , and a lots of other binary channel to fill-up from many "main" 8 bits channel.
It is possible, but not easy.
Thank you very much.
Eric
02-11-2020 10:23 AM - edited 02-11-2020 10:24 AM
Hi Adas,
The particular sorting routine that you found uses a "switching" action that relies on a Data Portal command, which won't work in a DataPlugin. But the same basic approach will work if you use an array of Channel objects (DirectAccessChannel or ProcessedChannel). There the "switching" action will be the rearranging of the elements of the array. I prefer to use the much more straightforward bubble sort, which just swaps 2 adjacent array elements. It's slower than a quick sort, but much simpler to use and always seems to be plenty fast for a list of channels.
Are you anticipating difficulty in populating such an array of Channel objects in the DataPlugin, or are you not sure how to sort that array after it's built up?
Once the array of Channel objects is sorted, you can just loop through the array and add each Channel object to the Group.Channels collection.
Brad Turpin
Senior Product Support Engineer
National Instruments
02-12-2020 09:39 AM
Good day Brad,
I was able to do something with the QuickSort fonction for my DirectAccessChannel and it seems to work well.
For the "other binary channel to fill-up from many "main" 8 bits channel" I talked in my last post, I'm thinking to make a Channel Pointer array, but it will not be "a walk in the park" ! 🙂
I tried the Bubble Sort; but for my particular application, it take 3 to 4 seconds to sort my imported channels (. For my 20 MBytes files, the processed time is about 5 seconds. So adding a 3 seconds to this isn't a good solution. Using the Quicksort is definitively the best approach. The sorting time is less than 100msec.
Thank you for you help.
Eric G.