09-18-2006 02:43 AM
09-20-2006 12:49 PM
Hi f-zoid,
The first thing you need to realize is that the ReadStore() subroutine is used inside a DataPlugin and is called automatically every time DIAdem (or LabVIEW) attempts to load a data file with that DataPlugin. I also edit and develop DataPlugins using the DIAdem-SCRIPT editor, but unlike "normal" DIAdem VBScripts, DataPlugin scripts can not be started with the DIAdem-SCRIPT "Run script" icon. Instead, the DataPlugin's ReadStore() subroutine is called whenever you drag a data file of that type into the Data Portal or attempt to index one of those data files with the DataFinder.
Inside of a DataPlugin you get the "File" object for free. The top-level subroutine of every VBScript DataPlugin looks like this:
Sub ReadStore(File)
' code happens here
End Sub
The "File" object is created for you and passed to you as the one parameter in the ReadStore() subroutine. As noted above, it is DIAdem (or LabVIEW) which creates the File object and passes it to the ReadStore() subroutine when it invokes the DataPlugin. Also note that the other parent object in the DataPlugin API, the "Root" object, is also created for you and is simply available as a global variable inside the DataPlugin.
For more information on DataPlugin programming, check out the following online-Help topic in DIAdem 10.x
"Programming Reference>>Object-Oriented Script Interfaces>>DataPlugin"
or download the DIAdem 9.1 DataPlugin API from the www.ni.com/dataplugins web site.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
09-20-2006 03:28 PM
09-21-2006 10:33 AM
Hi michael,
You are right. DIAdem 10.0 and earlier versions contained a bug that would not allow you to index a particular Group from the Root object, either by number or by name. This has been fixed in DIAdem 10.1. Until you get DIAdem 10.1, you can work around this bug by assigning each Group that you create to a new variable, so that you don't have to use the Root object to get that Group when you need it later, like this:
Dim i, Groups
ReDim Groups(5)
FOR i = 1 TO Ubound(Groups)
Set Groups(i) = Root.ChannelGroups.Add "Group " & i
NEXT ' i
'------ other code here ------
FOR i = 1 TO Ubound(Groups)
Groups(i).Properties.Add "description", "This is Group number " & i
NEXT ' i
Interestingly, this same bug did not prevent you from indexing a particular Channel from its parent Group by name or number-- that has always worked. If you need Group lookup by name, you can use a VBScript dictionary object.
The File object passed in the ReadStore(File) subroutine is not the same file object as you get with the standard VBScript FileSystemObject. You can, however open as many new File objects as you want in the ReadStore() subroutine or in any other Subs or Functions the ReadStore() subroutine calls, using the following function from the DataPlugin API:
Set MyNewFileObject = OpenFile("c:\test.txt")
Debugging a DataPlugin is a ticklish business, but it can be done. Prior to DIAdem 10, you could use the standard MsgBox command to output information to a MsgBox that would appear when you drag the data file into the Data Portal, or when you run a test VBScript like this:
Call DataDelAll
Call DataFileLoad(DataFilePath, DataPluginName)
Where the variable "DataFilePath" contains the full path to the data file you want to test with, and the variable "DataPluginName" contains the name of the DataPlugin (that you typed in) that you want to use when importing this data file.
But in DIAdem 10.x, because of indexing headaches the MsgBox command causes for the DataFinder, the MsgBox command is no longer allowed in a DataPlugin. You can instead use a similar method of outputting information to a Root or Group or Channel property instead of to a MsgBox dialog. Or you can use the standard FileSystemObject variable in VBS to output information to an external ASCII file. I hear that it is also possible to use a just-in-time VBScript debugger for DataPlugins, but I have not personally ever done that.
Hope all this helps,
Brad Turpin
DIAdem Product Support Engineer
National Instruments