Академический Документы
Профессиональный Документы
Культура Документы
Overview
NI-DAQmx 7.4 includes a beta type library that you can use to create applications in Visual Basic 6.0. This type library is named nidaqmx.tlb and is installed and registered when the NI-DAQmx driver is installed with Microsoft Visual C Support selected. This type library provides declarations for NI-DAQmx C API functions and enumerations. Visual Basic 6.0 uses these declarations to determine how to call into the C API DLL.
System Requirements
To install NI-DAQmx C API Visual Basic 6.0 Support Beta, your computer must have the following: NI-DAQmx 7.4 or later Visual Basic 6.0, with Service Pack 6 or later
What Is Installed
When you install NI-DAQmx (7.4 or greater) with Microsoft Visual C Support selected, the following items are installed on your computer: The NI-DAQmx driver (7.4 or greater)includes nicaiu.dll, the DLL that implements the NI-DAQmx C API support. The nidaqmx.tlb type library The NI-DAQmx C Reference Helpavailable from StartProgramsNational InstrumentsNI-DAQNI-DAQmx C Reference Help. Examples o Examples written in C that can be converted to Visual Basic 6.0 are installed in the NI-DAQ\Examples\DAQmx ANSI C Dev directory. o Examples written in Visual Basic 6.0 are available from Knowledge Base 39BF3M1E: Can I Program A Board with NI-DAQmx in Visual Basic 6.0? This help document is available in Knowledge Base 39BF3M1E: Can I Program A Board with NI-DAQmx in Visual Basic 6.0?
Getting Started
Read through this document for detailed information about using the NI-DAQmx C API from within Visual Basic 6.0. Complete the following steps to create an NI-DAQmx application in Visual Basic 6.0: 1. Create a new Standard EXE project. 2. From the Visual Basic 6.0 menu, select ProjectReferences. 3. To add the NI-DAQmx type library, nidaqmx.tlb, to the project, select NI DAQmx C API from the list. If NI DAQmx C API is not available in the list, browse to and select nidaqmx.tlb in the Windows\System32 directory. 4. Write code to call into the C API functions. 5. Build your application. For information about specific NI-DAQmx C API functions, refer to the NI-DAQmx C Reference Help, which you can launch from the Windows Start menu by selecting StartProgramsNational InstrumentsNI-DAQNI-DAQmx C Reference Help. .
NI-DAQmx Concepts
For conceptual information about data acquisition and the NI-DAQmx driver, refer to the following sections in the NI-DAQmx C Reference Help. To locate these sections in the help, click the Contents tab and expand the NI-DAQmx Concepts book. Key NI-DAQmx Concepts Traditional NI-DAQ (Legacy) Versus NI-DAQmx Measurement Fundamentals Common Applications
Once you have added the type library to the project, the DAQmx functions display in the Object Browser. From within Visual Basic 6.0, click ViewObject Browser to launch the Object Browser. When you view the library in the Object Browser, you see that it consists of a single DAQmx module and many global enumerations. The DAQmx module is a flat list that contains all of the DAQmx functions.
Creating Tasks
Most of the operations that you can perform with the NI-DAQmx library, such as acquiring data or generating a signal, require that you first create an NI-DAQmx task. A task is a collection of one or more virtual channels with timing, triggering, and other properties. Conceptually, a task represents a measurement or generation you want to perform. Refer to the NI-DAQmx C Reference Help for more information on NI-DAQmx tasks. There are two ways that you can create a task to use within your Visual Basic 6.0 program. You can programmatically create a new NI-DAQmx task and call various NIDAQmx functions to configure the task; or you can use National Instruments Measurement & Automation Explorer (MAX) to create and configure your task and then
load it within your Visual Basic 6.0 program. After you load a task that was created in MAX, you can call NI-DAQmx functions to further configure the task.
Programmatically Creating and Configuring a Task Complete the following steps to programmatically create and configure a task:
1. Call DAQmxCreateTask to create a new task. 2. Call an appropriate channel creation function, such as DAQmxCreateAIVoltageChan or DAQmxCreateCIPeriodChan to add one or more channels to the task. 3. Call an appropriate timing configuration function, such as DAQmxCfgSampClkTiming, to configure the task timing characteristics.
Using MAX to Create and Configure a Task You can use the NI-DAQmx Visual Basic 6.0 API to load a task that you have already configured and saved in Measurement & Automation Explorer (MAX). You create and configure NI-DAQmx tasks in MAX through an interactive, graphical interface. This approach reduces the amount of code you have to write. You can load tasks saved in MAX and run them in any programming language that has access to an NI-DAQmx library, including Visual Basic 6.0, Visual C, Visual C++, Visual C#, Visual Basic .NET, and LabVIEW.
Complete the following steps to create a task in MAX and load it from within your Visual Basic 6.0 program: 1. From the Start menu, select StartProgram FilesNational InstrumentsMeasurement & Automation Explorer to launch MAX. 2. In the left-hand pane, right-click Data Neighborhood and select Create New. 3. Select NI-DAQmx Task and click Next. 4. Follow the on-screen steps to create and configure the NI-DAQmx task. 5. After the task has been successfully created and saved in MAX, use the DAQmxLoadTask function to load the task in the program.
Caution: Neglecting to call DAQmxClearTask before terminating your Visual Basic 6.0 program debugging session causes the NI-DAQmx driver to keep the task resources reserved. Reusing reserved resources, such as the task name, in subsequent debugging sessions causes errors. To fix this problem, you must restart Visual Basic 6.0 to unload the NI-DAQmx driver and free the resources.
Properties that are read-only have only a get function. For a complete list of properties and get/set/reset functions, refer to the NI-DAQmx C Properties section of the NI-DAQmx C Reference Help.
Handling Errors
All of the functions in the NI-DAQmx API return an integer value indicating whether the function executed successfully. A value of 0 indicates success. A positive value indicates a warning. A negative value indicates an error. You can pass this error code to the DAQmxGetErrorString and DAQmxGetExtendedErrorInfo functions to get additional information. All of the NI-DAQmx C API Visual Basic 6.0 Support Beta examples use the DAQmxGetErrorString function. For additional help on the error functions, refer to Error Handling in the NI-DAQmx C Functions section of the NI-DAQmx C Reference Help.
Using Enumerations
The NI-DAQmx C API includes named constants that you use to specify predefined parameter values for some functions. The NI-DAQmx C API Visual Basic 6.0 Support Beta groups these constants into Visual Basic 6.0 enumeration types. The Visual Basic 6.0 editor has built-in support for enumerations. While you are typing a call to a function that is defined in the NI-DAQmx type library, the Visual Basic 6.0 editor recognizes when a parameter is of an enumerated type and displays a list of valid values. The name of each enumeration value is different than the equivalent NI-DAQmx C APInamed constant, even though internally they are both set to the same integer value. Note: If you are copying code from the NI-DAQmx C API to the NI-DAQmx Visual Basic 6.0 API, you must translate the C API constant names to their corresponding Visual Basic 6.0 enumeration value names. For more information, refer to the Using C to Create Visual Basic 6.0 Applications section of this document.
Using Events
nidaqmx.tlb includes functions that provide configuration and control for task Use DAQmxRegisterDoneEvent, DAQmxRegisterEveryNSamplesEvent, or
events.
DAQmxRegisterSignalEvent
The following events are supported: Every N Samples EventOccurs when the specified number of samples is written from the device to the buffer or from the buffer to the device. Counter Output EventOccurs when any of the counters used in the task reaches its terminal count. Digital Change Detection EventOccurs when a digital change is detected on any of the digital lines used in the task. Task Done EventOccurs when the task finishes, either successfully or due to an error. Sample Clock EventOccurs on each pulse of the task's sample clock. Sample Complete EventOccurs when each sample is acquired into the NIDAQmx driver buffer and is ready for reading.
For additional information, refer to the Events topic under Task Configuration/Control in the NI-DAQmx C Functions section of the NI-DAQmx C Reference Help.
In addition to the function names being the same in both APIs, in most cases, the names of the parameters are identical as well. The main difference between the NI-DAQmx C API and the NI-DAQmx Visual Basic 6.0 API is the data type of parameters. For example, the NI-DAQmx C API function may contain types such as const char [] or uint32. Because these data types are not valid in Visual Basic 6.0, the nidaqmx.tlb type library specifies the appropriate Visual Basic 6.0 data type. When you use the Object Browser in Visual Basic 6.0, you see that the DAQmx functions use data types that are valid in Visual Basic 6.0.
Differences Between the NI-DAQmx C API and the NIDAQmx Visual Basic 6.0 API
The primary difference between the C API and the Visual Basic 6.0 API is the data type of function parameters. The nidaqmx.tlb type library specifies the translated parameter
data types. In addition to data types, there are several other differences between the two APIs, including the following: Visual Basic 6.0 does not support unsigned numbers. If a function uses an unsigned data type in C, you must use the signed equivalent in Visual Basic 6.0. This can reduce the range of values you can pass for some function parameters. Visual Basic 6.0 does not support 64-bit numbers. If a function uses a 64-bit data type in the C API, you must use a 32-bit number in Visual Basic 6.0. This can reduce the range of values you can pass for some function parameters. When using the nidaqmx.tlb in Visual Basic 6.0, numeric array parameter types display as scalar parameter types in the Object Browser and the editor. For example, if a function parameter is an array of doubles in C, the Object Browser and source editor display it as a ByRef double. o You must refer to the documentation of the function in the C API to determine if a parameter requires an array or not. Appendix A of this document lists all of the functions in the Visual Basic 6.0 API that use arrays. o Pass the first item in the array for the parameter value to pass the entire array to the NI-DAQmx driver. Because the array type is ByRef, the NIDAQmx driver is able to read the entire array of values. Visual Basic 6.0 does not support variable parameter functions. The following variable parameter functions have different parameter sets in C and Visual Basic 6.0. The differences in the parameter sets are more than just simple data type translations.
o DAQmxSetDigitalPowerUpStates
In the NI-DAQmx C API, the variable parameter list allows you to specify combinations of additional channels and states (high or low) to set the channels to when the device powers up or when the device is reset. In the NI-DAQmx Visual Basic 6.0 API, you must use an array to specify the channels and states. Each value in the states array applies to the channel in the channels array at the corresponding index position. In the NI-DAQmx C API, the variable argument list allows you to specify combinations of additional channels, types (current or voltage), and states (value of the current or voltage) to set the channels to when the device powers up or when the device is reset. In the NI-DAQmx Visual Basic 6.0 API, you must use an array to specify the channels, types, and states. Each value in the types and states arrays applies to the channel in the channels array at the corresponding index position. In the NI-DAQmx C API, the variable argument list allows you to specify combinations of additional channels and expiration states
DAQmxSetAnalogPowerUpStates
DAQmxCreateWatchdogTimerTask
to set the channels to when the device powers up or when the device is reset. In the NI-DAQmx Visual Basic 6.0 API, you must use an array to specify the channels and expiration states. Each value in the expiration states array applies to the channel in the channels array at the corresponding index position. The NI-DAQmx C API event registration functions allow you to specify whether an event is synchronous or asynchronous. Visual Basic 6.0 only supports synchronous events. The Visual Basic 6.0 event registration functions omit this parameter.
Examples
Using Visual Basic 6.0
The NI-DAQmx C API Visual Basic 6.0 Support Beta installs the following Visual Basic 6.0 examples:
Analog In/MultipleFiniteAcquisition Analog In/SinglePointAcquisition Analog Out/ContGenVoltWfmIntClk Counter In/CountDigEvents Counter Out/ContDigPulseTrain Digital In/ReadDigChan Digital Out/WriteDigChan
8. Make the same function calls to the driver in your Visual Basic 6.0 program. 9. In many cases, you are able to simply copy and paste the code from the C program to the Visual Basic 6.0 project, including the DAQmxErrChk macro, if you have added NIDAQmxErrorCheck.bas to your project. After you copy and paste the code, you must complete the following cleanup items: Remove trailing semicolons. Declare variables that are used by the functions. Replace C constant values with Visual Basic 6.0 enumerations. Refer to the Enumerations section of this document for more information. Replace any C statements with Visual Basic 6.0 equivalents. For example, replace while loops with for loops.
Why do I get Error -200089: Task name specified conflicts with an existing task name when I call DAQmxCreateTask or DAQmxLoadTask?
This error occurs when you neglect to call DAQmxClearTask and then subsequently attempt to create another task with the same name without restarting the program. A common scenario in which this error occurs is while debugging a Visual Basic 6.0 program. If your program creates a task and hits a breakpoint and then you choose to stop debugging before your code calls DAQmxClearTask, you will get error -200089 the next time you run your program. This behavior is particular to Visual Basic 6.0 because Visual Basic 6.0 loads the NI-DAQmx driver into its own process and does not free it when you stop debugging. To work around this problem, ensure that you always call DAQmxClearTask or restart Visual Basic between debug sessions.
http://support.microsoft.com/kb/189133/EN-US/#kb2