IC Imaging Control ActiveX

Using the VCD Simple Property Class

Using the VCD Simple Property Class

Up to the version 1.41 of IC Imaging Control, the properties of a device could be accessed using the properties %%Auto, %%AutoAvailable, %%Available, %%Default and %%Range. These properties have been depreciated as of version 2.0. The new VCD properties allow more detailed and generic access to the device's properties but require a little more code to be written. If you are happy with the old properties, a new helper class is introduced in version 2.0 that provides access methods to the VCD properties, which are similar to the old way. This chapter shows you how to use this helper class.

Setting up the Project

The source code for this sample program can be found in the samples\VB6\VCD Simple Property sample source directory. It also uses some files, which are located in the samples\VB6\common directory.

Create a new project and add IC Imaging Control to the form. Before you run the program, select the video device, input and video format as shown in the First Steps in Visual Basic 6 chapter. Alternatively, run the program without selecting a device. In this case, the program shows the device selection dialog provided by IC Imaging Control. If you close this dialog without having made a selection, the program will display an error message and terminate.

In order to use the VCDSimpleProperty class, some files have to be added to the project. Select Project from the menu and then choose Add Class Module. Now click on the Existing tab and browse to the samples\VB6\common directory. Select the file VCDSimpleProperty.cls and click Open. The class is now added to the project. Now we need to add two modules. To do this, select Project from the menu and then choose Add Module. In the dialog, click the Existing tab and browse to the samples\VB6\common directory. Mark the file VCDSimpleModule.bas and click the Open button. Do the same to add the file VCDPropertyID.bas. Now you are ready to use the VCDSimpleProperty class.

Accessing a Property

First, we add some controls to the form. They will allow us to manipulate a device property. Add a slider, a label and a check box to the form. Name the slider sldWhiteBalance, the label lblWhiteBalanceValue and the check box chkWhiteBalanceAuto. These controls will be used to manipulate the "WhiteBalance" property of a device.

image

Of course we need an instance of the helper class in order to use it. Therefore, add a global variable:

Private VCDProp As VCDSimpleProperty

The helper class and the controls are initialized in the Form_Load event, so add a Form_Load and insert the following code:

Private Sub Form_Load()
    ' If a device has not yet been selected, show the device selection dialog.
    If Not ICImagingControl1.DeviceValid Then
        ICImagingControl1.ShowDeviceSettingsDialog

        If Not ICImagingControl1.DeviceValid Then
            MsgBox "No device was selected."
            Unload Me
            Exit Sub
        End If
    End If

    ICImagingControl1.OverlayBitmapPosition = PATHPOSITION_NONE

    ' Initialize the VCDProp class to access the properties of the
    ' ICImagingControl object.
    Set VCDProp = GetSimplePropertyContainer(ICImagingControl1.VCDPropertyItems)

    ' Initialize the auto checkbox.
    If Not VCDProp.AutoAvailable(VCDID_WhiteBalance) Then
        chkWhiteBalanceAuto.Enabled = False
        cmdWhiteBalanceOnePush.Enabled = False
    Else
        VCDProp.Automation(VCDID_WhiteBalance) = False
    End If

    ' Initialize the slider and the label.
    If Not VCDProp.Available(VCDID_WhiteBalance) Then
        sldWhiteBalance.Enabled = False
    Else
        sldWhiteBalance.Enabled = True
        On Error Resume Next
        sldWhiteBalance.Min = VCDProp.RangeMin(VCDID_WhiteBalance)
        sldWhiteBalance.Max = VCDProp.RangeMax(VCDID_WhiteBalance)
        sldWhiteBalance.Value = VCDProp.RangeValue(VCDID_WhiteBalance)
        sldWhiteBalance.TickFrequency = (sldWhiteBalance.Max - sldWhiteBalance.Min) / 10
        lblWhiteBalanceValue = sldWhiteBalance.Value
    End If

    ' start live mode.
    ICImagingControl1.LiveStart
End Sub

To add functionality to the controls, add a Scroll event for the slider and a Click event for the check box. If these events are called, the "WhiteBalance" property is updated appropriately. The following code will do this:

