11 Alternate Software for DAQ

Are you already familiar with another programming language, such as Microsoft Visual C++ or Microsoft Visual Basic? You may not want to use LabVIEW if this is the case. NI makes an excellent option to LabVIEW called LabWindows/CVI, which is based upon the C programming language. Measurement Studio is the name of NI’s product that includes LabWindows/ CVI, ComponentWorks (customized for Visual Basic), and ComponentWorks++ (customized for Visual C++). If you don’t want to buy Measurement Studio, you can access NI-DAQ functionality directly from most C compilers, or from any environment that can access DLLs. See Section 11.4 for further details.

11.1 LABWlNDOWS/CVI

LabWindows/CVI, or just CVI hereafter, ships as a part of Measurement Studio. I just installed CVI 5.5 on my computer and ran the ai_samp. prj in CVI’s sample folder, which is analogous to LabVIEW’S examples folder. ai_samp.

prj collects and displays analog input data; I ran this CVI project with absolutely no modification. I connected analog input channel 0 to analog output channel 0 on my DAQ device, then free-ran LabWIEW’s AO Update Channel. vi, as we’ve done earlier in this book (see Figure 11-1).

Figure 11-1
LabVIEW continuously updates analog output channel 0.

Image

Clicking the up /down arrows on the LabVIEW screen shown in Figure 11-1, my CVI sample project displays the window shown in Figure 11-2.

Looks like LabVIEW, doesn’t it? Sure it does, until you see the code that drives CVI. This code is not graphically oriented, like LabVIEW’s, but text oriented. Following is the core of the actual code (with a bit of white space removed) used to update the CVI panel you see in Figure 11-2.

int CVICALLBACK TimerCallback (int panel, int control, int event,
            void *callbackData, int eventDatal, int eventData2)
{
      short error;
      static int errorMsgActive = 0;
      static int inc = 0;
      static int needToRestartActualRateCalc = 1;
      static double startTime, elapsedTime;

      switch (event) {
            case EVENT_TIMER_TICK:

Figure 11-2
LabWindows/CVI continuously reads analog input channel 0.

Image

                  DisableBreakOnLibraryErrors () ;
                 error = AlSampleChannels (device, channelString, upper, lower, voltages);
                  EnableBreakOnLibraryErrors ();
ErrorHandler (error) ;
if (numChanne1s)
                   PlotStripChart (panelHandle, PANEL_STRIPCHART, voltages,
                            numChannels, 0, 0, VAL_DOUBLE);
if (needToRestartActualRateCalc)
            {
                 startTime = Timer();
                 needToRestartActualRateCalc = 0;
                 inc = 0;
            }
if ((elapsedTime = (Timer() - startTime)) >= 1.0)
            {
                 SetCtrlVal (panelHandle, PANEL_ACTUAL_RATE, inc/
elapsedTime) ;
                 needToRestartActualRateCalc = 1;
            }

inc++;
break;
    }
       return 0;
}

One of the nice things about CVI is that you can create its panels very much like you can create LabVIEW’s panels. Just drop objects like graphs and buttons directly onto the CVI panels and arrange them much like you would in LabVIEW. Here is a list of reasons I prefer developing DAQ applications in CVI rather than with the powerful and popular Microsoft Visual C++ (which is better for many non-DAQ applications).

1.   C++, although touted by most college professors living in academia as powerful, often turns out to be a time sink as compared to C when used by programmers living in reality.

2.   The manner by which CVI’s panels’ objects are linked to the code is very elegant and simple, much more so than in Visual C++.

3.   When you use CVI’s standard debugging mode, CVI will automatically detect when you write to an “out of bounds” location of an allocated array, whether that array has been allocated dynamically or statically. Visual C++ is likely to crash, but it might let you slip on by white corrupting some other piece of your program. This CVI feature is a real time saver.

4.   CVI is designed for use with DAQ, like LabVIEW, and has a huge library of example DAQ projects.

The one thing I like better about Visual C++ is that it can detect uninitialized local variables. These can result in crashes that are intermittent and not reproducible.

NI people, both CVI fans and LabVIEW fans, are likely to send me letter bombs for saying this, but it’s true: CVI is better for more complex projects, white LabVIEW is better for simpler projects. Suppose you are good with C and good with LabVIEW, and you were to consider all possible DAQ projects, ranging from simple to complex. Figure 11-3 is an admittedly rough sketch of how you should choose which to use.

