[Design Application]
Build Com Objects In Visual Basic For Your Embedded System Applications
VB developers can easily deploy COM applications for test and measurement, as well as many other client-server design projects.
Due to the highly transparent integration of the Component Object Model (COM) into the Visual Basic (VB) development environment, VB developers are effectively programming and deploying COM applications today. Unlike their C/C++ counterparts, VB programmers build on concepts that they already know. There are no extra tools, such as the Microsoft Interface Definition Language (MIDL) compiler. Plus, there's no need to initialize the COM system or be aware of the COM runtime's existence because that's all simply integrated into the environment.
COM development is a natural fit for the test and measurement domain, as well as for many other embedded-system applications. Interfaces can be made in VB that correspond to the Standard Commands for Programmable instruments (SCPI) hierarchies. These de-fined interfaces combined with VB's development environment In-telliSense capability essentially eliminate the need for programming manuals.
Still, the value proposition of COM doesn't stop there. For instance, COM offers location independence. A COM object client doesn't know if the object is being used in the same process, across processes, or on an entirely different system. With minor changes, objects built in COM can be used in distributed scenarios. For the test and measurement world, the remote system could be an instrument running an embedded Win32 environment that hosts these COM objects.
The VB developer also can create an ActiveX control that encapsulates the programming model and adds visual controls that aid in setting the initial state of the COM object using Graphical User Interface (GUI) controls. That process previously would have taken multiple lines of programming.
Once proficient in the use of COM, the flexibility factor is seemingly limitless. Many Microsoft applications expose their features' programmability using COM technology. For example, the test and measurement developer can easily take measurements from an instrument and quickly insert them into a Microsoft Excel spreadsheet.
Finally, the environment doesn't lock a user's development efforts strictly to VB. Those COM objects developed in VB can either be used from C/C++, or from more traditional test and measurement visual environments, like Agilent Technologies' VEE and National Instruments' LabVIEW.
Start With Interfaces When starting with COM, a user needs to begin with interfaces. Interfaces allow the programmer to separate the programmatic interface from an object's implementation. This separation allows COM to be characterized as a binary reuse model rather than a source reuse model found in C++ class hierarchies, which combine both implementation and interface.
Interfaces can be made that correspond to the subsystems found in a SCPI hierarchy. Interfaces additionally facilitate an object-oriented feature called "polymorphism," which allows a programmer to define interfaces that can be applied to dissimilar objects while accessing them in a similar manner.
Currently, the Interchangeable Virtual Instrument (IVI) Consortium is developing a standardization process that will define interchangeable instrument-class interfaces. Once IVI completes its work in this area, each manufacturer of a particular class of instrument (like an oscilloscope) will be able to implement the standardized class interface. Instrument users will then develop their test programs with this interface as the "abstraction," and enjoy the freedom of applying different hardware solutions in their test-system deployment.
Consider the development of a hypothetical test system involving a multimeter. The example instrument server defines a small subset of the Configure, Measure, and Trigger subsystems. The server factors in a new polymorphic interface, called the "IIEE488," to implement the standard IEEE-488 SCPI commands, such as reset and identification. To create a VB interface, the programmer creates a class with methods and properties definitions that don't contain any implementation code in their bodies.
The first step toward creating the instrument server entails invoking the VB development tool and selecting the ActiveX DLL icon in the new-project dialog box. After that is accomplished, the project name is changed from the default name of "project1" to "Multimeter," and the default class of "class1" to "Multimeter34401A."
Creating a new interface consists of selecting the "project" menu dropdown and the menu item Add Class Module. In the dialog that's launched from the menu selection, the developer chooses the new tab, the Class Module icon, and clicks on the "open" button. This action will cause the VB development tool to create a default class with the name "class1." Because a convention in COM suggests the prefacing of interfaces with an "I," the name is set to "IMeasure." The next step would be to define two methodsVoltage DC and Voltage AC (Listing 1).
Of interest in this particular interface is the choice of the Variant type. For range values, the SCPI definition allows the programmer to specify the string values "MAX," "MIN," and "DEF," together with a specific numeric value. To enable this interface to accommodate these potential values, one would use the predefined type Variant that could accept string as well as numeric values. The same process would apply to the remaining interfacesIConfigure, ITrigger, and IIEE488as would the filling out of their function prototypes.
After defining all the interfaces, the programmer returns to the first class created"MultiMeter34401A"and provides the implementation, using the "Implements" keyword in VB:
Implements IMeasure
Implements IConfigure
Implements ITrigger
Implements IIEEE488
At this point, the VB development environment is set to aid in developing the interface skeletons. As a sample exercise, select the IMeasure object in the object viewer, and select each of the interfaces one by one (Fig. 1).