IMAQ Acquisition, Images, and Displaying in Visual Basic
Overview
ActiveX controls for NI-IMAQ and NI Vision come in two different sets. NI-IMAQ includes cwimaq to control the acquisition and cwimaqViewer to control the display. The Viewer is provided for display, but if you plan to distribute applications with the Viewer, you must purchase NI-Vision for Measurment Studio. Refer to the link below for more information on displaying images without the Viewer.
Table of Contents
Acquisition (CWIMAQ)
The cwimaq property pages allow you to configure your acquisition, signal I/O, and image attributes. Refer to Getting Started with ComponentWorks for more information on the property pages. The following illustrations demonstrate how each type of acquisition is configured using the property pages:
Figure 1
The following VB code works with any of the modes listed above:
‘Put the first Image into the viewer. Viewer automatically updates when new data is in the Image
Private Sub StartButton_Click()
CWIMAQViewer1.Attach CWIMAQ1.Images(1) 'Displays the acquired images in the viewer
CWIMAQ1.Start
End Sub
Private Sub StopButton_Click()
‘Check to see if acquisition in progress. For snap and sequence, may not be acquiring anymore
If CWIMAQ1.AcquisitionInProgress Then
CWIMAQ1.Stop
End If
End Sub
If you used this code with a multiple buffer acquisition, such as a ring or sequence, the viewer will only display the first buffer because it is hardcoded to 1. Refer to the following code to display each buffer acquired for the ring and sequence example:
Private Sub StartButton_Click()
CWIMAQ1.Start
End Sub
Private Sub CWIMAQ1_AcquiredImage(ImageIndex As Variant)
CWIMAQViewer1.Attach CWIMAQ1.Images(ImageIndex)
End Sub
Private Sub StopButton_Click()
‘Check to see if acquisition in progress.
If CWIMAQ1.AcquisitionInProgress Then
CWIMAQ1.Stop
End If
End Sub
Where to find examples:
C:\Program Files\National Instruments\NI-IMAQ\Sample\VB
See Also:
Getting Started with ComponentWorks
Getting Results with ComponentWorks IMAQ Vision
IMAQ Grab Examples
IMAQ Snap Examples
IMAQ Sequence Examples
Signal I/O
From the Signal I/O tab, you can also configure triggers, route internal signals to RTSI or External Trigger lines, and generate pulses:

Once these settings are configured, use the command CWIMAQ.Configure to start the acquisition.
Where to find examples:
C:\Program Files\National Instruments\NI-IMAQ\Sample\VB\Trigger
C:\Program Files\National Instruments\MeasurementStudio\VB\Samples\IMAQ\2. Functions
See Also:
Factors to Consider when Triggering
Pulse Generation and Trigger Drive Examples
Triggering IMAQ Acquisition Examples
Measure IMAQ Triggers with DAQ
Display (CWIMAQViewer)
The cwimaqViewer control allows you to attach images to the Viewer to display images. The following sample code demonstrates a grab and display:
Private Sub Form_Load()
‘Starts Acquisition
CWIMAQ1.Start
‘Attaches image from acquisition to Viewer
CWIMAQViewer1.Attach CWIMAQ1.Images(1)
End Sub
Once the image is attached, the Viewer automatically updates when the image changes. Use the Viewer control to set the tools, display options, zoom factors, and palettes. Viewers can have objects attached or associates, such as images or regions of interest, that you can access through the Viewer control.
The CWIMAQImage is a separate object with its own properties, methods and other objects attached, such as overlays and calibration, that are associated with the Viewer when an image is attached. The CWIMAQImage object does not have an ActiveX Control to place on the form. Use one of the following methods to create a CWIMAQImage:
- Use the key word New to create a new image:
Dim MyImage as New CWIMAQImage
- Let CWIMAQ allocate the images for you. When you define the properties for an acquisition, the number of buffers you specify determines how many images CWIMAQ will allocate automatically. You can then access those images using CWIMAQ1.Images(n) where n is the image number you want (1 based). This technique was used in the acquisition example above.
- Set an empty image object to be associated with an allocated one: Private Sub Form_Load()
Dim myImage As CWIMAQImage
‘Didn’t use New here
Set myImage = CWIMAQ1.Images(1)
‘So I must use Set here
CWIMAQ1.Start
‘Now I can attach myImage
CWIMAQViewer1.Attach myImage
End Sub - Set and New are VB specific commands. If you want to use CWIMAQImage in another environment, use the method CWImaqVision1.CreateCWIMAQImage, which is equivalent to New. CWIMAQImage myImage;
myImage = CWIMAQVision1.CreateCWIMAQImage();
C:\Program Files\National Instruments\NI-IMAQ\Sample\VB\Display
See Also:
Display Examples
Display Events Examples
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