Figure 11-3
Deciding between LabWindows/CVI and LabVIEW. (WARNING: Controversy-generating diagram; lean towards CVI if you already know C.)

Image

Hoping not to make any enemies at NI based on that last paragraph, I use some text directly from NI’s Web site that describes many of CVI’s features very well.

Design a Graphical User Interface. Building an application in LabWindows/CVI begins with the user interface. You use an intuitive graphical user interface (GUI) editor to interactively design virtual instruments. Select from controls designed specifically for instrumentation, such as knobs, meters, gauges, dials, graphs, and strip charts, to build your GUI. As you place each control on the GUI, you double-click to customize its appearance and function to meet your needs.

Generate Program Code. You can generate a C program using CodeBuilder. CodeBuilder automatically generates C source code to display and respond to the controls on your user interface. CodeBuilder creates code for you to respond to user events, such as mouse clicks, key presses, and menu selections.

Complete the Program with Function Panels. Complete the application by inserting acquisition, analysis, and control code into the program. The LabWindows/CVI code generation tools, called function panels, help you use the built-in libraries and instrument drivers. A function panel, available for every function, is a graphical representation of a LabWindows/CVI function and its parameters. Simply set the values of each parameter to interactively build a function call. You can even execute the function from the function panel to test its operation, then automatically paste the function call into your source file. You save time, bypassing the tedious process of typing and editing function calls in your program. The LabWindows/CVI development environment has an array of editing and debugging tools to streamline your programming, including a 32-bit compiler, linker, variable display, watch window, and full-function source editor.

Measurement Studio for CVI Multithreading. You can easily create and debug multithreaded applications in LabWindows/CVI. The Lab-Windows/CVI libraries are multithread-safe, and the LabWindows/ CVI Utility Library contains a large set of functions to simplify multithreaded programs. The LabWindows/CVI development environment provides full multithreaded debugging capabilities, such as setting breakpoints that can be honored in any thread and viewing the state of each thread when the program is suspended.

Automatic Run-Time Checking When you run your LabWindows/CVI program in debug mode, LabWindows/CVI’s patented User Protection feature automatically checks for program memory errors, such as writing beyond the end of an array or dereferencing an uninitialized pointer. If LabWindows/CVI encounters such an error, it stops the program and points to the offending line of code. LabWindows/CVI also checks the calls you make to its library functions for parameter values that might cause memory errors. For example, if you pass an array to one of the Analysis functions along with a count that indicates the array is larger than it really is, LabWindows/CVI stops your program and points to the function call. Additionally, you can configure the LabWindows/CVI debug mode to stop your program whenever a LabWindows/CVI library function returns an error. These User Protection features significantly speed up the development process.

Package Your Code for Delivery. When you finish your application, you can build an executable with a single mouse click. You can also build a dynamic link library (DLL) and incorporate your instrumentation code into external development tools or applications that work with DLLs, such as LabVIEW, Visual Basic, or other C/C++ development environments. You can package your code onto disks with the built-in LabWindows/CVI distribution kit builder and then download the code onto target computers.

11.2 MICROSOFT VISUAL BASIC WITH DAQ (COMPONENTWORKS)

ComponentWorks, like CVI, ships as a part of Measurement Studio. I defer yet again to the experts at NI, by snagging some wonderfully descriptive ComponentWorks text directly from their Web site.

User Interface Components for Visual Basic. With these ActiveX controls in Measurement Studio, you can configure real-time 2D and 3D graphs, knobs, meters, gauges, dials, tanks, thermometers, binary switches, and LEDs to create professional instrument front panels in your computer-based measurement applications. For example, you can display waveforms acquired from DAQ boards or GPIB instruments. Or you can display slowly changing data, such as temperature, pressure, or strain, in a scrolling strip chart. The 2D graph displays multiple waveforms, X and Y axes, and interactive cursors.

Internet Components for Visual Basic. Using the DataSocket ActiveX control, you can share live measurement data between applications via the Internet. DataSocket provides a simple mechanism for interacting with OPC, HTTP, FTP, and file servers from any ActiveX container. DataSocket delivers Plug and Play connectivity throughout your company by providing an easy interface for sharing live measurement data between applications separated by a network or the Internet. DataSocket delivers seamless access to live data, which empowers users throughout your company to improve productivity, reduce costs, and increase profitability. Use DataSocket to share data between Visual Basic, Visual C++, LabWindows/CVI, and LabVIEW applications.