Private Sub sldWhiteBalance_Scroll()
    ' Set the value for WhiteBalance.
    VCDProp.RangeValue(VCDID_WhiteBalance) = sldWhiteBalance.Value

    ' Display the current value for WhiteBalance.
    lblWhiteBalanceValue = VCDProp.RangeValue(VCDID_WhiteBalance)
End Sub
Private Sub chkWhiteBalanceAuto_Click()
    If chkWhiteBalanceAuto.Value = 1 Then
        VCDProp.Automation(VCDID_WhiteBalance) = True
        sldWhiteBalance.Enabled = False
    Else
        VCDProp.Automation(VCDID_WhiteBalance) = False
        sldWhiteBalance.Enabled = True
    End If
End Sub

Accessing advanced Properties

There are some properties that allow a more detailed access than the one described above. In case of "WhiteBalance" it is possible to specify a value for red and blue and to perform an automatic adjustment for a limited time called one push. These advanced properties can be accessed using the following IDs: VCDElement_WhiteBalanceBlue and VCDElement_WhiteBalanceRed. The "One Push" operation is triggered by calling the VCDSimpleProperty.OnePush method with either VCDID_WhiteBalance, VCDElement_WhiteBalanceBlue or VCDElement_WhiteBalanceRed as a parameter.

The following sample shows you how to access "WhiteBalanceBlue" and "WhiteBalanceRed" property. It will also access the "Brightness" property to show the difference between the standard property and the advanced way.

After setting up the project as described in the "Setting up the Project" section of this document, add some controls to the form. Add 3 sliders and name them sldBrightness, sldWhiteBalanceBlue and sldWhiteBalanceRed. Now add 2 check boxes. Label them Auto and name them chkBrightnessAuto and chkWhiteBalanceAuto respectively. Finally, add a button to the form and name it cmdWhiteBalanceOnePush. Label the button One Push.

image

Now add an instance of the helper class to your code:

Private VCDProp As VCDSimpleProperty

The helper class and the controls are initialized in the Form_Load event. Add a Form_Load event and insert the following code:

Private Sub Form_Load()

    ' If no device is selected yet, show the device selection dialog
    If Not ICImagingControl1.DeviceValid Then
        ICImagingControl1.ShowDeviceSettingsDialog

        If Not ICImagingControl1.DeviceValid Then
            MsgBox "No device was selected."
            Unload Me
            Exit Sub
        End If
    End If

    ICImagingControl1.ScrollbarsEnabled = True

    ' Initialize the VCDProp class to access the properties of our ICImagingControl
    ' object
    Set VCDProp = GetSimplePropertyContainer(ICImagingControl1.VCDPropertyItems)

    ' Initialize the auto checkboxes
    If Not VCDProp.AutoAvailable(VCDID_Brightness) Then
        chkBrightnessAuto.Enabled = False
    Else
        VCDProp.Automation(VCDID_Brightness) = False
    End If

    If Not VCDProp.AutoAvailable(VCDID_WhiteBalance) Then
        chkWhiteBalanceAuto.Enabled = False
        cmdWhiteBalanceOnePush.Enabled = False
    Else
        VCDProp.Automation(VCDID_WhiteBalance) = False
    End If


    ' Initialize the brightness slider
    If Not VCDProp.Available(VCDID_Brightness) Then
        sldBrightness.Enabled = False
    Else
        sldBrightness.Enabled = True
        sldBrightness.Min = VCDProp.RangeMin(VCDID_Brightness)
        sldBrightness.Max = VCDProp.RangeMax(VCDID_Brightness)
        sldBrightness.Value = VCDProp.RangeValue(VCDID_Brightness)
        sldBrightness.TickFrequency = (sldBrightness.Max - sldBrightness.Min) / 10
        lblBrightnessValue = sldBrightness.Value
    End If

    ' Initialize the whitebalance blue slider
    If Not VCDProp.Available(VCDElement_WhiteBalanceBlue) Then
        sldWhiteBalanceBlue.Enabled = False
    Else
        sldWhiteBalanceBlue.Enabled = True
        sldWhiteBalanceBlue.Min = VCDProp.RangeMin(VCDElement_WhiteBalanceBlue)
        sldWhiteBalanceBlue.Max = VCDProp.RangeMax(VCDElement_WhiteBalanceBlue)
        sldWhiteBalanceBlue.Value = VCDProp.RangeValue(VCDElement_WhiteBalanceBlue)
        sldWhiteBalanceBlue.TickFrequency = (sldWhiteBalanceBlue.Max - sldWhiteBalanceBlue.Min) / 10
        lblWhiteBalanceBlueValue = sldWhiteBalanceBlue.Value
    End If

    ' Initialize the whitebalance red slider
    If Not VCDProp.Available(VCDElement_WhiteBalanceRed) Then
        sldWhiteBalanceRed.Enabled = False
    Else
        sldWhiteBalanceRed.Enabled = False
        sldWhiteBalanceRed.Enabled = True
        sldWhiteBalanceRed.Min = VCDProp.RangeMin(VCDElement_WhiteBalanceRed)
        sldWhiteBalanceRed.Max = VCDProp.RangeMax(VCDElement_WhiteBalanceRed)
        sldWhiteBalanceRed.Value = VCDProp.RangeValue(VCDElement_WhiteBalanceRed)
        sldWhiteBalanceRed.TickFrequency = (sldWhiteBalanceRed.Max - sldWhiteBalanceRed.Min) / 10
        lblWhiteBalanceRedValue = sldWhiteBalanceRed.Value
    End If

    ' start live mode
    ICImagingControl1.LiveStart
