advertisement
6 Creating Reports Easily Using ActiveX Chapter
5 After you have compared the entries to Figure 150,
iconize the four objects.
256
Figure 150 The Globals UserFunction
Notice that by using the datatype Objects in the globals
UserFunction, you could specify the Object Type and Class.
There are two reasons to specify Object Type and Class: more specific type checking, and catching events.
More Specific Type Checking:
For example, if you specify an
Object app as being of type Excel.Application, then only an
Object of type Excel.Application can be assigned to app.
Assigning an Object of type Excel.worksheet or
Word.bookmark will cause an error.
Catching Events:
You could also use a VEE UserFunction to catch various events that could occur in the application, such as a right- button- down in the MS Excel worksheet. For any of these types of events, you can specify a VEE UserFunction to handle the event and pass information back to MS Excel.
VEE User’s Guide
Creating Reports Easily Using ActiveX Chapter 6
Events are useful for ActiveX Controls, where you need a way for the control to communicate back to VEE. For more information, refer to the VEE Pro Advanced Techniques manual.
6 Open the UserFunction globals object menu and click
Generate
⇒ Call. This generates a Call globals object configured correctly. Place it to the left in the Main window and iconize the globals UserFunction window.
7 Click Device
⇒ Formula and place it in the upper center of the
Main window. Rename it Set up Excel Worksheet.
Connect the globals sequence out pin to the Formula sequence in pin. Delete the input terminal A from Set Up Excel
Worksheet (open the Object menu and select Delete Terminal
⇒
Input.)
8 Inside Set up Excel Worksheet, enter the lines shown in
Figure 151. Notice that semicolons are used for line
separators, just as in ANSI C.
VEE User’s Guide
Figure 151 Setting Up the MS Excel Worksheet
257
6 Creating Reports Easily Using ActiveX Chapter
258
Table 25 Setting up an Excel Worksheet in the Formula Object
Command set sheet =
CreateObject
(“Excel.Sheet”).
worksheets(1);
Description
The keyword set is used to assign or set whatever is on the right-hand side of the assignment operator (in this case, the equal sign) to the variable on the left-hand side of the expression. For example, set app sets the application sheet.application, which has been defined as an Excel worksheet.
Creates a new instance of the Automation Server (in this case, MS Excel) and creates an empty sheet (Excel terminology for a new workbook). Each Automation Server has its own terminology, but the syntax is the same. For example, to create a report in MS Word, you would enter
CreateObject
(“Word.Document”)
to run
Word and create a blank document.
If the set keyword is used, the right-hand side object pointer itself is assigned to the left-hand side variable. If set is not used, then the default property (often the name) of the right-hand side is assigned to the left-hand side. For more information, refer to the VEE Pro Advanced Techniques manual.
Now that Excel is running with a new workbook in it, with
CreateObject ("Excel.Sheet"
), you want to address the first worksheet in it. Add worksheets(1) to the statement, so the entire statement reads: setsheet =
CreateObject("Excel.Sheet").worksheets(1);
This sets sheet to Sheet 1 of the report. (To see an example, open MS Excel and select File
⇒ New
to create a new workbook. You will notice there are several sheets in it labeled Sheet1, Sheet2, and so on. You want Sheet1.) set app = sheet.application;
Asks Excel for a pointer to the entire application, and not just the worksheet itself, by asking the worksheet for its property Application and setting it to the variable app.
app.visible = true; Sets the app’s visible property to true in order to display
Excel on screen (so that you can see it).
VEE User’s Guide
VEE User’s Guide
Creating Reports Easily Using ActiveX Chapter 6
Table 25 Setting up an Excel Worksheet in the Formula Object
Command set window = app.windows(1);
Description
References the first window.
window.caption =
“Test System
Results”;
Sets the first window’s caption to “Test System Results.”
N O T E
For more information about the Application Server libraries, refer to the many books available about ActiveX Automation and MS Visual Basic. You can probably find information on the World Wide Web about ordering books such as Office 2000 or the Office 97 Visual Basic Programmer’s
Guide. The books will help you with VEE as well, since VEE syntax is very similar to MS Visual Basic.
9 Create a Formula object (under Device
⇒ Formula). Clone the
Formula object to create a second Formula object. Create a
For Range object (under Flow
⇒ Repeat ⇒ For Range).
Rename the objects, connect them, and configure them as
shown in Figure 152. (Be sure to delete the input
terminal on the Formula object Fill in Title.)
259
6 Creating Reports Easily Using ActiveX Chapter
260
Figure 152 Adding the Title and Data to the Sheet
The instructions in the Formula objects and the For Range object are described as follows
:
Table 26 Instructions in Formula Objects and the For Range Object
Formula sheet.cells(1,1) =
“DC Volts”
Description
Refers to the first row and column in the Excel worksheet.
The text DC Volts will be placed there. This sets the default property (which is value) of cell (1,1) , to "DC
Volts" .
VEE User’s Guide
VEE User’s Guide
Creating Reports Easily Using ActiveX Chapter 6
Table 26 Instructions in Formula Objects and the For Range Object
Formula Description sheet.cells(A+1,1)
= random(1,100)
This statement is shorthand for sheet.cells(A+1,1).value=random(1,100) .
The worksheet cell at row A+1, col 1 gets the row number by adding 1 to the input pin A value but stays in column 1.
The value between 1 and 100 returned by random is assigned to the specified cell in the worksheet.
from 1 thru 20, step 1 (the
For Range object)
As the For Range object outputs the integers from 1 to 20 ,
Fill in Cells puts the random number in the specified cell.
10 Create a Formula object and an AlphaNumeric object, rename,
configure, and connect them as shown in Figure 153.
261
6 Creating Reports Easily Using ActiveX Chapter
262
Figure 153 The Results Average Program
The entries in the Formula object are as follows:
Table 27 Formula Object Entries
Entry set range = sheet.range(“A2:A21"); range.NumberFormat =
“##,#00.00";
Description
Sets the VEE variable range to reference the range
A2 to A21 on the Excel worksheet. ( A refers to the first column in a worksheet.)
Assigns the format to each of those cells with the pound signs ( # ) allowing for larger numbers, if necessary.
VEE User’s Guide
Creating Reports Easily Using ActiveX Chapter 6
Table 27 Formula Object Entries
Entry app.worksheetFunction.
average(range);
Description
Calls an Excel method average() that returns the average value of the designated range of values, which is displayed in Results Average.
11 Save the program as results_average.vee. Run the program.
MS Excel will launch with a worksheet like the one shown
VEE User’s Guide
Figure 154 Excel Worksheet for “Results Average” Program
263
6 Creating Reports Easily Using ActiveX Chapter
Creating an Agilent VEE to MS Excel Template
In this exercise, you will create a program to display an array of
VEE test data in MS Excel. You can use this program as a template for displaying the results of other tests in MS Excel spreadsheets.
Lab 6-2: Creating an Agilent VEE to MS Excel Template
1 Open results_average.vee.
2 Change the For Range object to loop 10 times.
3 Add the input B to Fill in Cells and change the statement inside to read: sheet.cells(A+1,1) = B[A-1].
4 Click Device
⇒ Formula, rename it to Array of Test Data, and enter the embedded functions randomize(ramp(20),
4.5, 5.5) to create a random array of 20 elements with values from 4.5 to 5.5. Delete the input pin and connect the data output pin to the B input of Fill in Cells.
5 Change the range in the Formula box on the bottom of the screen from A21 to A11. The statement should now read: set range = sheet.range(“A2:A11");
6 Save the program as report_template.vee and run it. Compare it
to the Excel worksheet as shown in Figure 155 and the
complete program as shown in Figure 156.
264 VEE User’s Guide
VEE User’s Guide
Creating Reports Easily Using ActiveX Chapter 6
Figure 155 Excel Worksheet for Array of Test Data
265
6 Creating Reports Easily Using ActiveX Chapter
266
Figure 156 Program for Array of Test Data
You can re- use this program as a template for displaying test results in MS Excel. You simply put the test data into arrays and modify the rest of the template to fill in the appropriate cells in the right format.
To find additional methods and properties in the MS Excel library, look at the Function & Object Browser and choose the
ActiveX Objects under Type and Excel under Library. You can choose a Class or Member and press Help to get Help provided by the Automation Server author (in this case, Microsoft). For more complete information about these libraries, consult
Microsoft documentation.
VEE User’s Guide
Creating Reports Easily Using ActiveX Chapter 6
On Your Own
Generate a waveform and strip out the Time Span to get an array. Create a VEE object for MS Excel with a worksheet and set it to an Object variable. Make the application visible.
Then put the 256 point array into the worksheet range
"A1:A256" in one step, instead of one cell at a time.
Use an Unbuild Waveform object. Use the [a] build array syntax to create a 2D array from a 1D array. Then call the function transpose() to make it a 256 x 1 array instead of a
1 x 256 array for Excel to accept it in one step, as shown in
VEE User’s Guide
Figure 157 Program for On Your Own Exercise
Extending Capabilities With MS Excel
Figure 158 shows a more elaborate example of a program to
display test results in MS Excel. You can see how knowledge of a few more calls in the MS Excel library can expand the template for displaying VEE data in MS Excel.
267
6 Creating Reports Easily Using ActiveX Chapter
268
Figure 158 A VEE to MS Excel Program Example
The entries in Figure 158 are as follows:
Table 28 Description of Figure 13’s Entries
Item Description
MS Excel Window
Size
Notice the Drop-Down List in the upper right work area.
This allows you to choose one of three options xlMaximized , xlMinimized , xlNormal to select the size of the worksheet window inside Excel when it comes up.
Each window size is associated with a number, which VEE calculates and puts in the wndState variable. This value is then assigned to the windowState property in the Excel library.
VEE User’s Guide
VEE User’s Guide
Creating Reports Easily Using ActiveX Chapter 6
Table 28 Description of Figure 13’s Entries
Item Description
Memory Tracking (Click Show Terminals in the Properties boxes on the
Formula and Meter objects.) Notice the memoryTotal and memoryUsed properties in the Excel library that are assigned to the VEE variables memTotal and memUsed .
These values are then used to calculate the ranges to configure a VEE meter before it displays the memory being used by MS Excel.
Number Format sheet.SaveAs
(filename)
Notice how easy it is to add a dollar sign to the number format.
The SaveAs() method is being called from the Excel library to automatically save the worksheet. Notice that a File
Name Selection box (from the Data
⇒
Dialog Box menu) is used to display the pop-up Save As box from VEE.
The file name you select is then used as a parameter in the
Excel SaveAs() method call.
Press to Kill Excel The Confirm (OK) button has been used to signal when you want to close Excel.
Close Excel The quit() method is called to tell MS Excel to exit.
269
6 Creating Reports Easily Using ActiveX Chapter
Using MS Word for Agilent VEE Reports
This lab describes how to display VEE test information in an MS
Word document, including text, a time stamp, and a screen dump of a VEE pop- up panel with an XY Display. Consult
Microsoft documentation to find out more elaborate ways of controlling MS Word from other applications using ActiveX
Automation.
Lab 6-3: Using MS Word for Agilent VEE Reports
To begin, follow the steps to declare five variables as type
Object.
1 Click Device
⇒ ActiveX Automation References... and select
Microsoft Word 9.0 Object Library.
2 Click Data
⇒ Variable ⇒ Declare Variable.
a Change the Type field to Object. Clone it four times.
b Name the five object variables App, Doc, Wnd, Sel, and
Bmp.
c Select Specify Object Type on all of them. The advantages of declaring the particular Class within a Library are as follows: VEE can do type checking for program errors, and you can catch events from the Automation Server.
d Then click the Edit... button and select Word for Library in each case. Select the following Classes:
App will use Application
Sel will use Selection
Wnd will use Window
Doc will use Document
Bmp will use Shape
e Select Enable Events where the class permits it. Iconize
these five icons. See Figure 159 for the open view of
these variables.
270 VEE User’s Guide
Creating Reports Easily Using ActiveX Chapter 6
VEE User’s Guide
Figure 159 Object Variables
3 Create a UserFunction called Graph, which uses a Function
Generator virtual source to send a sine wave to a Waveform
(Time) display. Create a panel view of the display only. Then generate a Call Graph object in the Main window. (Recall that the UserFunction object menu includes an easy way to generate a call.)
Now create a bitmap file of the Panel with the Waveform display to use in the report in MS Word.
4 To create a file name for the bitmap, click Device
⇒ Formula.
Rename it Image Filename. Enter installDir() + "\\ panel.bmp" in the Formula input field. (Use the escape
271
6 Creating Reports Easily Using ActiveX Chapter sequence
\\ to specify the ASCII character \.) Delete input terminal A.
If you installed in c:\Program Files\Agilent\ for example, you would then generate the following text string on the Result output pin:
C:\Program Files\Agilent\VEE Pro 6.0\panel.bmp.
5 Create another Formula object and enter savePanelImage("Graph", FileName, 256)
. Rename the input terminal to FileName.
6 This saves the screen dump from the UserFunction Graph in the panel.bmp file in the installation directory at a color depth per pixel of 256.
7 Create another Formula object and enter the statement:
Set App = CreateObject("Word.Application")
This launches MS Word and assigns the object variable app to refer to this instance of the application. Delete input terminal
A. Connect Call Graph, ImageFileName, and savePanelImage as
272
Figure 160 Beginning of Lab 6-3 Program
VEE User’s Guide
Creating Reports Easily Using ActiveX Chapter 6
8 Click Device
⇒ Formula and enter the statements shown in
Figure 161, which are also described below. Rename input
terminal A to FileName. Connect the data input and
sequence input pins as shown in Figure 161.
VEE User’s Guide
Figure 161 Adding the ActiveX Statements
In Figure 161, notice that you can nest property and method
calls together with the Object’s dot notation. Refer to
ActiveX documentation to find the right properties in the target applications. You can use the properties and methods described in this chapter to begin generating test and measurement reports. The entries in the Formula object are as follows:
Table 29 Entries in the Formula Object
Entry
App.Visible = 1;
Description
Makes MS Word visible on the screen.
273
6 Creating Reports Easily Using ActiveX Chapter
Table 29 Entries in the Formula Object
Entry
Set Doc =
App.Documents.
Add();
Description
Adds a Document in MS Word and assigns it to the Object variable Doc .
Note: In the Excel example, Excel was started with a blank worksheet using CreateObject(Excel.Sheet) . In this example, Word is started and the method Add() adds an empty Document to it. Either application can be created either way.
Doc.Activate();
Set Wnd =
App.Active
Window;
Set Sel =
App.Selection;
Activates the Document above.
Takes the document in the active window and assigns it to the Object variable Wnd .
Puts focus (selection) into the document and assigns this to the Object variable Sel . This allows you to insert text.
Wnd.View.Type =
3;
Specifies the type of window for displaying the document.
The 3 indicates a normal window size. A 1 would iconize the window.
Note: The 3 is used here instead of the constant wdPageView because the constant is missing from the
Office 2000 Type Library.
Sel.TypeText(***
Test Results ***),
Sel.TypeParagrap
h();
Puts the title *** Test Results *** in the document and issue a carriage return/line feed.
Set Bmp =
Doc.Shapes.
AddPicture(FileN ame);
Puts the panel.bmp bitmap into the document and assigns this call in the Shapes Class to the Object variable Bmp.
Sel.TypeParagrap
h();
Sel.InsertDateTim
e
(M/d/yy h:mm:ss am/pm, 0);
Puts a time stamp in the document.
274 VEE User’s Guide
Creating Reports Easily Using ActiveX Chapter 6
9 Add three more Formula objects and one If/Then/Else object,
configure, and connect them as shown in Figure 162.
VEE User’s Guide
Figure 162 The Complete Program for Report in MS Word
The entries in the additional objects are as follows:
Table 30 Additional Objects in Figure 17
Object Description
App.ActivePrinter
Requests the default printer in a string including its port.
strLen(str) != 0 Makes sure that ActivePrinter has located a configured printer (if the string on the input is not null, then...), then outputs a 1
(=TRUE)
on the Then pin, which pings the
Formula object containing the PrintOut call.
DocPrintOut(0)
App.Quit(0)
Prints the document.
Closes the MS Word Application
275
6 Creating Reports Easily Using ActiveX Chapter
10 Run the program. It should look like Figure 163. (If the
colors look strange in the screen dump, iconize any open applications, so the PC has a full palette of colors to work with.)
276
Figure 163 The MS Word Document Created by Lab 6-3
For more information about controlling MS Excel and MS Word using ActiveX Automation, refer to Microsoft documentation.
Remember that you can also control other Server applications that support ActiveX Automation, sometimes just called
Automation, or OLE Automation.
For more information about using ActiveX controls, refer to
Chapter , “Using Operator Interfaces.” For more information
about using ActiveX from a MS Visual Basic program to
control VEE, refer to Chapter , “Overview 473.”
VEE User’s Guide
Creating Reports Easily Using ActiveX Chapter 6
Chapter Checklist
• You should now be able to perform the following tasks.
Review topics, if necessary, before going on to the next chapter.
• Describe the basic concept behind ActiveX Automation in
VEE.
• Send data from VEE to MS Excel.
• Use a generic template to send arrays of test data to an MS
Excel worksheet. (Make sure you know how to send an array to the spreadsheet in one step.)
• Employ some of the extended capabilities of the MS Excel library, such as finding out the memory used by a program.
• Send text, a time stamp, and a display bitmap to MS Word from VEE.
VEE User’s Guide 277
6 Creating Reports Easily Using ActiveX Chapter
278 VEE User’s Guide
VEE User’s Guide
7
Using .NET with VEE
VEE and the .NET Framework 282
Importing a Namespace into VEE 288
VEE and Primary Interop Assemblies 292
Distributing the VEE Runtime 314
Using .NET with VEE 7
279
7 Using .NET with VEE
Using .NET with VEE
In this chapter you will learn about:
• Some of the basic .NET Terminology
• How to import a namespace into VEE
• What a PIA is and why it is important
• Special .NET considerations for distributing the VEE
Runtime
• VEE and .NET Security
Average time to complete: 1.5 hours
280 VEE User’s Guide
What is .NET?
Using .NET with VEE 7
Visual Studio .NET is Microsoft’s latest development platform. Unlike previous products, such as Visual Studio 6,
.NET addresses the needs of both desktop programmers and
World Wide Web developers. The strength of .NET from a
VEE perspective is the free .NET Framework that is distributed with VEE 7.0. In fact, this free runtime is integral to several of VEE’s new features.
The key features and benefits of the .NET Framework for
VEE are the Framework Class Library (FCL) and the COM interop technology. The Framework Class Library is of particular value to VEE programmers. There are 100’s of new properties and methods that are now available through the Function&Object Browser. This new feature enables your code to derive functionality such as File and Directory management; simpler String managment; the simplified views of the Operating System environment; the manipulation of
Web pages; access to Operating System processes; reading the registry; and many, many more.
.NET also provides a native COM interop technology. This means a COM component can be accessed as a .NET object and a .NET object can be accessed as a COM component.
At the end of this chapter is a set of definitions for
Microsoft terminology that is used throughout this chapter.
Please refer to it as necessary.
VEE User’s Guide 281
7 Using .NET with VEE
VEE and the .NET Framework
Before beginning a review of how the .NET Framework interacts with VEE, review the .NET Framework by looking up the “.NET Framework – getting started” in the MSDN index at this unfortunately long address:
(http://msdn.microsoft.com/library/en- us/cpguide/html/cpovri ntroductiontonetframeworksdk.asp).
Under the Device menu there is a new menu option called
.NET Assembly References, which is very similar to References for
ActiveX. As you will remember from the definitions, a
Reference makes an Assembly available to you. Open this
menu selection. You will see a window similar to Figure 164.
282 VEE User’s Guide
Using .NET with VEE 7
VEE User’s Guide
Figure 164 Import Namespaces Dialog Box
.NET Assembly References
There are many assemblies you could select. These assemblies are located in the directory where your VEE program is stored or in the directory where the .NET
Framework is installed. If you are using an assembly that is not in one of these two directories, use the Browse button to select it. There is also a checkbox for Import namespaces after
closing . Importing a namespace is equivalent to the using statement in C# or the Imports statement in Visual Basic.
283
7 Using .NET with VEE
284
The most commonly used assembly, mscorlib, is selected in the previous graphic. Go ahead and select this assembly.
mscorlib encapsulates many functions useful to VEE users, such as file system manipulation, collection management, and data type conversion. Another very commonly used assembly is System, which contains functions such as process management, web request and response, and regular expressions.
Under the COM tab is a list of all the COM type libraries currently registered on your computer. In fact, this is almost the same list of type libraries you see when you use the
ActiveX automation references dialog box.
How do you know which of these two choices to use? You should use the ActiveX automation references dialog box if the following cases are all true:
• If the library appears there
• If the library is fully functional in previous versions of
VEE
• If the library has no Primary Interop Assembly (PIA).
Using the ActiveX automation references directly avoids adding another layer, the .NET and COM Interop layer.
You should use the .NET/COM Interop explained in this topic:
• If the library doesn't appear in the ActiveX automation references dialog box.
• If not all of the library’s functionality gets imported
• If you know the COM library has a PIA
For example: not all IVI- COM driver interfaces are visible from the Function & Object Browser’s ActiveX Objects list.
However, the .NET interop does allow you to see all of the
IVI driver interfaces.
When using the .NET Assembly References menu option and selecting a COM type library from the list, VEE tries to import the COM type library as a .NET assembly. If there is a PIA, VEE uses it, otherwise VEE creates an Interop
Assembly (or assemblies if the COM type library references
VEE User’s Guide
VEE User’s Guide
Using .NET with VEE 7
N O T E
N O T E other type libraries) in the directory where the program is saved. After VEE gets the Interop Assembly, it gets all of the type information from it.
To avoid the overhead of VEE having to copy the generated Interop
Assemblies from a temporary directory to your VEE program directory, save your VEE program first. This way, the generated Interop Assemblies will be directly saved in your VEE program directory.
Go ahead and select the COM tab. This may take some time as VEE scans your registry for COM type libraries. Now select the Microsoft ActiveX Plugin.
You are now prompted for the namespaces to import. This is an optional step, but go ahead and select
Interop.ActiveXPlugin, System, and System.IO.
The Import .NET Namespaces dialog box will come up every time unless you uncheck the check box in the .NET Assembly References dialog box.
From the Device menu, open the Function & Object Browser.
One of the menu selections is .NET/CLR Objects. Select this option. Note how the
Assembly window in Figure 165 reflects
the two selections you made earlier.
285
7 Using .NET with VEE
286
Figure 165 Function & Object Browser - .NET Objects
All of the namespaces of the selected assembly are listed in the Namespace list box. For each Namespace, all of its types are listed in the Type list box and all the members of each
Type are listed in the Members list box. Members include constructors, fields, properties, methods, and enumerations.
If you have used ActiveX in VEE, you will find that selecting a .NET class member is almost exactly the same process. The differences are minor and include:
1 COM does not have any shared (static) members. If the
.NET member is a static member, the help area shows the
STATIC keyword and the icon has an beside it. To invoke a static member, you will invoke on the class, not on an object instance. You can use the Function & Object
VEE User’s Guide
VEE User’s Guide
Using .NET with VEE 7
.
Browser to get yourself familiarized with the syntax. See
“Lab 7- 2: Using .NET to Perform DateTime Operations" on page 305 for an example.
2 Instance object variables are generated with the first letter in lower case. This is a clue to you that you are calling a method or property on an instance member of an object. This also means that you need to create a .NET object.
3 To create a .NET object, select a Constructor (constructors and methods share this icon ) in the member list. As in the previous graphic, the Create Instance button is available. Selecting this button generates a formula template for creating a new .NET object. Note the
dateTime output pin in Figure 166 that is generated by
VEE. You may connect this output pin to the input pin of any formula box that requires this .NET object as input.
See “Lab 7- 3: Using .NET to Get File Information" on page 309 for an example.
Figure 166 Creating a .NET Object
4 The Enumerations ( ) in .NET are strongly typed, so you can no longer substitute an integer constant for an
Enum like you did with ActiveX objects. You have to enter the full Enum name (minus the namespace if you have imported it) or use the Create Formula button and save yourself some typing. For examples, see Enum related examples in the examples\dotnet directory.
287
7 Using .NET with VEE
Importing a Namespace into VEE
To reiterate the definition for a namespace: “.NET
Framework types use a dot syntax naming scheme that connotes a hierarchy. This technique groups related types into namespaces so they can be searched and referenced more easily. The first part of the full name — up to the rightmost dot — is the namespace name. The last part of the name is the type name. For example,
System.Collections.ArrayList represents the ArrayList type, which belongs to the System.Collections* namespace. The types in System.Collections can be used to manipulate collections of objects.”
Importing a namespace is the same as using the Imports statement in Visual Basic or the using statement in C#. In both cases, you will not have to qualify the use of a type from that namespace. VEE supports two methods for importing a namespace. You can either call the Import .NET
Namespaces directly from the Devices menu or you can use the checkbox on the .NET Assembly References menu choice
A full list of available .NET namespaces are listed and, to import one, just select the checkbox beside it. If the
assembly you chose does not have any namespaces, the list will be empty.
*Nested classes are an exception to this general rule. Please see MSDN documentation for further details.
288 VEE User’s Guide
Using .NET with VEE 7
VEE User’s Guide
Figure 167 Assemblies, Namespaces, Types, and Members
289
7 Using .NET with VEE
290
Figure 168 .NET Assembly References - Importing Namespaces
VEE User’s Guide
Using .NET with VEE 7
VEE User’s Guide
Figure 169 Namespaces Selection List
If you have not imported a namespace for a class, the formula templates generated for the static members and enumerations for that class will contain fully qualified type names. This will make your formula boxes much larger.
291
7 Using .NET with VEE
VEE and Primary Interop Assemblies
When you choose the COM tab in Device
⇒ .NET Assembly
References, VEE goes through the registry and finds all registered COM type libraries on your machine. As you select
COM type libraries, if the library has a PIA and the
PrimaryInteropAssemblyCodeBase key for the COM type library is registered, then the PIA location is shown in the
Function & Object Browser description area. Note that
PrimaryInteropAssemblyCodeBase is only registered when the PIA is registered with /codebase option. Not all PIAs are registered this way. Currently, all Agilent IVI- COM drivers are registered with the /codebase option, but many assemblies are not. Also note that when you check a COM type library, all VEE does is look at the registry, it does not load the interop assembly if there is one. Once you choose
OK, if there is no PIA, then VEE will generate one or more
Interop Assemblies automatically. The Interop Assemblies are also loaded after the OK button is clicked.
If you choose Browse and select a PIA or an Interop
Assembly directly, however, VEE actually loads the interop assembly in order to find out which COM type library it belongs to and whether it is a primary interop assembly or not, which is the key difference between browse/select and just a check on the COM tab list. After the interop assembly is loaded, VEE finds out which COM type library it belongs to and then checkmarks the corresponding COM type libraries under the COM tab list.
292 VEE User’s Guide
Using .NET with VEE 7
Programming Practices
Converting Data Types Between .NET and VEE
VEE converts data types between VEE and .NET automatically for all data types that both VEE and .NET natively support. For example, Int16, Int32, Real64, etc. You may wish to “undo” this automatic conversion so you can use the data as a true .NET object. In those cases, you can use the new asClrType() type conversion function to convert a VEE data type to a .NET/CLR type. See the conversion tables below for more details.
.NET operations in VEE will usually accept a precision- widening (type promotion) data type as a parameter, but not a precision- narrowing (type demotion) data type. For example, you may pass VEE’s UInt8 to a .NET operation that requires a parameter of type System.Int16, but not the other way around. Also, if the .NET operation requires a ByRef parameter and you want to retrieve its result back, then the data type has to match exactly. For example, if the .NET method requires a parameter of type
ByRef Int32, then you can only pass VEE’s ByRef Int32 data type. If you don’t care about retrieving the result back, then you may skip the ByRef keyword and the normal parameter rule would apply.
The following tables illustrate the data type conversion functions between VEE and .NET.
Table 31 Converting .NET scalar data types to VEE data types in VEE 7.0
Convert From .NET Data Type Convert To VEE
Data Type
Notes
System.Boolean
Int16 Use isVariantBool() to determine if the VEE Int16 was of type System.Boolean
System.Byte
Uint8
VEE User’s Guide 293
7 Using .NET with VEE
System.Char
System.DateTime
System.Decimal
System.Double
System.Enum
System.Int16
System.Int32
System.Int64
System.SByte
System.Single
Object
Object
Object
You can use a System.Convert.To* method to convert it to a .NET data type that VEE can convert automatically, e.g., ToInt32().
See examples\dotnet\DateTime.vee
.
You can use a System.Convert.To* method to convert it to a .NET data type that VEE can convert automatically, e.g., ToInt32(). If the value does not fit in an Int32, an error 751 will occur indicating a
System.OverflowException. The System.Decimal structure itself also provides a number of conversion methods.
See examples\dotnet\FileInfo.vee
.
Real64
Object
Int16
Int32
Object
Object
Real32
You can use a System.Convert.To* method to convert it to a .NET data type that VEE can convert automatically, e.g., ToInt32(). If the value does not fit in an Int32, an error 751 will occur indicating a
System.OverlfowException.
You can use a System.Convert.To* method to convert it to a .NET data type that VEE can convert automatically, e.g., ToInt16().
294 VEE User’s Guide
VEE User’s Guide
Using .NET with VEE 7
System.String
System.UInt16
System.UInt32
System.UInt64
System.Object
Text
Object
Object
Object
VEE automatically converts String to Text. If you want to use the many useful functionalities in the
System.String class, you may use asClrType() to convert the text back to System.String, e.g.,
Set dotNetString = asClrType(veeText,
System.String);
ModifiedString = dotnetString.Replace( “ “,”_”);
Also see examples\dotnet\ stringsplit.vee
for an example
You can use a System.Convert.To* method to convert it to a .NET data type that VEE can convert automatically, e.g., ToInt32().
You can use a System.Convert.To* method to convert it to a .NET data type that VEE can convert automatically, e.g., ToInt32(). If the value does not fit in an Int32, an error 751 occurs indicating a
System.OverflowException.
You can use a System.Convert.To* method to convert it to a .NET data type that VEE can convert automatically, e.g., ToInt32(). If the value does not fit in an Int32, an error 751 will occur indicating a
System.OverflowException.
Object
Table 32 Converting VEE data types to .NET scalar data types in VEE 7.0
Convert From VEE Data
Type
Convert To .NET Data
Type
Int16 System.Int16
Notes
Int32 System.Int32
Use asClrType() to convert to other .NET/CLR types. See asClrType() documentation.
Use asClrType() to convert to other .NET/CLR types. See asClrType() documentation.
295
7 Using .NET with VEE
Real32
Real64
Text
UInt8
<scaler of type *>
Date/Time
Object
System.Single
System.Double
System.String
System.Byte
System.Boolean
System.DateTime
Use asClrType() to convert to other .NET/CLR types. See asClrType() documentation.
Use asClrType() to convert to other .NET/CLR types. See asClrType() documentation.
Use asClrType() to convert to other .NET/CLR types. See asClrType() documentation.
Use asClrType() to convert to other .NET/CLR types. See asClrType() documentation.
Use asVariantBool() on any scalar VEE data type that can be cast to an Int16, (UInt8, Int16,
Int32, Real32, Real64, Text). You may also use the more generic asClrType(), e.g., asClrType(veescalar,
System.Boolean) .
VEE’s Date/Time is stored as type Real64.
Use asClrType(veeDateTime,
System.DateTime) .
See examples\dotnet\
DateTime.vee
.
If VEE holds a pointer to a .NET Object.
System.Object
Table 33 Converting .NET array data types to VEE data types in VEE 7.0
Convert From .NET Data Type
System.Boolean Array
System.Byte Array
Convert To VEE Data
Type
Notes
Int16 Array Use isVariantBool() to determine if the array was of type System.Boolean
Uint8 Array
296 VEE User’s Guide
System.Char Array
System.DateTime Array
System.Decimal Array
Double Array
System.Enum Array
System.Int16 Array
System.Int32 Array
System.Int64 Array
Using .NET with VEE 7
Object
Object
Object
The VEE object holds a pointer to a
System.Array .NET object.
You can use the formula
CreateInstance(“mscorlib”,”System.String”, charArray).ToString(); to convert an array to a
.NET data type that VEE can convert automatically.
The VEE object holds a pointer to a
System.Array .NET object.
The VEE object holds a pointer to a
System.Array .NET object.
You can use a System.Convert.To* method to convert each array member to a .NET data type that VEE can convert automatically, e.g.,
ToInt32().If the value does not fit in an Int32, an error 751 occurs indicating a
System.OverflowException. The
System.Decimal structure itself also provides a number of conversion methods.
The VEE object holds a pointer to a
System.Array .NET object.
Real64 Array
Object
Int16 Array
Int32 Array
Object The VEE object holds a pointer to a
System.Array .NET object.
You can use a System.Convert.To* method to convert each array member to a .NET data type that VEE can convert automatically, e.g.,
ToInt32(). If the value does not fit in an Int32, an error 751 occurs indicating a
System.OverflowException.
VEE User’s Guide 297
7 Using .NET with VEE
System.SByte Array
298
System.Single Array
System.String Array
System.UInt16 Array
SystemUInt32 Array
System.UInt64 Array
System.Object Array
Object
Real32 Array
Text Array
Object
Object
Object
Object
The VEE object holds a pointer to a
System.Array .NET object.
You can use a System.Convert.To* method to convert each array member to a .NET data type that VEE can convert automatically, e.g.,
ToInt16().
VEE automatically converts String to Text. If you want to use the many useful functions in the System.String class, you can use asClrType() to convert the text array back to a
System.String array.
The VEE object holds a pointer to a
System.Array .NET object.
You can use a System.Convert.To* method to convert each array member to a .NET data type that VEE can convert automatically, e.g.,
ToInt32().
The VEE object holds a pointer to a
System.Array .NET object.
You can use a System.Convert.To* method to convert each array member to a .NET data type that VEE can convert automatically, e.g.,
ToInt32(). If the value does not fit in an Int32, an error 751 occurs indicating a
System.OverflowException.
The VEE object holds a pointer to a
System.Array .NET object
You can use a System.Convert.To* method to convert each array member to a .NET data type that VEE can convert automatically, e.g.,
ToInt32(). If the value does not fit in an Int32, an error 751 will occur indicating a
System.OverflowException..
The VEE object holds a pointer to a
System.Array .NET object.
VEE User’s Guide
Using .NET with VEE 7
Table 34 Converting VEE array data types to .NET data types in VEE 7.0
Convert From VEE Data
Type
Int16 Array
Convert To .NET Data Type *
System.Int16 Array
Int32 Array
Real32 Array
Real64 Array
Text Array
UInt8 Array
< type *> Array
Date/Time Array
System.Int32 Array
System.Single Array
System.Double Array
System.String Array
System.Byte Array
System.Boolean Array
System.DateTime Array
Notes
Use asClrType() to convert to other
.NET/CLR types. See asClrType() documentation.
Use asClrType() to convert to other
.NET/CLR types. See asClrType() documentation.
Use asClrType() to convert to other
.NET/CLR types. See asClrType() documentation.
Use asClrType() to convert to other
.NET/CLR types. See asClrType() documentation.
Use asClrType() to convert to other
.NET/CLR types. See asClrType() documentation.
Use asClrType() to convert to other
.NET/CLR types. See asClrType() documentation.
Use asVariantBool() on any VEE data type that can be cast to an Int16, (UInt8, Int16,
Int32, Real32, Real64, Text). You may also use the more generic asClrType(), e.g., asClrType(veeArray,
System.Boolean).
VEE’s Date/Time is really of type Real64.
Use asClrType(veeDateTimeArray,
System.DateTime). See examples\ dotnet\DateTime.vee
.
VEE User’s Guide 299
7 Using .NET with VEE
Table 35 .NET Data Type Modifers
.NET data type modifiers ref, out, ByRef
VEE Type Notes
Either scaler or array of the type indicated by the mapping table above
Use the VEE keyword ByRef. Not using the
ByRef keyword will not cause a .NET operation exception, but the passed-in parameter will not be changed. This is probably not what the .NET class designer intended.
Calling an Instance Method
When calling an instance method, be sure to declare and create the .NET object first. It is recommended that you use the Function & Object Browser and the Create Instance button to generate the constructor formula template first.
Figure 173 illustrates an example.
In Figure 170, fileInfo is initialized as System.IO.FileInfo
object. You can wire the fileInfo output pin to the input pin of any subsequent formula boxes that require this object instance. Also note, that both the CreateInstance and fileInfo.LastAccessTime formula boxes are created by VEE automatically. All you need to do is wire them together and provide any additional parameters.
300
Figure 170 Creating a .NET Object and Accessing Its Instance Member
VEE User’s Guide
Using .NET with VEE 7
Calling a Shared/Static Method
When you call a .NET member, if the member is
Shared/Static, the word STATIC appears in the Function &
Object Browser description box. Static methods are called on a .NET class directly, not on an object. Thus, you do not
need to create a .NET object first. Figure 171 illustrates an
example.
Figure 171 Static Method without Namespace Imported
If you imported the namespace System.IO, the above formula
template looks like Figure 172:
VEE User’s Guide
Figure 172 Static Method with an Imported Namespace
.NET Programming Tips
• If you are calling a .NET method requiring a certain numeric data type where the parameter comes from an input pin, say 'A', you can often eliminate a 'Method Not
Found' exception by simply double- clicking the input pin
A, and setting the required type to match. This is easier than calling the built- in asClrType function or the .NET
System.Convert.To* functions.
301
7 Using .NET with VEE
302
• The formula template generated for Instance members always begins with a lower case letter. Static members have a fully qualified name (namespace plus classname) unless their namespace has been imported.
• When you call a .NET member, if the member is Static the word STATIC appears in the description box. Static methods are called on a .NET class directly, not on an instance of an object. Thus, you do not need to create a
.NET object first.
• Enums in .NET are different from enums in COM. They are strongly typed. There are two types of enums in .NET, one is treated as an enumeration of constants, the other is treated as bit fields. Only the latter type of enums are intended for bitwise operations. In VEE, both types of enums will have their underlying integral value displayed in the description area of the Function & Object Browser.
You can use bitOr, bitAnd, etc. on the latter type of enums as in the VEE example, examples\dotnet\
FileAttributes.vee.
• There is a new Copy to Clipboard button in Function &
Object Browser. You can use this button to copy a formula text into the clipboard, and later paste it anywhere in a formula box. This is especially useful when you want to have multiple formula statements inside of one formula box.
Lab 7-1: Using .NET to Select Files
Create a .NET object of the type
Systems.Windows.FormsOpenFileDialog. Use this object to filter a group of files by file extension and display the filenames in a dialog box. The complete example can be found in examples\dotnet\OpenFileDialog.vee.
1 From the Device menu, select .NET Assembly References.
2 From the .NET tab, select the System.Windows.Forms checkbox. Choose OK.
3 Open the Function & Object Browser and select .NET/CLR
Objects.
4 Highlight the System.Windows.Forms namespace.
VEE User’s Guide
Using .NET with VEE 7
5 Highlight the OpenFileDialog Type and the Constructor
Member. Select Create Instance.
VEE User’s Guide
Figure 173 Function & Object Browser Creating an Instance
6 Declare a global variable named openFileDialog and set its type to Object.
7 Since you have declared openFileDialog as a global variable, delete the openFileDialog output pin from the
CreateInstance formula box.
8 Change the title of the
CreateInstance(“System.Windows.Forms”,
303
7 Using .NET with VEE
“System.Windows.Forms.OpenFileDialog”) Formula object to
Open File Dialog. Within the object do the following steps:
a Set the directory where the program will open the dialog box.
b Set the openFileDialog property Multiselect to True.
(Tip: You will need asVariantBool or asClrType to get
System.Boolean). This lets you choose multiple files from the Open File Dialog Box.
c Set up the file extension filter, in this case DLL files.
d Call the openFileDialog method, ShowDialog, and display the dialog box.
e Call the openFileDialog property, FileNames, and retrieve the list of DLL files you have selected. This list will appear in the Logging Alphanumeric object.
The program should look like Figure 174.
304 VEE User’s Guide
Using .NET with VEE 7
VEE User’s Guide
Figure 174 openFileDialog Program
Lab 7-2: Using .NET to Perform DateTime Operations
Use both instance and static members of the .NET type
DateTime. .NET’s DateTime type provides more functionality than VEE’s DateTime functions. This exercise uses the
DateTime type to get the current DateTime, current day of
305
7 Using .NET with VEE
306 the week, current year, and to query whether it is a leap year. The complete example is found in examples\dotnet\
DateTime.vee
.
1 Select Device
⇒ .NET Assembly References.
2 From the .NET tab, select the mscorlib checkbox. Choose
OK.
3 In the Import .NET Namespaces dialog box, select the System checkbox. Choose OK.
4 Open the Function & Object Browser and select .NET/CLR
Objects.
5 Highlight the System namespace.
6 Highlight the DateTime type and the static property Now.
Choose the Create Get Formula button. Since this is a static member, you do not need to create or get an instance of the DateTime obect first.
7 Repeat steps 4 and 5, highlight the DateTime type. Note that there are multiple versions of the ToString methods.
Highlight the simplest version, the one requiring no parameters. Choose the Create Call button.
8 Wire the result pin of DateTime.Now formula box to the dateTime input pin of the dateTime.ToString() formula box.
9 Add an Alphanumeric and wire it to the output pin of the
dateTime.ToString() formula box.
10 Repeat step 4 and 5, highlight the DateTime type and the property DayOfWeek. Click the Create Get Formula button.
The DayOfWeek property returns another .NET object of type System.DayOfWeek. Since every .NET object has a
ToString() method, you can use it to format and print out the day of the week. So, edit the formula you just created with VEE by appending “.ToString()” before the semicolon.
11 Wire the result pin of the DateTime.Now formula to the dateTime input pin of the dateTime.DayOf Week formula box.
12 Add an Alphanumeric and wire its input pin to the output pin of the dateTimeDayOfWeek formula box.
VEE User’s Guide
Using .NET with VEE 7
VEE User’s Guide
Figure 175 Step 10 of Lab 7-2
13 Repeat step 4 and 5, highlight the DateTime type and the property Year. Choose the Create Get Formula button.
14 Wire the result pin of DateTime.Now formula box to the dateTime input pin of the dateTime.Year formula box.
15 Add an Alphanumeric and wire its input pin to the output pin of the dateTime.Year formula box.
16 Repeat step 4 and 5, highlight the DateTime type and the static method IsLeapYear. Choose the Create Call button.
Since this is a static method, you do not need to create or get an instance of the Datetime object.
17 Wire the Result pin of dateTime.Year formula box to the year input pin of DateTime.IsLeapYear formula box.
18 Add an Alphanumeric and wire its input pin to the output pin of the DateTime.IsLeapYear formula box.
The completed Lab is shown in Figure 176
307
7 Using .NET with VEE
308
Figure 176 Lab 7-2 Completed
VEE User’s Guide
Using .NET with VEE 7
VEE User’s Guide
Lab 7-3: Using .NET to Get File Information
The .NET System.IO namespace provides a tremendous amount of functionality for dealing with the file system. This functionality is more accessible than ever. In this exercise, you will query a file about its creation time, last access time, and length. The complete example is in examples\dotnet\
FileInfo.vee
.
1 Choose Device ⇒ .NET Assembly References.
2 From the .NET tab, select the mscorlib checkbox. Choose
OK.
3 If the Import .NET Namespaces dialog box comes up, you may check the System namespace, or just choose Cancel. In this
Lab, you do not use any static or enum members, but in the complete example, you do.
4 Open the Function & Object Browser and select .NET/CLR
Objects.
5 Highlight the System.IO namespace.
6 Highlight the FileInfo Type and the Constructor member.
Choose the Create Instance button. Take a look at the generated formula template. Note that an output pin named fileInfo is created by VEE, and it is set to a newly created FileInfo object.
7 Choose Data
⇒ Dialog Box ⇒ File Name Selection. Wire the
File Name output pin to the fileName input pin of the Create
Instance formula box. Iconize the File Name Selection object.
8 Repeat step 4 and 5, highlight the FileInfo type. Highlight the CreationTime property. Click the Create Get Formula button. Since the CreateTime property returns a .NET
DateTiime object, you will use its ToString() method to format and print out the creation time. So, append
“.ToString()” after the formula generated by VEE. Be sure to append it before the semicolon.
9 Wire the fileInfo output pin from the CreateInstance formula box to the fileInfo input pin of fileInfo.CreationTime formula box.
10 Add an Alphanumeric and wire it to the output pin of the
fileinfo.CreationTime formula box.
309
7 Using .NET with VEE
11 Repeat steps 8 and 9 to create and wire the formula box for the fileInfo.LastAccessTime property.
12 Add an Alphanumeric and wire it to the output pin of the
fileinfo.LastAccess formula box.
13 Repeat steps 8 and 9 to create and wire the formula box for the fileInfo.Length property.
14 Add an Alphanumeric and wire it to the output pin of the
fileinfo.Length formula box.
The complete Lab should look like Figure 177
310
Figure 177 Completed Lab 7-3
VEE User’s Guide
Using .NET with VEE 7
.NET and IVI Drivers
VEE User’s Guide
What is IVI? IVI is a new instrument driver standard being developed by the IVI Foundation. The IVI Foundation is a consortium established to promote specifications for programming test instruments. These specifications provide multiple benefits but primarily make instrument interchangeability simpler. For a review of the IVI
Foundation, go to http://www.ivifoundation.org/.
Why would you want to use an IVI- COM driver? Assume two hardware vendors provide an IVI- COM driver for each of their DMM’s. To meet the IVI standard, the base drivers must be interchangeable. This means that if you start with one vendor’s DMM and matching driver, you can switch to the other vendor’s DMM and driver with no other changes to your program. Your code is reusable without any intervention.
Install the IVI- COM drivers when necessary. To find drivers for your instruments, go to http://www.agilent.com/find/adn.
If you are an ADN member, select Downloads from the menu
⇒ Drivers by Driver Type ⇒ IVI-COM Drivers and Components. If you are not an ADN member, it is an online source for Agilent drivers, evaluation software, documentation, and white papers. To sign up for this free service, fill out the online registration form for new users.
Once the IVI- COM drivers are registered on your system, they are available just like any other COM component and, like most COM components, will appear on the COM tab of the Device
⇒ .NET Assembly References in VEE.
How do VEE and .NET make IVI- COM drivers available? Via
.NET’s COM interop, the IVI- COM drivers become available to VEE. If there isn’t a primary interop assembly available for a COM DLL that you select, VEE attempts to generate an interop assembly (or more than one if the COM .dll references other type libraries). After the interop assembly is referenced, the IVI- COM driver can be invoked just like any
.NET object.
311
7 Using .NET with VEE
For further information about IVI- COM, connect to www.agilent.com/find/adn. Login in, go to the Knowledge
Library, and choose IVI- COM information. There are many white papers at this location.
312 VEE User’s Guide
Using .NET with VEE 7
Assemblies
Installing a New Assembly
Assemblies are the basic building blocks of the .NET
Framework. They take the form of an executable (.exe) or dynamic link library (.dll) file.
Assemblies may be installed in the Global Assembly Cache
(GAC). You will need the appropriate privileges and need to use extra caution as the GAC is a machine wide resource.
The assemblies installed in the GAC are seen by all the applications on your computer. (Please refer to MSDN for more details.) Once the shared assembly is updated, you can reference it by choosing the Browse button and browsing to the original location of the assembly before it was installed in the GAC.
Most assemblies are not installed in the GAC. They are called private assemblies. A private assembly should be located with the VEE program that references it. The first time you use the .NET Assembly References dialog box to browse and select a private assembly, VEE will copy it over to the same directory as your current VEE program if it is not already located there. This copying also makes distributing your VEE program easier and is known as xcopy deployment.
Updating an Assembly
If you have already referenced the shared assembly in your
VEE program, you need to do a File/New or restart VEE again before the new version of the shared assembly will be loaded by VEE. If it is not a shared assembly but a private assembly, you need to do a File/New or restart VEE after manually copying the new version of the private assembly into your current VEE program directory. See the section
“Distributing the VEE Runtime" on page 314 for additional
information.
VEE User’s Guide 313
7 Using .NET with VEE
Distributing the VEE Runtime
If your VEE program references shared assemblies (the ones installed in the GAC), you will need to install those assemblies to the destination machine's GAC. If the shared assembly is a Microsoft .NET Framework assembly, then the assembly should have been installed when the Microsoft
.NET Framework redist package was installed.
N O T E
The .NET Framework redist package needs to be installed before installing the VEE Runtime.
VEE saves any referenced, private assemblies with the VEE program. If your VEE program only references private assemblies, you can simply copy the entire VEE program directory over to the destination machine. This is much easier than distributing VEE programs that reference COM type libraries where you must register all of the COM type libraries on the destination machine.
314 VEE User’s Guide
Using .NET with VEE 7
VEE and .NET Security
VEE’s use of the .NET Framework introduces one security issue. If you see the following dialog box, make the following adjustments to your .NET Framework security profile:
VEE User’s Guide
1 Go to your system drive
2 Go to directory \[winnt or windows]\Microsoft.NET\
Framework\v1.1.4322
3 From the command prompt run the following command:
Caspol –machine –addgroup “All_Code” –url
File://[VEEInstallDir]/* FullTrust
The VEEInstallDir is your VEE installation directory on a network drive. (Caspol ships with the .NET Framework
Redist package and is installed when VEE is installed). You can also run the .NET Framework Configuration Wizard to achieve the same result. You must have administrative privileges to run either tool.
In addition to this, if your VEE program references .NET assemblies, VEE often needs to generate and/or save assemblies to an accessible location. So, for example, if you open a VEE program (with .NET references) from email or a network without saving locally first, you might get a warning.
315
7 Using .NET with VEE
.NET Terminology
Assembly
“Components are packaged in assemblies. Assemblies are the reusable, versionable, self- describing building blocks of .NET applications. The simplest assembly is a single executable that contains all the information necessary for deployment and versioning. An Assembly is the fundamental building block of the .NET Framework. It takes the form of an executable (.exe) or dynamic link library (.dll) file.”
Primary Interop Assembly (PIA)
“A primary interop assembly is a unique, vendor- supplied assembly that contains type definitions (as metadata) of types implemented with COM. There can be only one primary interop assembly, which must be signed with a strong name by the publisher of the COM type library.”
Namespace
You will find these terms throughout the chapter, so use these Microsoft definitions as a resource while you read or you can review them now.
“.NET Framework types use a dot syntax naming scheme that connotes a hierarchy. This technique groups related types into namespaces so they can be searched and referenced more easily. The first part of the full name — up to the rightmost dot — is the namespace name(*). The last part of the name is the type name. For example,
System.Collections.ArrayList represents the ArrayList type, which belongs to the System.Collections namespace. The types in System.Collections can be used to manipulate collections of objects.”
*Nested classes are an exception to this general rule. Please see MSDN documentation for further details.
316 VEE User’s Guide
VEE User’s Guide
Using .NET with VEE 7
Reference
To use an Assembly, you must add a reference to it.
Class
“If you are familiar with object- oriented programming, you know that a class defines the operations an object can perform (methods, events, or properties) and defines a value that holds the state of the object (fields). Although a class generally includes both definition and implementation, it can have one or more members that have no implementation.
An instance of a class is an object. You access an object's functionality by calling its methods and accessing its properties, events, and fields.”
Shared or Static Members
“Shared members are properties, procedures, and fields that are shared by all instances of a class. Some programming languages refer to such items as static members.
Shared fields and properties are useful when you have information that is part of a class, but is not specific to any one instance of a class. Normal fields and properties exist independently for each instance of a class. Changing the value of a field or property associated with any one instance does not affect the value of fields or properties of other instances of the class. On the other hand, when you change the value of a shared field and property associated with an instance of a class, you change the value associated with all instances of the class. In this way, shared fields and properties behave like global variables that can be accessed only from instances of a class.”
Instance Member
An instance member is tied to a specific instance of a class.
Changes to its value affect the object it is associated with and no other objects.
317
7 Using .NET with VEE
Chapter Checklist
You should now be able to perform the following tasks.
Review topics, if necessary, before proceeding to the next chapter.
• Know the basic terminology of .NET
• Know how to import a namespace into VEE
• Define a PIA
• Know how to distribute the VEE Runtime
• Know how to adjust .NET security to accomodate VEE
318 VEE User’s Guide
Integrating Programs for the PC Chapter 8
8
Integrating Programs for the PC
Understanding the Execute Program Object 322
VEE User’s Guide 319
8 Integrating Programs for the PC Chapter
Integrating Programs In Other Languages
In this chapter you will learn about:
• The Execute Program object
• Using operating system commands from VEE
• Making VEE programs portable across platforms
Average time to complete: 30 minutes
320 VEE User’s Guide
Overview
Integrating Programs for the PC Chapter 8
In this chapter, you will learn the easiest way to integrate compiled programs and operating system commands with VEE.
One of the great advantages of VEE is that it integrates well with other applications and programs. Furthermore, by using
ActiveX, you can use components from other programs. (For
more information, refer to the Chapter , “Creating Reports
In VEE, the Execute Program object specifies programs and parameters and uses operating system commands. There is an
Execute Program object for the PC. This chapter includes a lab exercise with the Execute Program object for PC.
VEE User’s Guide 321
8 Integrating Programs for the PC Chapter
Understanding the Execute Program Object
In addition to ActiveX Automation, there are three ways to run programs in other languages from VEE:
1 Use the Execute Program object to escape VEE and run another program, application, or operating system command.
This method is the most versatile and easy to use.
2 Link compiled functions in other languages to VEE through
Dynamic Link Libraries on the PC. Although this is slightly more difficult to execute, it gives you significant performance gains. For more information about Dynamic Link Libraries,
refer to “Using Dynamic Link Libraries" on page 453.
The Execute Program object is located in the I/O menu. There
is one object for the PC, as shown in Figure 178. Notice that
the Execute Program object does not use transaction I/O to communicate with programs, so you do not add data input and output pins to pass data to the compiled program.
Using the Execute Program Object
Execute Program Object on the PC.
322
Figure 178 The Execute Program Object (PC)
Use the Execute Program object to run the following from VEE:
• Compiled programs written in other languages
• *.BAT or *.COM files
• MS DOS system commands, such as dir
VEE User’s Guide
VEE User’s Guide
Integrating Programs for the PC Chapter 8
• Any document or URL with a recognized extension. The
“open” action is invoked in the files. If an “open” action does not exist, the default action is invoked with the file. An example of a URL would be http://www.agilent.com/find/vee.
The fields in the Execute Program Object are:
Table 36 Execute Program Object Fields
Field Name
Run Style
Description
Determines the window size. Normal specifies a standard window, Minimized specifies an icon, and Maximized specifies the maximum window size. The Working directory is the directory that holds any files related to the program.
Wait for prog exit Specifies when to fire the sequence pin.
• When set to Yes, the sequence pin is not fired until the program finishes executing.
• When set to No, the sequence out pin fires before the specified program is done executing.Note that when launching documents or URLs, if the document or web site is loaded into an application that is already running,VEE does not wait until the application exits.
Prog with params (Program with parameters) This field holds the same words you would type at a DOS prompt. For example, to run a program in C, enter the executable file name
- myprog.exe
. (You can omit the
.exe
extension.)
• If the program has parameters, they would follow the executable file name preceded by a hyphen, such as myprog -param1 -param2 .
• To run a DOS system command, first run the DOS command interpreter with the
/c
option. For example, for Windows 98, enter the command command.com
/c <system command>.
• For Windows NT 4.0, Windows 2000, and Windows XP, enter the command cmd /c <system command>
This option tells the command interpreter to read the string following the /c as a system command.
323
8 Integrating Programs for the PC Chapter
Using a System Command
To call a compiled program in another language, you can type in the executable file and any parameters in the Execute
Program object.
However, to execute an MS DOS system command, you must first run the DOS command interpreter. In this exercise, you will run the DOS command interpreter and execute an MS DOS system command.
Lab 8-1: Using a System Command
1 Select I/O
⇒ Execute Program. Click the Prog with params field to get a cursor, then type: command.com /c dir >> c:\bob
N O T E
Replace command.com with cmd for Windows NT 4.0, Windows 2000, or
Windows XP. If the drive letter is different from c:, then substitute that drive letter in these instructions. On NT, you may have to specify a directory for which you have write permissions.
(You may need to include the complete path of the
command.com executable.) The command runs the DOS command interpreter, which runs the system command to display the current directory, and redirects the output ( >) to the bob file instead of the computer screen.
Leave Yes for the Wait for prog exit selection. Leave Normal for Run Style, and enter c:\ for the Working directory.
2 Select I/O ⇒ From ⇒ File and place it below Execute
Program. Connect the sequence out pin of Execute Program to the sequence in pin of the From File object.
Click the From File: input field labeled myFile to get a list box, enter c:\bob, then click OK. (The program creates the file
bob for you.)
324 VEE User’s Guide
Integrating Programs for the PC Chapter 8
3 Double- click the transaction bar to get the I/O Transaction box.
a Change REAL64 FORMAT to STRING FORMAT.
b Change SCALAR to ARRAY 1D.
c Click on the SIZE : (10) field to toggle it to TO END: (*), then click OK. The transaction bar should now read: READ
TEXT x STR ARRAY:* . This transaction will read the contents of the bob file.
4 Select Display ⇒ Logging AlphaNumeric and connect its data input pin to the From File data output.
5 Run the program. It should look like Figure 179.
VEE User’s Guide
Figure 179 Listing the Files in a Directory
325
8 Integrating Programs for the PC Chapter
Writing Programs That Port Easily
If you plan to integrate programs in other languages, write the VEE programs so they port easily to other operating systems. VEE includes system information objects in Function
& Object Browser
⇒ System Information, as shown in Figure 180.
These objects can also be used as functions.
326
Figure 180 System Information Functions
The system information functions in the Function & Object
Browser that are commonly used to enhance program portability are as follows:
VEE User’s Guide
VEE User’s Guide
Integrating Programs for the PC Chapter 8
Table 37 System Information Functions
Function Name installDir whichOS whiclatform whichVersion
Description
Specifies the VEE installation directory.
Determines the operating system and sends out one of the following strings: Windows_98 , Windows_2000 ,
Windows_NT , Windows XP.
The program can branch based on these results when incorporating programs in other languages. For example, look at manual49.vee
in the examples\manual directory to see a program that uses whichOS() to make sure it imports the right type of library. On a PC, it would import a Dynamic Link Library.
Determines the hardware system on which VEE is running, then returns a string indicating that platform.
Specifies the VEE version, which is useful for program maintenance and debugging.
327
8 Integrating Programs for the PC Chapter
Chapter Checklist
You should now be able to perform the following tasks. Review topics, if necessary, before going on to the next chapter.
• Explain the purpose of the Execute Program object.
• Give an overview of the configuration settings on the Execute
Program object.
• Explain the general process of how the Execute Program object sends data to/from a program on a PC platform.
• Run operating system commands from VEE.
• Create a program that will use the whichOS(), whichplatform(), or whichVersion() object so that it will run on different operating systems.
328 VEE User’s Guide
Using Agilent VEE Functions Chapter 9
9
Using Agilent VEE Functions
Using Libraries With Agilent VEE UserFunctions 344
Finding Functions in Large Programs 356
Merging Agilent VEE Programs 358
VEE User’s Guide 329
9 Using Agilent VEE Functions Chapter
Using Agilent VEE Functions
In this chapter you will learn about:
• Defining a user function
• Creating, calling, and editing functions
• Creating, merging, importing, and deleting function libraries
• Finding functions in large programs
• Merging existing VEE programs with tests
Average Time to Complete: 1 hour
330 VEE User’s Guide
Overview
Using Agilent VEE Functions Chapter 9
In this chapter, you will learn about VEE UserFunctions , compiled functions, and remote functions. Functions are re- usable, modular code that can help you significantly reduce the time it takes to develop tests. By re- using functions that have been created in previous programs, you can leverage existing work, reduce the code size of programs, and make it easier to maintain test programs. You can also use functions in groups, as libraries, which you can create and then merge into new programs. You can share functions among multiple programs and multiple developers.
VEE User’s Guide 331
9 Using Agilent VEE Functions Chapter
Using Functions
Like many programming languages, VEE uses functions to create subprograms that perform specific tasks. The lab exercises in this chapter describe how to create, call, and edit
VEE user- defined functions. You will also learn how to create libraries of functions, which can be merged into programs in the development phase or imported at runtime.
Defining an Agilent VEE Function
There are three types of user- defined functions in VEE. The overview of each type of function is as follows:
1 UserFunctions
• To create a UserFunction, you select Device ⇒
UserFunction, or click Edit ⇒ Create UserFunction with several objects selected.
• To call a UserFunction from different places in a program, you use the Call myFunction (Device
⇒ Call) object or use an expression within an object (from Formula, for example).
You can also generate call objects in the Main program from the UserFunction, using the UserFunction object menu and selecting choices such as Generate ⇒ Call.
• To edit a UserFunction, you click on Edit ⇒ Edit
UserFunction ... and select the appropriate UserFunction from the list box presented.
• To transfer UserFunctions from one program to another, you merge the UserFunctions during program development or import them at runtime ( Device ⇒ Import
Library).
2 Compiled Functions
• To create a compiled function, you work outside of VEE using a compiled language. You then put the functions into a library, such as a DLL.
• To link a compiled function to a program, you use the
Import Library object, which links the library to VEE at run time. (For a more detailed discussion, refer to
Chapter 12, “Optimizing Agilent VEE Programs).
332 VEE User’s Guide
VEE User’s Guide
Using Agilent VEE Functions Chapter 9
• To call a compiled function, you use the Call myFunction object or write an expression within a VEE object.
3 Remote Functions
• Similar to UserFunctions, except that they run on a remote host computer connected on your network.
The Differences Between UserObjects and UserFunctions
In previous chapters, you have already created and used
UserObjects. The reason that VEE provides both UserObject and
UserFunction is because the two have different characteristics and can therefore be used for different purposes. Here are the differences between a UserObject and a UserFunction:
A UserObject (located in Device ⇒ UserObject) is an object you define that may be used just like any other object in VEE. You program a UserObject like a subprogram but it graphically remains on the screen. If you want to use it elsewhere in a program, you must clone it and maintain all copies. Note that if you clone a UserObject many times, it makes the program larger and slower to load. If you add a feature to one UserObject, you would need to add the same feature to all the other UserObjects if you want them to remain identical.
With a UserFunction (located in Device ⇒ UserFunction), there is just one copy of the subroutine in memory, and it is only displayed graphically in the workspace in its own window if you want it to be. Otherwise, it is stored to be called from the Call object or any other expression field. Changes to a UserFunction will be inherited by all instances in the program that call that
UserFunction. You can also create libraries of UserFunctions for more code re- use.
Lab 9-1: UserFunction Operations
This exercise describes how to create a UserFunction named
ArrayStats, which will accept an array, calculate its maximum value, minimum value, mean, and standard deviation, and put the results on its output pins.
333
9 Using Agilent VEE Functions Chapter
Creating a UserFunction
1 Select Device ⇒ Formula, delete its default input pin, and change its default expression to ramp(1024,1,1024).
This will create a 1024 element array with values from 1 to 1024.
2 Select Device
⇒ UserFunction. Rename it ArrayStats.
a Add one data input terminal for the array
b Add four data output terminals for the results.
c Rename the output terminals: Max, Min, Mean, and
Sdev . Select max, min, mean, and sdev from the
Probability & Statistics category in the Function &
Object Browser box.
d Place them in ArrayStats, and connect their data inputs to A and their data outputs to the appropriate output terminals. Make the ArrayStats window smaller to see
both of the Main and ArrayStats windows. See Figure
334 VEE User’s Guide
Using Agilent VEE Functions Chapter 9
Figure 181 The Main and ArrayStats Windows
3 Iconize ArrayStats. It appears as an icon at the bottom of the workspace.
4 Click Device ⇒ Call, open the object menu, and click
Select Function as shown in Figure 182. Then click
OK.
Notice that VEE renames the object automatically and adds the correct pins.
VEE User’s Guide
Figure 182 Configuring the Pins for Call myFunction
5 Connect the output of Formula to the Call ArrayStats input. Select Display ⇒ AlphaNumeric, clone it three times, and connect the displays to the Call ArrayStats output pins. Rename the displays.
6 Run the program. It should look like Figure 183. Save the
program as array_stats.vee.
335
9 Using Agilent VEE Functions Chapter
336
Figure 183 Calling the User Function ArrayStats
To use ArrayStats elsewhere in the program, you would click on Device ⇒ Call, open the Select Function box from the object menu, and choose ArrayStats. VEE would automatically rename the object Call ArrayStats, and add the necessary input and output terminals.
From the UserFunction object menu, select Generate ⇒ Call to bring up the Call ArrayStats object. (Make sure that the
UserFunction is not expanded to the whole workspace when doing this.)
Editing a UserFunction
In this exercise, edit ArrayStats to deliver a record with four fields giving the array statistics.
1 Delete the four AlphaNumeric displays.
2 Select Edit ⇒ Edit UserFunction... and select ArrayStats from the Edit UserFunction list box. All of the
UserFunctions in the program are displayed.
3 Open the ArrayStats object menu, click on size, and enlarge the editing window. If you need to resize objects, click and drag any corner of the object.
4 Delete the four lines going to the output terminals. (Press
Ctrl-Shift and click on the line you want to delete.)
VEE User’s Guide
Using Agilent VEE Functions Chapter 9
5 Select Data ⇒ Build Data ⇒ Record and place it to the right side of the ArrayStats window.
a Add two data input terminals.
b Label the four terminals after the statistical functions: max, min, mean, and sdev.
c Connect the four Formula object outputs to the inputs on Build Record.
d Rename the Max output terminal X by double- clicking
Max, typing the new name, and clicking OK.
e Delete the other ArrayStats data output terminals.
f Connect the Build Record output to the X output terminal on the User Function editing window. The
program should look like Figure 184. Then click the
iconize button on the window.
VEE User’s Guide
Figure 184 Editing the UserFunction ArrayStats
6 Open the Call ArrayStats object menu and click Configure
Pinout. This will adjust the number of pins to match the recent edits.
337
9 Using Agilent VEE Functions Chapter
N O T E
I n order to update the number of pins, you must open the object and click
Configure Pinout whenever you change the number of inputs or outputs in a UserFunction. Or you can manually update the Call object’s input and output pins, but using Configure Pinout is much simpler. You can use Find to find all the Call objects and expressions that call a UserFunction. For
more information, refer to “Finding Functions in Large Programs" on page 356.
Now display a record using the Record Constant object. Use the Default Value control input to accept a record from
ArrayStats. VEE automatically configures the Record
Constant to hold the incoming record.
7 Select Data
⇒ Constant ⇒ Record and place it to the right of the Call Function object.
a Open the Record object menu and click Add Terminal ⇒
Control Input .... Select Default Value from the list box presented. You can open the Properties menu to Show
Terminals, if you wish.
b Now connect the Call Function data output to the control input pin on the Record object. Notice that control lines are indicated by dashed lines to differentiate them from data lines.
8 Run the program. It should look like Figure 185.
338
Figure 185 After Editing ArrayStats Output to a Record
VEE User’s Guide
Using Agilent VEE Functions Chapter 9
Calling a UserFunction from an Expression
In this exercise, you will learn how to call ArrayStats from an expression in the Formula object.
1 Select Device
⇒ Formula and replace the default formula with ArrayStats(A). Click Replace in the Call ArrayStats object menu.
The Status Bar at the bottom of the VEE screen prompts you to select the replacement object. Click on the Formula object that calls the ArrayStats function. VEE automatically replaces the Call ArrayStats object with the new Formula object and retains the wiring of the data lines.
The Formula object takes the input at terminal A and sends it to the UserFunction ArrayStats. ArrayStats delivers the record of statistics to its terminal X. The first output value from the UserFunction (X) is returned to the
Formula object and delivered to its Result output.
2 Run the program. It should look like Figure 186.
VEE User’s Guide
Figure 186 Calling the ArrayStats User Function
339
9 Using Agilent VEE Functions Chapter
N O T E
Notice that the functionality of ArrayStats in the Formula object is exactly the same as it was in the Call ArrayStats object. This example uses a Formula object, but you could call ArrayStats from any input field that accepts expressions, such as the To File object.
When you call a UserFunction from an expression, the UserFunction will only deliver a single output (the uppermost data output pin). If you need all of the outputs, or they cannot be put into a Record, then use the Call
Function object.
N O T E
When you call a UserFunction from an expression, input terminals are used as function parameters to pass to the function. If no data is passed to the function, you must still include empty parentheses after the function name. Otherwise, VEE assumes you are referring to a Global variable or input terminal. For example, if the UserFunction called MyFunction has no input parameters, you must write MyFunction() in an expression. The Call object does not require the parentheses, because VEE knows you are referring to a function
.
Generating a Call to a UserFunction
To generate and place a call object in the Main program from a UserFunction, use the UserFunction object menu
Generate menu. The Generate menu contains most of the common objects that call a UserFunction. When you select a calling object, it can be placed in the calling window, such as the Main program, properly configured with the correct name and pins.
340 VEE User’s Guide
Using Agilent VEE Functions Chapter 9
In this exercise, you will learn how to generate the
ArrayStats object in the Main program from the ArrayStats
UserFunction.
1 In the same example used in Figure 186, double- click the
Formula object ArrayStats to delete the object. (You could also select the object menu and select Cut.)
2 In the UserFunction ArrayStats, select the object menu and select Generate
⇒ Formula Call. Figure 187 shows the
Generate menu in a UserFunction object menu.
VEE User’s Guide
Figure 187 The Generate Menu in a UserFunction
3 Place the object in Main. Notice that VEE automatically names the new object ArrayStats(A) and includes the expression ArrayStats(A) to call the UserFunction ArrayStats.
341
9 Using Agilent VEE Functions Chapter
4 Connect the output from the Formula object to ArrayStats(A), and connect the output from ArrayStats(A) to Record.
5 Run the program. It should look like Figure 188.
Open a UserFunction object menu and select the Generate menu to review the other objects that can be placed into a program to call a UserFunction. They include Call, Formula Call (used in this example), If/Then/Else Call, ShowPanel, and HidePanel objects.
342
Figure 188 Generating a Call Object ArrayStats(A) from a UserFunction
UserFunctions and the Program Explorer
UserFunctions and UserObjects make VEE programs more modular and easy to understand. The Program Explorer is a valuable tool for navigating through complex programs. For
example, the hierarchy of the program in Figure 189 is
shown in the Program Explorer. To display the Program
Explorer, click View
⇒ Program Explorer or click the Program
Explorer icon on the toolbar.
VEE User’s Guide
Using Agilent VEE Functions Chapter 9
Program Explorer
Figure 189 Program Explorer Icon on the Toolbar
Figure 190 shows the Program Explorer being used.
VEE User’s Guide
Figure 190 Using the Program Explorer with UserFunctions
343
9 Using Agilent VEE Functions Chapter
Using Libraries With Agilent VEE UserFunctions
To leverage existing VEE test programs, you can re- use
UserFunctions. When you save a program, the UserFunctions are automatically saved as well. A UserFunction can hold a VEE program or a library of logically related UserFunctions.
There are two ways to put existing UserFunctions into a new program:
Put a copy of the original UserFunctions into the current program, using the File ⇒ Merge Library... command (where you now maintain the separate copy of each UserFunction).
These merged UserFunctions can be edited, so use the File ⇒
Merge Library ... command when you plan to modify the
UserFunctions.
- OR-
Access the original UserFunctions using the Device ⇒ Import
Library object, which accesses the original functions in another file without making a copy. These UserFunctions are imported at run time. This spreads out the load times, conserves disk space, and saves memory. Imported UserFunctions can be viewed (such as for debugging purposes) but cannot be edited.
Instead, you can edit their original files. You can also delete imported UserFunctions programmatically, using the Device ⇒
Delete Library object.
Therefore, merge UserFunctions when you need a new copy of the function to modify or you need a standalone program, and
import UserFunctions when you want a single source for the function or you want to save space.
Lab 9-2: Creating and Merging a Library of UserFunctions
In this exercise, you will create a report generation program that includes a VEE library of UserFunctions. Then you will create a new program that merges the library of UserFunctions.
344 VEE User’s Guide
Using Agilent VEE Functions Chapter 9
Creating a Library of UserFunctions
1 Create the top level program (without programming the details of the UserFunctions).
a Create four UserFunctions: BuildRecAry with one output pin, ReportHeader, ReportBody with one input pin, and ReportDisplay. Iconize all the UserFunctions.
b In Main, create four Device ⇒ Call objects configured
and connected as shown in Figure 191. Save the
program as Report.vee.
VEE User’s Guide
N O T E
Figure 191 Report.vee from the Top Level
The Call object does not require parentheses when referring to a
UserFunction. If you were calling the function from a Formula object, you would need to include parentheses whether or not the function used parameters.
345
9 Using Agilent VEE Functions Chapter
The four UserFunctions are a library. You can see them listed by clicking Edit ⇒ Edit UserFunction.... Click Cancel to close the list box.
2 Program the four UserFunctions as shown in the following figures.
BuildRecAry UserFunction. It includes a Formula object with the triadic expression testing if
A<=5. If the expression evaluates to TRUE, then the object outputs "PASS". Otherwise, the object outputs "FAIL".
(Note that the parentheses are required.)
346
Figure 192 The BuildRecAry UserFunction
VEE User’s Guide
Using Agilent VEE Functions Chapter 9
ReportHeader UserFunction
.
VEE User’s Guide
Figure 193 The ReportHeader UserFunction
ReportBody UserFunction. Note the array of records A[B]. As the Value of B changes from 0 to
1 to 2, you can access the particular field in that Record, including Value, Limit, and PassFail, using the
<record>.<field> notation. Note that the For Count outputs start with zero. Note also that the first transaction has EOL off.
The vertical bar in quotes, "|", represents a constant string character for a vertical bar. FW:5 stands for a string field width of 5. RJ stands for right justified.
347
9 Using Agilent VEE Functions Chapter
348
Figure 194 The ReportBody UserFunction
Figure 195 shows the ReportDisplay
UserFunction in detail view. Note that it reads a string array to the end of the file, specified by the asterisk sign ( *) after the STR ARRAY format.
VEE User’s Guide
Using Agilent VEE Functions Chapter 9
VEE User’s Guide
Figure 195 The ReportDisplay Detail View
Figure 196 shows the panel view of the ReportDisplay
UserFunction with Show Panel on Execute selected in the
Properties box. In the Properties box, the Pop- up Panel Title has also been changed to ReportDisplay. To create the panel, select the Confirm (OK) and Logging AlphaNumeric objects, and click
Edit
⇒ Add to Panel. Note that the Logging AlphaNumeric display has Show Title Bar deselected. Note also that Confirm (OK) button has been renamed DONE. The Confirm (OK) button is included to keep the display on the screen until the user is done viewing it.
3 Run the program and the ReportDisplay panel should pop up
and display the values as shown in Figure 196. Click on
DONE to complete execution. Then save the program as
Report.vee.
349
9 Using Agilent VEE Functions Chapter
350
Figure 196 The ReportDisplay Panel View
Creating Another Program and Merging in the Library
In this exercise, you will create a new program and merge the library into it. This exercise builds a library of functions for generating reports. The new program contains a Note Pad object explaining each function in the library. It will be named
RepGen.
You could re- use RepGen by creating new report generation
User Functions, merging them with the program, and updating the Note Pad object to keep track of them. Then you could use the Merge Library... command to leverage all the functions from
RepGen.
1 Select File ⇒ New.
2 Select File ⇒ Merge Library.... Select Report.vee from the
Merge Library list box. (If you are in a different directory, type the whole file path.)
Select Edit ⇒ Edit UserFunction (or look at the Program
Explorer) to make sure the library from Report.vee transferred to the new program. When you use the Merge
Library... command, you can edit merged functions just like local functions.
VEE User’s Guide
N O T E
Using Agilent VEE Functions Chapter 9
3 Select Display
⇒ Note Pad and type the UserFunction
descriptions similar to the ones shown in Figure 197.
Then save the program as RepGen.vee.
You can save a “program” of UserFunctions for the purpose of creating a library, even though there is no actual VEE program calling the functions.
VEE User’s Guide
Figure 197 The RepGen.vee Library of UserFunctions
Lab 9-3: Importing and Deleting Libraries
Once you have created a library of UserFunctions, you may not want to merge them into every program. You might like to bring in the library at run time, use some of the functions, and then delete the library to conserve memory. The Import Library and
Delete Library objects are designed for this situation.
In this exercise, you will import functions from the RepGen program. Then you will call the BuildRecAry function to simulate some test data, display it, and finally delete the library to free up memory and swap space.
1 Select File
⇒ New.
2 Select Device
⇒ Import Library and place it in Main. Set the fields in the Import Library object as follows:
351
9 Using Agilent VEE Functions Chapter
N O T E
Table 38 Import Library Fields
Description Import Library
Fields
Library Type
Library Name
File Name
The menu in the Library Type field allows you to select a
UserFunction, a Compiled Function, or a Remote Function.
In this case you want a UserFunction library, so leave the default.
The Library Name shows myLib as a default. This name is used as a “handle” by the VEE program to distinguish between different libraries being imported. The Delete
Library object uses this name to identify the library to be deleted. You can use the default name.
The File Name field shows a dialog box for the user program directory by default. Specify the file that holds the library of functions.
Click the default name myFile to get the list box. Select
RepGen.vee
(from “Lab 9-2: Creating and Merging a
Library of UserFunctions" on page 344). This file will be in
the directory you specified for your programs during installation.
3 Open the object menu and select Load Lib to import the library immediately instead of waiting until runtime. This command is very useful in the development stage. (In the next step, you will notice that when choosing Select Function in the Call object, the functions are designated with the library handle first, such as myLib.BuildRecAry.)
To display the library of imported functions, use the Program
Explorer.
Because you have imported the library, you can only view the
UserFunction and set breakpoints for it. You cannot edit the UserFunction.
To add a UserFunction to a program that can be edited, use the Merge
Library... command.
352 VEE User’s Guide
Using Agilent VEE Functions Chapter 9
4 Select Device ⇒ Call and place it below the Import Library object. Connect the output sequence pin from Import Library to input sequence pin on the Call object.
5 Open the Call Function object menu and click Select
Function to show a list of the functions imported with the
Load Lib command. Select myLib.BuildRecAry as shown in
VEE User’s Guide
Figure 198 Selecting a Function from an Imported Library
VEE automatically inserts the function in the Function Name field and adds the required output terminal. You could also have entered myLib.BuildRecAry in the Function Name field to accomplish the same results. Use Select Function when you need to list the names of the functions in the library.
6 Select an AlphaNumeric display, enlarge it, and connect it to the Call data output.
353
9 Using Agilent VEE Functions Chapter
7 Select Device ⇒ Delete Library and place it below the Call object. Connect the sequence pins, so the library is deleted after the BuildRecAry function has been called. You can leave the default Library Name, since this is the same name you used with the Import Library object.
8 Run the program. It should look like Figure 199. Save the
program as libraries.vee.
354
Figure 199 Calling a Function from a Library
Note the following about names of merged and imported functions:
• If a merged function has the same name as a local function,
VEE displays an error.
• If an imported function has the same name as a local function, it is allowed, but the local functions are called if only the function name is used. You can explicitly call the imported function with the MyLib_func() syntax as in the
VEE User’s Guide
Using Agilent VEE Functions Chapter 9
• If two imported libraries have the same function names, the results will be indeterminate. Notice that the Call object uses the Library name myLib.BuildRecAry, so there is no confusion. Even if there were another local function or other imported function with the same name, this specifies the name and location of BuildRecAry.
VEE User’s Guide 355
9 Using Agilent VEE Functions Chapter
Finding Functions in Large Programs
VEE provides a Find feature located in the Edit menu to help you locate objects and text in a large program. For example, open the Solitaire.vee
program in the Examples\Games directory.
Go to the detail view and click Edit
⇒ Find... to display the
dialog box shown in Figure 200.
356
Figure 200 The Find Dialog Box
Type makeamove (a UserFunction in the Solitaire.vee program), as shown in the figure, and click Find. VEE automatically locates the UserFunction named makeamove and shows the part of the
program from which it was called, as shown in Figure 201.
VEE User’s Guide
Using Agilent VEE Functions Chapter 9
N O T E
Figure 201 The Find Results Dialog Box
You can use Find to locate any object or text such as variables, titles, settings on objects, etc. Double- click on any line in the
Find Results box to locate an object.
Find can also be used by placing the mouse pointer over objects in the
Program Explorer and clicking the right button. This will limit the scope of the search to the particular UserFunction or UserObject.
VEE User’s Guide 357
9 Using Agilent VEE Functions Chapter
Merging Agilent VEE Programs
The easiest way to leverage existing programs is to merge a past program with the current test. You can re- use programs by merging them and then editing them to suit your current needs.
The File
⇒ Merge... command adds the contents of a program or set of saved objects into the work area while keeping the existing contents of the work area. By default, File
⇒ Merge... displays a directory of programs that are shipped with VEE.
They include commonly needed programs such as a bar chart display and a data entry keypad for user input (such as ID numbers).
Lab 9-4: Merging a Bar Chart Display Program
In this exercise, you will merge an existing program with a new program. Although the example uses a program from the VEE
Lib directory, you could use any program. You will create an array with five values from 1 to 5 using the ramp() function.
Instead of displaying the array with one of the internal VEE displays, you will merge the BarChart program with the program you are creating.
1 Select Formula and place it in the left work area.
2 Delete the data input terminal.
3 Change the default formula to ramp(5,1,5).
The first parameter is the number of elements desired in the ramp array. The second parameter is the starting number, and the third is the last number. For more information on this function, select Help in the Formula object menu now that it has the ramp call in it. (Or try Help
⇒ Contents & Index, then use the Search feature in the Index folder.)
4 Click on File ⇒ Merge... to get the Merge File list box.
Select BarChart.vee and place it to the right of the Formula object. Connect the two objects.
5 Run the program. It should look like Figure 202.
358 VEE User’s Guide
Using Agilent VEE Functions Chapter 9
VEE User’s Guide
N O T E
Figure 202 Merging the BarChart Program
Notice that the Bar Chart Display takes a one- dimensional array and displays the values as vertical bars. It uses the number of bars necessary to display the values in the array. To see how the program is created, open the detail view of the display. You can look at examples in the library directory for more ideas about programs.
The File
⇒ Merge command is used to merge in UserObjects and objects.
The File
⇒ Merge Library command is used to merge UserFunctions.
359
9 Using Agilent VEE Functions Chapter
Chapter Checklist
You should now be able to perform the following tasks. Review topics, if necessary, before going on to the next chapter.
• Define a UserFunction and compare it to a Compiled
Function and a Remote Function.
• Create, call, and edit a UserFunction .
• Create, merge, import, and delete UserFunction libraries.
• Use the Find feature in one of the game programs.
• Merge an entire VEE program with the current program.
360 VEE User’s Guide
10
Test Sequencing
Using the Sequencer Object 365
Creating a Test Execution Order 366
Passing Data in the Sequencer 377
Analyzing Data from the Sequencer 389
Storing and Retrieving Logged Data 393
Test Sequencing Chapter 10
VEE User’s Guide 361
10 Test Sequencing Chapter
Test Sequencing
In this chapter you will learn about:
• The Sequencer object
• Configuring a test for the Sequencer
• Creating a test execution order based on run time results
• Accessing data logged by the Sequencer
• Ways to pass data to or from Sequencer tests
• Performing analysis on logged data from the Sequencer
• Storing Sequencer test data
Average time to complete: 2 hours
362 VEE User’s Guide
Test Sequencing Chapter 10
Overview
N O T E
In this chapter, you will learn the fundamentals of using the
Sequencer object. The Sequencer object can execute a series of sequence transactions, each of which may call a UserFunction,
Compiled Function, or Remote Function. Typically, the
Sequencer is used to perform a series of tests.
Some of the benefits of using the Sequencer include:
• Easy development of a test plan
• Wide array of branching capabilities between tests
• Major component for building a customized test executive
• Ability to call tests in VEE and other languages
• Automatic logging of test results
The Sequencer is one of VEE’s most powerful features. For more information about the Sequencer, refer to online Help.
N O T E
The first lab shows you how to configure a test for the
Sequencer object, to add or insert or delete a test in the test execution flow, and to access the test data that has been logged by the Sequencer. The lab simulates test results with the random() function.
In the second lab, you will learn how to structure data passed to tests using global variables, to call UserFunctions from the
Sequencer, and to log Sequencer data to files. Finally, you will analyze parts of the data.
To use a status panel that updates through a sequence of tests, see “Lab
11-5: Creating a Status Panel" on page 434.
VEE User’s Guide 363
10 Test Sequencing Chapter
N O T E
In addition to the lab exercises in this chapter, you can get more practice
in using the Sequencer by completing the exercise in “Test
Sequencing" on page 541 in Appendix , “Test Sequencing 541.”
364 VEE User’s Guide
Test Sequencing Chapter 10
Using the Sequencer Object
The Sequencer object executes tests in a specified order based on runtime results. Each test may be a VEE UserFunction, a
Compiled Function, a Remote Function, or any other expression which returns a single result. That result is compared to a test specification to determine whether or not it passes. The
Sequencer then uses a pass or fail indicator to determine the next test it should perform.
There are six different options for branching to the next test.
These options include executing the next test, repeating the same test, or jumping back to an earlier test. Lab 10- 1 explains branching options in detail. The Sequencer can even ask for user input to decide what course of action to take.
After the specified tests have been executed, the Sequencer automatically logs the test data to an output terminal. From this point the data can be analyzed and displayed, or stored to a file for future investigation.
VEE User’s Guide 365
10 Test Sequencing Chapter
Creating a Test Execution Order
In this lab you will simulate test results using the random() function, establish a test execution order, learn how to modify that order, and retrieve specific data from the logged results.
Lab 10-1: Configuring a Test
N O T E
The example explains how to implement the random() function with a certain range of test results expected, but you can use the same principles to configure other tests.
N O T E
1 Select Device ⇒ Sequencer and place it in the upper- left work area.
2 Select Display ⇒ AlphaNumeric display, place it below the
Sequencer, increase its width, and connect the Sequencer
Log output terminal to the Alphanumeric data input.
3 Double- click the Sequencer transaction bar to get the
Sequence Transaction dialog box. Set the fields as follows.
As you edit the fields, remember to click on new fields to modify them or use the Tab key to move forward to different fields. Use the Shift-Tab keys to move the cursor backward. Press the Enter key only when you are done editing the dialog box.
366
Table 39 Sequencer Transaction Fields
Field Name
TEST:
Description
The default name is test1, which you can use. This is just the label for the test in the Sequencer. It is not the test function itself.
VEE User’s Guide
Test Sequencing Chapter 10
Table 39 Sequencer Transaction Fields
Field Name Description
SPEC NOMINAL: Represents the expected test value. The default is .5
.
Change this to .25, and then alter the upper RANGE field (on the far right) from 1 to .5
.
FUNCTION: The default entry testFunc(a) holds the actual function that performs the test. In this case, replace the default field with the random()function. Random() will return a Real64 value between 0 and 1 simulating a test result. This result will be compared to the test specification.
The random(low,high) object is located in the Probability &
Statistics category in the Function & Object Browser box.
Remember that you can call this math function from any expression field without actually using a Formula object. If you do not provide the parameters low and high, as shown in this example, the function will use the default parameters
0 and 1.
You may leave the other defaults. This configuration will lead to a PASS result in approximately half of the runs. The dialog
box should look like Figure 203.
VEE User’s Guide
Figure 203 The Sequence Transaction Dialog Box
367
10 Test Sequencing Chapter
Click OK to close the dialog box. You will see the transaction test1 0 <= (.25) <= .5 on the first transaction bar. This means that test1 will pass if the returned value is in the range from 0 to .5 with the end points included. The expected result is about .25.
4 Run the program. It should display the name of the test, the test result, and the pass- fail indicator ( 1 for PASS, 0 for FAIL)
in the display, as shown in Figure 204.
368
Figure 204 Configuring a Test
Before proceeding, study Table 203 to understand the
various choices in the Sequence Transaction dialog box.
Open the dialog box again by double- clicking on the transaction bar. Open the various menus and read about the different options.
VEE User’s Guide
VEE User’s Guide
Test Sequencing Chapter 10
Table 40 Sequence Transaction Dialog Box
Sequence
Transaction Field
TEST:
Description
Unique name used to reference the test in the Sequencer.
The default names start with test1 and increment with each test. Choosing TEST : means that a test result will be compared to specifications and branching will occur to the next test based on the configuration.
ENABLED
The TEST : button toggles to EXEC:. If you toggle TEST: to
EXEC :, the test will execute without a comparison between a test result and specifications. For example, you might choose EXEC : when the UserFunction is setting up global variables. Selecting EXEC : will also disable logging for the test.
Determines when to execute a test. This menu displays four menu choices:
• ENABLED executes the test under all conditions.
• ENABLED IF : executes the test if the stated expression evaluates to TRUE. For example, the test might be enabled if the input pin A holds the value 1 (A == 1).
You can use ENABLED IF : for audit test control. You might want a particular test to execute every ten runs, for instance.
• DISABLED is the opposite of ENABLED.
• DISABLED IF : is the opposite of ENABLED IF:.
Expected value from the test. SPEC
NOMINAL:
RANGE: Specifies the range of test values. This menu displays four menu choices:
• RANGE signifies the range of test values that signify a
PASS condition. You may also choose from the usual comparisons: >, >=, <, <=, ==, !=.
• LIMIT uses just one value for a comparison of test data.
• TOLERANCE states the passing range of values by adding or subtracting the specified tolerance to the
SPEC NOMINAL value.
• %TOLERANCE states the passing range of values by adding and subtracting a percent tolerance of the SPEC
NOMINAL value to the nominal specification.
369
10 Test Sequencing Chapter
Table 40 Sequence Transaction Dialog Box
Sequence
Transaction Field
FUNCTION:
Description
Specifies the test to run. You can call UserFunctions,
Compiled Functions, Remote Functions, or you can write in an expression to be evaluated. The result of the function you call (or expression you evaluate) is tested against the specifications.
LOGGING
ENABLED
If a UserFunction returns more than one value, VEE assumes the top output pin holds the result to be tested.
Functions can also be combined and nested:
(random(0,myfunc()+3,100)*2), for example.
Logs test data. To specify logging options, open the
Sequencer object menu, choose Properties, click on the
Logging folder, and choose from the list. By default, Name,
Result, and Pass are checked. There is also a field to choose between Log to Output Pin Only and Log Each
Transaction To:. If logging is enabled, each test logs a record.
IF PASS
This button toggles to LOGGING DISABLED.
Determines branching instructions. If the test passes, VEE goes to this line for branching instructions. IF PASS tells
VEE to branch according to the selection in the drop-down menu.
This button also toggles to IF PASS CALL :.
IF PASS CALL : tells VEE to call the stated function, then go to the branching menu selection.
(Refer also to THEN CONTINUE, which is the next item in this table.)
370 VEE User’s Guide
VEE User’s Guide
Test Sequencing Chapter 10
Table 40 Sequence Transaction Dialog Box
Sequence
Transaction Field
Description
THEN CONTINUE Determines test branching.The drop-down menu THEN
CONTINUE (for IF PASS and IF FAIL) contains six branching options:
• THEN CONTINUE executes the next test configured in the Sequencer.
• THEN RETURN : tells VEE to stop executing tests and put the specified expression on the Return output pin of the Sequencer.
• THEN GOTO : jumps to the test named in its field.
• THEN REPEAT repeats the current test up to the number of times specified in the MAX TIMES : field. If the
PASS/FAIL condition still exists after the maximum number of repeats, then VEE continues with the next test.
• THEN ERROR: stops execution by generating an error condition with the given error number. An error can be trapped with the Error output pin on the Sequencer. No other output pins will send data.
• THEN EVALUATE : calls the specified UserFunction, which must return a string that states a branching menu option. Valid string results from the UserFunction are:
"Continue", "Return <expr>", "Goto <name>", "Repeat
<expr>", "Error <expr>", where <expr> is any valid VEE expression and
<name> is the name of a test in the sequence. This option allows you to ask the user what to do next.
IF FAIL
DESCRIPTION:
Branching instructions. If the test fails, VEE goes to this line for branching instructions. IF FAIL toggles to IF FAIL
CALL :. Options are the same as for IF PASS.
Text comments on the test. They will show on the
Sequencer transaction bar and can be stored with the test record by using the Logging folder in the Properties dialog box.
371
10 Test Sequencing Chapter
Adding or Inserting or Deleting a Test
In this section, you add another test transaction to the
Sequencer object. You can use the same random() function to simulate a test result, but this time you will compare the result to a limit instead of a range of values.
1 Double- click below the first Sequencer transaction bar to get the Sequence Transaction dialog box. Fill in the fields as follows:
Table 41 Sequencer Transaction Dialog Box
Item test2
Description
Use the default.
SPEC NOMINAL Change the settings from .5 to .25
.
RANGE In the drop-down menu, select LIMIT:. Choose < for the operator. Change 1 to .5
for the limit.
FUNCTION Change the field from testFunc(a) to random().
N O T E
Leave the other default selections and click OK to return to the Sequencer.
You could also add a transaction after the highlighted one by selecting
Add Trans... from the object menu.
The Sequencer test plan should now have a second transaction that reads: test2 (.25) < .5. Now insert a transaction between these two tests.
2 Make sure the second transaction bar is highlighted. Then open the object menu and select Insert Trans.... Fill in the fields as follows:
372 VEE User’s Guide
VEE User’s Guide
Test Sequencing Chapter 10
N O T E
Table 42 Inserting a Transaction
Field
TEST
FUNCTION
Description
Change the name field to Insert.
Change to random()
.
Click OK. You will now see Insert 0 <= (.5) <= 1 on the second transaction bar. Run the program to see the three records from the three tests. (You may have to enlarge the display to see all the entries.)
3 Now delete Insert by clicking the Insert transaction bar, placing the mouse pointer over the Insert transaction bar, and pressing Ctrl-K.
You could also click the target transaction bar and select Cut Trans from the object menu. You can also paste a transaction that has been cut by choosing Paste Trans from the object menu (Ctrl-Y is the shortcut).
And in a similar fashion, you can copy a transaction with the Copy Trans selection.
4 Run the program and note the two records of data from the two tests. Save the program as seq1.vee. The program should
373
10 Test Sequencing Chapter
374
Figure 205 A Simple Sequencer Example
The braces indicate a Record data type. The Sequencer outputs a Record of Records, as shown in the AlphaNumeric display.
This means you could put the sequencer in a loop and run the same sequence of tests several times yielding an array of
Records of Records.
Accessing Logged Test Data
The Sequencer outputs a Record of Records. Each test uses the test name as its field name in the Sequencer record. The fields within each test are named according to the logging configuration. Using the default configuration with the fields
Name, Result, and Pass, you could access the result in test1 with
the notation Log.Test1.Result, as shown in Figure 206.
VEE User’s Guide
Test Sequencing Chapter 10
.
VEE User’s Guide
Figure 206 A Logged Record or Records
The following steps access test results.
1 Open seq1.vee.
2 Select Device
⇒ Formula and place it below the display.
Change the expression to Log.Test1.Result. (Remember that
VEE is not case sensitive and the capitals in the names are for clarity in documentation.)
Change the input terminal name from A to Log. (You could leave the default name A. The formula would then read
A.Test1.Result.) Connect the Sequencer output terminal Log to the Formula input terminal Log .
3 Select Display
⇒ AlphaNumeric display and connect it to the
Formula output.
4 Run the program and it should access the Result field in
Test1. Save the program as seq2.vee. The program should look
375
10 Test Sequencing Chapter
376
N O T E
Figure 207 Accessing Logged Data
Each test creates a record, named with the test name, as it executes within the Sequencer. This record can be used in subsequent tests. For example, you could enable test2 if test1 passed (ENABLED IF: test1.pass
== 1). If you need to access test data in an expression field while the test is still running, test data is stored in the temporary record thistest.
5 Change the formula to read Log.test1 and run the program again. It should retrieve the entire record for test1, which is indicated by the braces around the three values in the display.
6 By changing the formula, you can access the result, pass, name, and other fields in the test1 and test2 records. Select
Logging tab in the Properties box and add the Nominal and
Time Stamp fields to the logged records. Access these new fields with the Formula object.
VEE User’s Guide
Test Sequencing Chapter 10
Passing Data in the Sequencer
In this lab, you will create a UserFunction and call it from three different tests. In the first part, you will pass data to the
UserFunctions through an input terminal on the Sequencer. In the second part, you will modify the program to use a global variable instead of an input terminal. This will give you a chance to call a function in EXEC mode rather than TEST mode.
In the third part, you will learn how to test a waveform output against a mask.
Lab 10-2: Passing Data Using an Input Terminal
First, follow the steps to create the UserFunction Rand, which will simulate a measurement procedure. Rand() will add an input parameter to the output of the random(low,high) object, and put this result on the output pin. Rand() will be called from three different tests.
1 Select Device
⇒ UserFunction. Change the name from
UserFunction1 to Rand.
2 Get the random(low,high) function, delete the input terminals, delete the parameters, and place it in Rand.
(Recall that without parameters, the defaults will be 0 and 1.)
Place an A+B object to the right of random(low,high).
Connect the output of random(low,high) to the upper left input of the A+B object.
3 Add a data input terminal to Rand. Connect the input terminal A to the lower left input terminal of the A+B object.
4 Add a data output terminal to Rand. Connect the output of the A+B object to the Rand output terminal.
The UserFunction Rand should look like Figure 208.
VEE User’s Guide 377
10 Test Sequencing Chapter
378
N O T E
N O T E
Figure 208 The Rand UserFunction
5 Save the program as seqdat1.vee. Close the Rand window using the x button on its top right corner.
Closing the window does not remove the UserFunction. If you want to check this, just click on Edit
⇒ Edit UserFunction and you will see Rand come up in a list box of UserFunctions to edit. Or you can iconize the Rand function and you will see the icon for it in the bottom of the VEE screen.
Now set up three tests in the Sequencer to call Rand using a
Sequencer input pin to feed the input parameter to Rand.
6 Select Device ⇒ Sequencer and place it in Main. Add an input terminal to the Sequencer. Click the transaction bar to get the Sequence Transaction dialog box. Change the
FUNCTION field from testFunc(a) to rand(a). This will call the
UserFunction Rand() and send it the value on the Sequencer input terminal A. Click OK to get back to the Sequencer open view.
You could also use a Sequencer input terminal name, such as A, to pass data to any of the expression fields within the Sequence Transaction box.
For example, you could use A to pass data to RANGE: and SPEC
NOMINAL:.
VEE User’s Guide
VEE User’s Guide
Test Sequencing Chapter 10
Make sure the transaction is highlighted, place the cursor on the transaction bar, press Ctrl-K
to cut the test, then press
Ctrl-Y three times to paste the test back into the Sequencer.
(You could also cut and paste using the object menus.)
The default test names will be test1x2, test1x1, and test1.
Open the three Sequence Transaction dialog boxes and change these names to test1, test2, and test3 for clarity.
1 Select Data ⇒
Continuous
⇒ Real64 Slider and place it to the left of the Sequencer. Change the name to the prompt Select
Num:, size the object to be smaller, and connect it to the
Sequencer input terminal.
You can size an object as you place it by clicking and dragging the object corners using the left mouse button.
2 Select an AlphaNumeric display, place it below the
Sequencer, enlarge it to be wider, and connect it to the Log output terminal on the Sequencer.
3 Save the program again as seqdat1. Select a number on the Real64 Slider object and run seqdat1. It should look
379
10 Test Sequencing Chapter
Figure 209 Passing Data Using an Input Terminal
As the number of tests increases, passing data using an input terminal requires more and more input pins. To reduce the input pins, you could pass records to input terminals and use individual fields in the records for the separate tests. You could also use a separate UserFunction to set up global variables, which can then be called by other UserFunctions or any expression field within the program. The next exercise illustrates this.
Passing Data Using a Global Variable
This exercise modifies the seqdat1 program by adding a global variable to pass the parameter a to the UserFunction Rand.
1 Delete the Real64 Slider object labeled Select Num. Delete the
A input terminal on the Sequencer.
2 Highlight the test1 transaction bar, open the object menu, and click Insert Trans .... When the Sequence Transaction box appears, click TEST to toggle the selection to EXEC and change the name to Setup.
3 You will use EXEC mode, since the User Function will only set up a global variable and will not yield a result that needs to be tested against a specification.
4 Change the FUNCTION field to global() and click OK to close the dialog box.
5 You will now create the UserFunction global().
6 Select Device ⇒ UserFunction. Change the name UserFunction1 to global.
Select Data ⇒ Continuous ⇒ Real64 Slider and put it in the
UserFunction, change the name to Select Num:, and size it to be smaller vertically.
Select Data ⇒ Variable ⇒ Set Variable and place it to the right of the Real64 Slider.
Change the global variable name from globalA to a. Connect the Real64 Slider to the Set Variable object.
380 VEE User’s Guide
VEE User’s Guide
Test Sequencing Chapter 10
N O T E
N O T E
To display the function on the screen for an operator to select a number, add a pop- up panel view. Include a Confirm (OK ) button, so that the panel remains on the screen until the operator has made a selection. (It is also possible to do these tasks with a Real Input Dialog Box inside the global()
UserFunction.)
7 Select Flow
⇒ Confirm(OK) and place it above the Real64
Slider object. Connect the OK data output pin to the Real64
Slider sequence input pin.
If you place the OK button below the Set Variable object it causes a logic error. That is because VEE sends the old value on the Slider to the Set
Variable object and pauses until the OK button is pressed. Any new value you entered on the pop-up panel is ignored. When OK is connected above the Real64 Slider, VEE waits to set the global variable until after the OK is pressed, and therefore uses the new Slider value. You can turn on Show
Data Flow to watch the execution order.
8 Select Display ⇒ Note Pad and remove the template information. Place it to the right of the OK button. Enter the following user prompt in the Note Pad:
Please select a number for this run of tests
1, 2, and 3.
9 Select the Note Pad, the Real64 Slider, and the OK button by pressing Ctrl and clicking on those objects. Each object will now have a shadow to indicate it is selected. Click Edit ⇒
Add To Panel. (Remember the Edit menu is also available via the right button on an open area of the VEE screen or the detail view of a UserObject or UserFunction.) In Panel view, size the panel to be smaller, and position the Note Pad on top, the Real64 Slider in the middle, and the OK button on the bottom.
.
When you reposition the objects in Panel view, it does not affect the layout of the objects in the Detail view
381
10 Test Sequencing Chapter
Open the UserFunction Properties window. In the General folder under Pop- up Panel, set the ShowPanelonExecute
property to True. Figure 210 shows the UserFunction in
detail view, and Figure 211 shows the panel view.
Figure 210 The Global UserFunction (Detail)
382 VEE User’s Guide
Test Sequencing Chapter 10
VEE User’s Guide
N O T E
Figure 211 The Global UserFunction (Panel)
10 Save the program as seqdat2 and run it. When the pop- up panel appears, select a value and press OK. It should look
The pop-up panel will appear in the center of the screen by default. To move it, click and drag the title bar.
383
10 Test Sequencing Chapter
Figure 212 Passing data Using a Global Variable
Comparing a Waveform Output with a Mask
In this exercise, you will create a UserFunction called noisyWv and call it from a single transaction bar in the Sequencer. The operator will be able to vary the amplitude of the wave from 0 to 1. This function simulates a test result that returns a noisy
384 VEE User’s Guide
Test Sequencing Chapter 10 waveform. You will use the Coord object in the Data ⇒ Constant menu to create a straight line mask at 0.6, which the Sequencer will use to test the noisy waveform.
1 Create the UserFunction called noisyWv, as shown in
Figure 213 in the Detail view.
VEE User’s Guide
Figure 213 The noisyWv UserFunction (Detail)
2 Press Ctrl and click on the OK button, the Real64 Slider, and the Note Pad to highlight them for creating a Panel view.
Select Edit ⇒ Add To Panel.
When the Panel view displays, rearrange the objects to your taste, and size the window.
Open the object menu, click Properties, and under Pop- up
Panel click next to Show Panel on Execute.
The Panel view should look like Figure 214.
385
10 Test Sequencing Chapter
386
Figure 214 The noisyWv UserObject (Panel)
3 Select Device
⇒ Sequencer and place it left- center of Main.
Add a data input terminal and name it mask.
4 Click the transaction bar to get the Sequence Transaction dialog box. Change fields as follows:
Table 43 Sequence Transaction Dialog Box
Field
FUNCTION
RANGE
Description
Type in noisyWv()
.
Click and select
LIMIT
from the pop-up menu. Leave the
<=
, and the
LIMIT
terminal name field type mask
. All of the other defaults are fine, so click OK .
test1 will get a result from noisyWv() and test it against the limit value at the input terminal named mask. If the noisy wave is less than or equal to the mask at all points, it will pass. Otherwise, it will fail.
VEE User’s Guide
VEE User’s Guide
N O T E
Test Sequencing Chapter 10
5 Select Data
⇒ Constant ⇒ Coord and place it above the
Sequencer. Connect its output to the Sequencer input terminal mask.
Open the Coord object menu, click Properties, and set fields as follows:
Table 44 Properties of the Coord Object
Property
DataShape
ArraySize
Description
Set to 1D Array.
Type in 2 (you only need two pairs of coordinates to specify a straight line.)
6 In the Coord object, you now see two indices for pairs of coordinates. Double- click the first index, 0000: and a cursor will appear. Type in the coordinates separated by a comma, and VEE adds the parentheses automatically. Type 0, 0.6
Tab 20m, 0.6 and then click on the work area outside the object. The entries are as follows:
• The x axis (time axis) for the Noise Generator in noisyWv() goes from 0 to 20 milliseconds; hence, the two x values of 0 and 20m.
• The two y values are both 0.6, since you want a straight line mask.
You can create any mask waveform by configuring the proper number of coordinate pairs and filling them in.
The Sequencer comparison mechanism operates just like the
Comparator object, which accepts the Coord data type to test waveforms. Of course, you could also compare two Waveform data types. Press Tab to move between coordinate pairs, and click on the work area when you are done.
7 Select an AlphaNumeric display, increase its width, and connect it to the Log output from the Sequencer.
387
10 Test Sequencing Chapter
8 Save the program as seqdat3 and run it. It should look like
388
Figure 215 Comparing a Waveform to a Mask
This completes the exercises about passing data with the
Sequencer. In the next exercise, you will learn how to access and analyze data from several iterations of the Sequencer.
VEE User’s Guide
Test Sequencing Chapter 10
Analyzing Data from the Sequencer
As mentioned earlier, Sequencer data comes out as a record of records. In many cases, however, the Sequencer may run through a series of tests several times. This generates an array of records. Each record represents one run through the
Sequencer and holds other records, representing each test within a run. The easiest way to visualize this is to imagine a
cube of data in memory, as shown in Figure 216.
VEE User’s Guide
Figure 216 A Logged Array of Records of Records
The array of records is called Log, because that is the name associated with the Sequencer output pin. To access a particular run, use array indexing with the bracket notation.
• Log[0] is the first run through the Sequencer, Log[1] is the second run, and so forth.
• The main record for each run has two fields, Test1 and Test2.
389
10 Test Sequencing Chapter
• Within the record Test1 there are three fields: Name, Result, and Pass. The same holds for the record Test2.
• Therefore, Log.Test1.Result gives an array of four values, each representing one of the four runs. Log[0].Test1.Result outputs a scalar value, the Result of Test1 in the first run (Log[0]).
The logged array of records simplifies analyzing and investigating the data. For example, you might want to know how many tests passed in a particular run. Or you might want to average the results of Test2 in all runs. Or you might want to see all of the data on Test1 in the fourth run. All of these queries are possible with this data structure. The next exercise performs some analysis operations on data.
Lab 10-3: Analyzing Several Runs of Data from the
Sequencer
1 Clear the screen and open the seqdat1.vee program.
Modify the seqdat1.vee program to run through the Sequencer three times. Then perform some analysis operations on the data.
2 Select Flow
⇒ Repeat ⇒ For Count and place it above the
Real64 Slider object. Change the number of iterations to 3, and connect the data output pin to the sequence input pin of the Sequencer.
3 Delete the data line between the Sequencer Log pin and the display. Select Data ⇒ Collector and place it to the right of the Sequencer. Connect its upper left data input pin to the
Sequencer Log pin and its XEQ pin (lower left) to the sequence output pin on the For Count object. Connect the
Collector data output pin to the AlphaNumeric display.
Enlarge the display vertically somewhat to accommodate an array with three elements.
The Sequencer will now run through test1 and test2 three times and collect the data into an array with three elements, each one holding a record of records for each run. (Refer to
the cube of data in Figure 216 to visualize this.)
Run the program at this point to see the display of the
Sequencer data.
390 VEE User’s Guide
Test Sequencing Chapter 10
Now use the Formula object to extract part of the data to analyze. This exercise uses the results of test1 for all three runs as an example, and finds the mean of that array.
4 Select Device
⇒ Formula and place it below the display.
Connect the Formula input pin to the output of the Collector.
Change the Formula input field to read: a[*].test1.result
. Connect a mean(x) object to
Formula, and an AlphaNumeric display to mean(x).
The a refers to the array on the input terminal A. Test1.result accesses the proper field. All runs will be shown in an array.
( A[0].test1.result would refer to the first run only, for example.)
5 Run the program. It should look like Figure 217.
VEE User’s Guide
Figure 217 Analyzing Several Runs of Sequencer Data
391
10 Test Sequencing Chapter
Although this exercise accesses a single array, the principle is the same for extracting other arrays of data from the Sequencer output. Note that you can easily change which fields are saved for each by opening the Logging folder in the Sequencer
Properties dialog box.
392 VEE User’s Guide
Test Sequencing Chapter 10
Storing and Retrieving Logged Data
This exercise shows how to use the To/From File objects and
To/From DataSet objects.
Lab 10-4: Using the To/From File Objects with Logged Data
1 Open the seqdat2 file and delete the data line to the display.
2 Select Flow
⇒ Repeat ⇒ For Count and place it to the left of the
Sequencer. Change the For Count number to 3, and connect its data output pin to the sequence input pin on the
Sequencer.
3 Enlarge the work area vertically and place the AlphaNumeric display near the bottom. Select Data ⇒ Collector and place it in the left work area. Connect the Sequencer Log pin to the
Collector data input pin. Connect the For Count sequence output pin to the Collector XEQ pin.
The Collector will create an array of records of records from the Sequencer. Using the WRITE CONTAINER transaction in the To File object you can write any VEE data container to a file quite easily.
4 Select I/O
⇒ To ⇒ File and place it to the right of the
Collector. Select I/O
⇒ From ⇒ File and place it below the To
File object. Add an input terminal to the To File object and connect the Collector output to it. Connect the To File sequence output to the From File sequence input pin.
Connect the From File data output to the display.
Check Clear File At PreRun & Open in To File, and configure a
WRITE CONTAINER a transaction. Configure a transaction in the From File object like the following: READ CONTAINER x.
You can use the default data file for storage.
5 Run the program. It should look like Figure 218.
VEE User’s Guide 393
10 Test Sequencing Chapter
394
Figure 218 Storing Logged Data with To/From File
Using the To/From DataSet Objects with Logged Data
Since you are storing test data as records, you may prefer to use the To/From DataSet objects. In this case you do not need a
Collector, because you can append each run of the Sequencer to the end of the DataSet.
Modify the last program to look like Figure 219. The
To/From DataSet objects are in the I/O menu. Notice the sequence line going into From DataSet. The sequence line is included because you want to wait for all three runs to be appended to the DataSet before you trigger From DataSet.
VEE User’s Guide
Test Sequencing Chapter 10
N O T E
One reason you might use the To/From DataSet objects to collect data instead of the To/From File objects is because you can convert the data to useful information with the Search
Specifier feature in the From DataSet object.
Remember to change the Get records field in From DataSet from One to
All.
VEE User’s Guide
Figure 219 Storing Logged Data with To/From DataSet
395
10 Test Sequencing Chapter
Chapter Checklist
Use the following checklist to determine whether there are topics you need to review before going on to the next chapter.
• Describe the Sequencer object conceptually.
• Configure a test for the Sequencer.
• Add, insert, and delete operations for a Sequencer test.
• Access logged data from the Sequencer.
• Use Sequencer input terminals to pass data to tests.
• Use Global variables to pass data to tests.
• Compare a waveform output to a mask.
• Analyze several runs of data from the Sequencer.
• Store data using the To/From File objects.
• Store data using the To/From DataSet objects.
396 VEE User’s Guide
Using Operator Interfaces Chapter 11
11
Using Operator Interfaces
Key Points Concerning Operator Interfaces 400
Using Operator Interface Objects 403
Common Tasks In Creating Operator Interfaces 419
VEE User’s Guide 397
11 Using Operator Interfaces Chapter
Using Operator Interfaces
In this chapter you will learn about:
• Building operator interfaces
• Using menus for an operator
• Importing bitmaps to add clarity
• Securing test programs
• Operator interface features
• Using ActiveX Controls to extend capabilities of VEE
Average Time To Complete: 2 hours
398 VEE User’s Guide
Overview
Using Operator Interfaces Chapter 11
In this chapter, you will learn more about operator interfaces, including adding menus, customizing interfaces, adding warning signals, and importing bitmaps. This chapter expands on the exercises in previous chapters, where you created operator interfaces and pop- up panels.
Some benefits of using VEE operator interface features are:
• Maximum ease of use for the operator
• Improved program performance
• Security from unauthorized changes
• Clarity through visual aids
VEE User’s Guide 399
11 Using Operator Interfaces Chapter
Key Points Concerning Operator Interfaces
This section is an overview of how to create an operator interface in VEE.
Creating an Operator Interface
VEE includes a wide range of selection controls, pop- up dialog boxes, indicators, and displays to create operator interfaces. Selection controls include items such as buttons, switches, check boxes, drop- down menus, and list boxes.
Indicators include items such as tanks, thermometers, fill bars, vu meters, and color alarms.
In addition to the operator interface elements provided within VEE, you can add elements from other sources. There are thousands of operator interface elements that can be downloaded from the World Wide Web. There are operator interfaces that are available through ActiveX controls. (Some items that you download may be free and some may charge a fee.)
Whether you use operator interface objects that are all provided in VEE or add outside elements of your own, the process for creating an operator interface is the same.
To create an operator interface for a VEE program, you create a Panel view of the program.
1 Select the object or objects that you want in the panel view, by holding down the Ctrl key and clicking each object to select it.
2 Select Edit
⇒ Add To Panel. The screen switches to Panel view, shown by default in blue, that includes the objects you highlighted from the Detail view.
You now have a view of the VEE program that you can customize to show only what the operator needs to see.
400 VEE User’s Guide
Using Operator Interfaces Chapter 11
Moving Between Panel View and Detail View
To move between the Panel view and the Detail view of a
VEE program, click the panel or detail icon on the title bar
of the window as shown in Figure 220.
N O T E
You must create a Panel view of the program to have the panel view button displayed in a window title bar.
.
Typically, you develop the program in Detail view and then create a Panel view for the operator interface. The Panel view button can be on the title bar of a UserObject window,
UserFunction window, or Main window.
VEE User’s Guide
Detail View Button
Panel View Button
Figure 220 Panel View Button and Detail View Button in Title Bar
Customizing an Operator Interface
In the Panel view of a VEE program, you can change the size of objects, rearrange objects, and change the way the objects are displayed without affecting the same objects in
the detail view. For example, you could remove the title bar and the scales from the Panel view of a Waveform (Time) display without affecting the detail view of the same
Waveform (Time) display. However, if you delete an object in the detail view, it will also be deleted in the panel view.
401
11 Using Operator Interfaces Chapter
In panel view, you can choose different colors and fonts to add emphasis, and scalable bitmaps to add clarity. You can also document the panel view for the operator by editing title bars, using the Note Pad and Label objects, and using the Description option in the object menus.
Figure 221 shows some of the VEE indicators available.
402
Figure 221 A Selection of VEE Indicators
VEE User’s Guide
advertisement
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Related manuals
advertisement
Table of contents
- 120 Using Data Types
- 121 Using Data Shapes
- 122 Using the Formula Object
- 174 Deleting Data Input or Output Terminals
- 174 On Your Own
- 251 Building a Record
- 253 Getting a Field From a Record
- 255 Setting a Field in a Record
- 258 Unbuilding a Record in a Single Step
- 284 More Specific Type Checking:
- 284 Catching Events:
- 431 Colors and Fonts
- 431 Color Alarms
- 431 Tanks, Thermometers, Fill Bars, Meters
- 487 Execute Program Object
- 487 Compiled Functions
- 487 Synchronous execution
- 511 How a Remote User Accesses Agilent VEE on Your System
- 514 Displaying the Agilent VEE Web Server Page
- 516 Lab 13-1: Practice Session with Agilent VEE Web Browser
- 519 Restricting Access to Programs Viewed over the Web
- 528 Optimal Solutions:
- 528 Until Break and Break Objects:
- 528 Accumulator:
- 528 Counter:
- 529 Start:
- 529 Shift Register:
- 529 Gate:
- 532 Auto Execute:
- 532 Consolidating Formulas:
- 535 Logging AlphaNumeric vs. AlphaNumeric:
- 536 Timing Pins:
- 537 Layout of Slider Objects:
- 537 XY Trace:
- 538 MovingAvg(x, numPts):
- 540 Mask:
- 540 Comparator:
- 541 TotSize:
- 541 Formula:
- 543 String Objects and Functions:
- 543 Formula Object:
- 543 Set Variable:
- 543 Optimizing:
- 548 UserObject:
- 548 Build Waveform:
- 550 Ramp():
- 550 Build Waveform:
- 555 Select Function:
- 555 Editing UserFunctions:
- 555 Set Variable Caution:
- 562 Generating an Array:
- 562 Time Stamp:
- 562 Storing Two Values in a Line:
- 562 Extracting a Value From a File:
- 562 Junction:
- 564 Time Stamp:
- 564 Configuring a Data Constant as an Array:
- 565 Naming Fields:
- 565 The Default Value Control Input:
- 566 Using a Conditional Expression:
- 566 The Sub Record Object:
- 568 The To DataSet Object:
- 568 The From DataSet Object:
- 583 Button
- 583 Cascading Menu
- 583 Checkbox
- 583 Click
- 583 Clone
- 583 Component
- 584 Component Driver
- 584 Container
- 584 Context
- 584 Cursor
- 584 Cut Buffer
- 584 Data Container
- 584 Data Flow
- 584 Data Input Pin
- 584 Data Output Pin
- 585 Data Shape
- 585 Data Type
- 585 Detail View
- 585 Direct I/O Object
- 585 Double-Click
- 585 Drag
- 585 Drop-Down List
- 585 Entry Field
- 585 Expression
- 586 Font
- 586 Grayed Feature
- 586 Group Window
- 586 Hypertext
- 586 Icon:
- 586 Main Window
- 586 Maximize Button
- 586 Menu Bar
- 587 Minimize Button
- 587 Object:
- 587 Object Menu
- 587 Object Menu Button
- 587 Open View
- 587 Panel Driver
- 587 Panel View
- 587 Pin (or Pins)
- 588 Pointer
- 588 Pop-Up Menu
- 588 Preferences
- 588 Program
- 588 Program Explorer
- 588 Propagation
- 588 Properties
- 588 Pull-Down Menu
- 588 Scroll Arrow
- 589 Scroll Bar
- 589 Select
- 589 Selection Field
- 589 Sequence Input Pin
- 589 Sequence Output Pin
- 589 Status bar
- 589 Status field
- 589 Terminal
- 589 Title Bar
- 590 Toolbar
- 590 Transaction
- 590 UserObject
- 590 Views
- 590 Windows 98, Windows NT 4.0, Windows 2000, Windows XP
- 590 Work Area
- 590 Work Space