Making Device Settings

This chapter shows you how to create a custom device settings dialog. The code is provided in reusable form, thus it can be easily integrated into your own applications.

IC Imaging Control also offers a built-in dialog, which can be used to select and set up a device. If, however, the dialog provided by IC Imaging Control does not fit your needs, this chapter shows you how to create a custom dialog. It will first show you how to integrate the sample code into your own projects and then how to actually build the dialog.

Integrating the sample code into your project

The sample code for this example can be found in the samples\VB6\Making Device Settings directory. To integrate the code into your project, you just have to add the file frmDeviceSettings.frm. Select Project from the menu and then select Add Form. In the Add Form dialog click on the Existing tab. Now browse to the sample folder and open the file frmDeviceSettings.frm.

To call the dialog from your application, just 2 lines of code are needed. First, the ICImagingControl instance that you are using in your application (here: ICImagingControl1 ) must be assigned to the dialog. Then the dialog has to be called. To do this, just insert the following lines at an appropriate place into your code.

Creating the Dialog

In this chapter, we will focus on the device settings dialog. In addition to the dialog, you will of course need an application that calls it. The sample code of this chapter contains a ready-to-run project with a small application that calls the dialog.

Assuming you have already set up a main project, you now have to add a new form to the project. This form will contain the elements of the custom dialog. To add a new form, select Project from the menu and then choose Add Form. Choose the Dialog type of form. Name the form frmDeviceSettings.

Now add 5 combo boxes to the form. Name them cboDevice, cboVideoNorm, cboVideoFormat, cboFrameRate and cboInputChannel. Also add a text box, called txtSerial and two check boxes named chkFlipV and chkFlipH.

In addition to the controls mentioned above, the sample dialog also contains a label named lblErrorMessage. The Visible property of this label is set to false, so that it will not be displayed when the dialog is called. The reason for this is explained when the Form_Load event is discussed.


Adding Functionality to the Dialog

First, we need a global data structure that will store the state of the device. This is necessary since that state has to be restored, if the user clicks the Cancel button of the dialog. For this sample, the data structure looks as follows:

Now add some global variables:

ImagingControl must be public since it is assigned from the main program before the dialog is called.

Now add a Form_Load event and insert the following code:

The Form_Load event checks, whether the live video is running. If it is, it reformats the dialog box to display a message to tell you that the dialog will not be displayed, while the live video is running. This behavior was implemented to point out that changing the device will cause side effects. The ring buffer collection ICImagingControl.ImageBuffers is reset when the device is changed. Therefore, image data in the collection is lost.

Now add the click events of the OK and the Cancel button and insert the following code accordingly:

As can be seen above, the Form_Load event calls a procedure SaveDeviceSettings and the CancelButton_Click event calls RestoreDeviceSettings. These are two helper procedures that fill and read out the global data structure DeviceState to save\restore the state of the device.

The UpdateDevices procedure that is called on the Form_Load event updates the controls of the dialog, but this will be discussed later.

Now add the click events for all 5 combo boxes and the 2 check boxes. On the click event of the device combo box, the currently selected device must be changed and all other combo boxes, the check boxes and the display of the serial number text field must be updated. This is done with the following code:

After the new device is selected, its serial number is retrieved. If a serial number is not available, n/a is displayed. The procedures UpdateVideoNorms, UpdateInputChannels and UpdateFlip update the controls. They will be discussed later. Please note that the video format and the frame rate are updated implicitly by UpdateVideoNorms and UpdateVideoFormat.

The click events for the other combo boxes are quite similar. The click event for the cboVideoNorm combo box includes a procedure UpdateVideoFormats, which is used to update the video format combo box according to the selected video norm. The click event for the cboVideoFormat combo box includes a procedure UpdateFrameRates that updates the frame rate combo box after the video format has changed. The other combo boxes just set the currently selected value. Here is the code for the video norm combo box:

The click events for the other combo boxes are implemented accordingly, except a minor detail, regarding the frame rate combo box. If you assign the new value for the frame rate, make sure you do a typecast, since cboFrameRate.Text returns a string, but ICImagingControl.DeviceFrameRate needs a floating point value.

Finally, add click events for the check boxes. They just toggle the horizontal and vertical flip:

The event for chkFlipH is implemented the same way.

The Update Procedures

As mentioned before, there is an Update procedure for every combo box and one for the two check boxes. The Update procedures for the combo boxes just fill the appropriate combo box with currently valid values. If the value that was selected before the update is still contained in the combo box, it is selected automatically. The code for the UpdateDevice procedure looks as follows:

The Update procedures for the other combo boxes are implemented accordingly, but note that ImagingControl.DeviceFrameRates returns a collection that contains floating point values. Therefore, in the UpdateFrameRates procedure, you must typecast them into a string before you can add them to the combo box.

The UpdateFlip procedure checks whether there is a vertical or horizontal flip available with the current device and sets their current state if possible:

<< Programmer's Guide