設備的開啟與操作: 讀取视频設備序列號

本程序演示的是如何使用IC Imaging Control讀取一台設備的序列號。
語言:.NET C#/Visual Basic
版本:3.0.3
发布于:2005年4月7日
作者:IC Imaging Control 技術支持部
需求:IC Imaging Control >2.1
由WDM數據流類驅動程序驅動的相機、視頻轉換器或圖像採集卡

The dialog window of the sample application.

每台設備都有它自己的序列號,使之與其它設備區分開來。IC Imaging Control 的Device 對象有一個叫做GetSerialNumber的方法,可以獲取一台設備的序列號。

首先,程序在列錶框listBox1中列出系統中所有設備的名稱。 IC Imaging Control的Devices集合提供了這項功能。 程序員只需把listBox1.DataSource 的屬性設為icImagingControl1.Devices即可列出系統中的所有視頻設備。

[C#]
private void Form1_Load(object sender, System.EventArgs e)
{
    listBox1.DataSource = icImagingControl1.Devices;
}

用戶點擊listBox1中的任何一項後,程序通過listBox1.SelectedItem讀取相應的設備。 而後使用Device.GetSerialNumber讀出所選設備的序列號, 將其顯示在文本框txtSerial中:

[C#]
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
    Device selectedDevice = listBox1.SelectedItem as Device;

    if( selectedDevice != null )
    {
        string serial;
        if( selectedDevice.GetSerialNumber( out serial ) )
        {
            txtSerial.Text = serial;
        }
        else
        {
            txtSerial.Text = "No Serial Number";
        }
    }
}

注意:不是所有的視頻捕捉設備都允許程序讀取其序列號,所以程序需要檢查GetSerialNumber的返回值是否為空。

相關源代碼示例

責任聲明
IC Imaging Control源代碼庫中的所有代碼均只用於教學目的,The Imaging Source Europe GmbH作為IC Imaging Control的開發製造商,不對任何由於使用本文或其中源代碼所產生的後果承擔責任。

该网站为The Imaging Source网络的一部分。其它的站点包括 公司, Imaging, 天文相機, Astronomy Cameras Blog, Blog caméras d'astronomie, 天文相機有獎競答, TX Text Control, LiveDocx, phpLiveDocxForum.