End Sub

As you can see above, the initialization of the sliders for the "WhiteBalanceBlue" and "WhiteBalanceRed" value is done in exactly the same way as the initialization of the slider for the "Brightness" value. The only difference is that you use the appropriate "Element ID" to specify the property instead of the "Item ID".

Now we need some events to update the properties accordingly. First, add a Scroll event for every slider. The code for the Scroll event of the "Brightness" slider looks as follows:

Private Sub sldBrightness_Scroll()
    VCDProp.RangeValue(VCDID_Brightness) = sldBrightness.Value
    lblBrightnessValue = VCDProp.RangeValue(VCDID_Brightness)
End Sub

The Scroll event for the "WhiteBalanceBlue" resp. "WhiteBalanceRed" slider is similar.

Add a Click event for both check boxes. The code for these looks as follows:

Private Sub chkBrightnessAuto_Click()
    If chkBrightnessAuto.Value = 1 Then
        VCDProp.Automation(VCDID_Brightness) = True
        sldBrightness.Enabled = False
    Else
        VCDProp.Automation(VCDID_Brightness) = False
        sldBrightness.Enabled = True
    End If
End Sub
Private Sub chkWhiteBalanceAuto_Click()
    If chkWhiteBalanceAuto.Value = 1 Then
        VCDProp.Automation(VCDID_WhiteBalance) = True
        sldWhiteBalanceBlue.Enabled = False
        sldWhiteBalanceRed.Enabled = False
        cmdWhiteBalanceOnePush.Enabled = False
    Else
        VCDProp.Automation(VCDID_WhiteBalance) = False
        sldWhiteBalanceBlue.Enabled = True
        sldWhiteBalanceRed.Enabled = True
        cmdWhiteBalanceOnePush.Enabled = True
    End If
End Sub

Now add the Click event for the cmdWhiteBalanceOnePush button and insert the following code:

Private Sub cmdWhiteBalanceOnePush_Click()
    VCDProp.OnePush (VCDID_WhiteBalance)
End Sub

<< Programmer's Guide

Get in touch with us


About The Imaging Source

Established in 1990, The Imaging Source is one of the leading manufacturers of industrial cameras, frame grabbers and video converters for production automation, quality assurance, logistics, medicine, science and security.

Our comprehensive range of cameras with USB 3.1, USB 3.0, USB 2.0, GigE interfaces and other innovative machine vision products are renowned for their high quality and ability to meet the performance requirements of demanding applications.

Automated Imaging Association ISO 9001:2015 certified

Contact us