Instrument Control Components for Visual Basic. With Measurement Studio you can use GPIB, serial, and VISA I/O controls and intuitive property pages to configure communications with your instruments. You can easily send commands and receive response strings from instruments. To simplify the parsing of data strings, Measurement Studio features an interactive tool to define rules for parsing information out of instrument strings and keep only the data you need.

ActiveX Interchangeable Virtual Instrument (IVI) Controls for Visual Basic. National Instruments Measurement Studio also includes ActiveX controls for communicating with two of the most popular IVI instrument classes, oscilloscopes and digital multimeters (DMMs). These ActiveX controls increase your productivity when using IVI drivers as opposed to the DLL version of the IVI drivers. With the drivers, you make fewer software calls, thereby reducing configuration. They provide a less complicated programming interface to the hardware and enforce interchangeability by making sure you do not call instrument specific functions instead of the class functions. The controls also have a built-in user interface so you can access the functions of your instrument without programming. You can turn off this feature so that you can create your own user interface.

Plug-In DAQ Controls for Visual Basic. With the Measurement Studio DAQ controls, you can easily perform analog, digital, and timing I/O operations on all National Instruments DAQ boards. With these ActiveX controls, you configure your DAQ operations by setting properties in the intuitive property pages. There is no need for any low-level programming to set up your acquisition routines or to transfer buffers from your board to your computer—the ActiveX controls handle the details for you.

11.3 MICROSOFT VISUAL C++ WITH DAQ (COMPONENTWORKS++)

ComponentWorks++, like CVI, ships as a part of Measurement Studio. I defer yet again to the experts at NI, by snagging some wonderfully descriptive CompentWorks++ text directly from their Web site.

User Interface Display Components for Visual C++. Because measurement applications often require real-time 2D and 3D graphs, knobs, meters, gauges, and more, Measurement Studio provides these flexible measurement-focused user interface components to simplify your development and save you time. Programmatically modify each property during the execution of the program to give you total programming flexibility.

Internet Components for Visual C++. Using the new DataSocket classes, you can easily communicate measurement data with multiple interfaces, such as OPC, HTTP, FTP, and DataSocket across any network, including the Internet. By using a client/server architecture, the data transfer across the network is optimized, making user interaction to live data across the Internet a reality. You will be able to view test information or control your system from anywhere in the world.

Analysis Components for Visual C++. Measurement Studio includes a powerful and comprehensive set of functions for analyzing data in Visual C++. You condition and transform your signal using smoothing windows, digital filters, frequency domain transforms, or measurement functions. With these powerful analysis routines, you can convert raw data into meaningful information and build robust virtual instruments.

Instrument Control Components for Visual C++. Interface your application to the outside world through Measurement Studio instrumentation classes. In addition to using the GPIB IEEE 488.2 library to send and receive commands to and from instruments, you can use VISA, an industry-standard I/O library, to communicate with your instruments. With VISA, you can control GPIB, VXI, or serial devices using the same set of components.

Application Wizard. To simplify the development of measurement applications in Visual C++, Measurement Studio features an application wizard. Built on the MFC AppWizard, you simply select the instrument drivers you want to include in your project and the type of measurement application you want to create, and the wizard automatically generates an MFC project with the necessary user interface, analysis, and instrumentation components.

Backward Compatibility with LabWindows/CVI. Use the LabWindows/CVI import wizard to preserve your legacy code. Any application developed in LabWindows/CVI can port to Visual C++ without changing a single line of code.

11.4 OTHER PROGRAMMING LANGUAGES WITH DAQ

If you just need a simple interface to NI-DAQ from Visual C++, Visual Basic, or another programming environment, read this section.

For Windows users, you can access the free, low-level NI-DAQ functions directly without paying a dime for any of the Measurement Studio components, provided you have a development environment that can link to DLLs. Currently, NI-DAQ functionality ships in a DLL called nidaq32. dll, and its functions are documented in the NI-DAQ Function Reference Manual, which you can download from NI’s Web site. Most C compilers and Microsoft Visual Basic can use this DLL directly.

If your application behaves as an ActiveX container, you can use the many powerful ActiveX Components of ComponentWorks, described in Section 11.2. For non-Windows users, there are similar mechanisms for accessing NIDAQ functions in platform-dependent libraries from a variety of programming environments.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.253.55