private void bnOpen_Click(object sender, EventArgs e) { if (m_stDeviceList.nDeviceNum == 0 || cmbDeviceList.SelectedIndex == -1) { ShowErrorMsg("No device, please select", 0); return; } // ch:获取选择的设备信息 | en:Get selected device information MyCamera.MV_GENTL_DEV_INFO device = (MyCamera.MV_GENTL_DEV_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[cmbDeviceList.SelectedIndex], typeof(MyCamera.MV_GENTL_DEV_INFO)); // ch:打开设备 | en:Open device if (null == m_MyCamera) { m_MyCamera = new MyCamera(); if (null == m_MyCamera) { return; } } int nRet = m_MyCamera.MV_CC_CreateDeviceByGenTL_NET(ref device); if (MyCamera.MV_OK != nRet) { return; } nRet = m_MyCamera.MV_CC_OpenDevice_NET(); if (MyCamera.MV_OK != nRet) { m_MyCamera.MV_CC_DestroyDevice_NET(); ShowErrorMsg("Device open fail!", nRet); return; } // ch:设置采集连续模式 | en:Set Continues Aquisition Mode m_MyCamera.MV_CC_SetEnumValue_NET("AcquisitionMode", (uint)MyCamera.MV_CAM_ACQUISITION_MODE.MV_ACQ_MODE_CONTINUOUS); m_MyCamera.MV_CC_SetEnumValue_NET("TriggerMode", (uint)MyCamera.MV_CAM_TRIGGER_MODE.MV_TRIGGER_MODE_OFF); // ch:控件操作 | en:Control operation SetCtrlWhenOpen(); }
private void DeviceListAcq() { // ch:创建设备列表 | en:Create Device List System.GC.Collect(); cmbDeviceList.Items.Clear(); cmbDeviceList.Text = ""; m_stDeviceList.nDeviceNum = 0; MyCamera.MV_GENTL_IF_INFO stIFInfo = (MyCamera.MV_GENTL_IF_INFO)Marshal.PtrToStructure(m_stIFInfoList.pIFInfo[cmbInterfaceList.SelectedIndex], typeof(MyCamera.MV_GENTL_IF_INFO)); int nRet = MyCamera.MV_CC_EnumDevicesByGenTL_NET(ref stIFInfo, ref m_stDeviceList); if (0 != nRet) { ShowErrorMsg("Enumerate devices fail!", 0); return; } // ch:在窗体列表中显示设备名 | en:Display device name in the form list for (int i = 0; i < m_stDeviceList.nDeviceNum; i++) { MyCamera.MV_GENTL_DEV_INFO device = (MyCamera.MV_GENTL_DEV_INFO)Marshal.PtrToStructure(m_stDeviceList.pDeviceInfo[i], typeof(MyCamera.MV_GENTL_DEV_INFO)); if (device.chUserDefinedName != "") { cmbDeviceList.Items.Add("Dev: " + device.chUserDefinedName + " (" + device.chSerialNumber + ")"); } else { cmbDeviceList.Items.Add("Dev: " + device.chVendorName + " " + device.chModelName + " (" + device.chSerialNumber + ")"); } } // ch:选择第一项 | en:Select the first item if (m_stDeviceList.nDeviceNum != 0) { cmbDeviceList.SelectedIndex = 0; } }