public string[] ScanAlldevice() { uInterface = system.InterfaceCount; //comboBox1.Items.Clear(); for (uint i = 0; i < uInterface; i++) { StInterface = system.GetIStInterface(i); //IStInterface tmpInterFacePtr = StSystem.GetIStInterface(i); IStInterfaceInfo tmpInterFaceInfoPtr = StInterface.GetIStInterfaceInfo(); uint uintDeviceCnt = StInterface.DeviceCount; Array.Resize(ref cameraIDStringArray, (int)uCamCnt + (int)uintDeviceCnt); Array.Resize(ref cameraNameStringArray, (int)uCamCnt + (int)uintDeviceCnt); Array.Resize(ref StDevice, (int)uCamCnt + (int)uintDeviceCnt); Array.Resize(ref dataStream, (int)uCamCnt + (int)uintDeviceCnt); for (uint j = 0; j < uintDeviceCnt; j++) { IStDeviceInfo tmpDeviceInfoPtr = StInterface.GetIStDeviceInfo(j); cameraIDStringArray[uCamCnt] = tmpDeviceInfoPtr.ID; cameraNameStringArray[uCamCnt] = tmpDeviceInfoPtr.DisplayName; eDeviceAccessFlags deviceAccessFlags = eDeviceAccessFlags.CONTROL; if (tmpDeviceInfoPtr.AccessStatus == eDeviceAccessStatus.READONLY) { deviceAccessFlags = eDeviceAccessFlags.READONLY; } StDevice[uCamCnt] = StInterface.CreateStDevice(cameraIDStringArray[uCamCnt], deviceAccessFlags); dataStream[uCamCnt] = StDevice[uCamCnt].CreateStDataStream(0); this.cameras[tmpDeviceInfoPtr.ID] = new MvaOmronSentechCameraLdd(StDevice[uCamCnt], dataStream[uCamCnt]); uCamCnt++; } } return(cameraNameStringArray); }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) { // ==== Connect to target camera with camera serial. ================================================================ // Input Serial. System.Console.WriteLine("Please input serial number of target camera: "); string sTgtCameraSerial = System.Console.ReadLine(); // Acquire interface counts. uint uiInterfaceCnt = system.InterfaceCount; // Prepear gcstring for saving device ID if hit. string strTgtDeviceID = ""; // Prepear for # of interface for later use. uint uiTgtInterfaceNo = 0; // Camera found hit flag. bool bHit = false; // Check all interface if target camera is exist. for (uint i = 0; i < uiInterfaceCnt; i++) { IStInterface tmpInterface = system.GetIStInterface(i); uint uiCamCnt = tmpInterface.DeviceCount; for (uint j = 0; j < uiCamCnt; j++) { IStDeviceInfo tmpDevInfo = tmpInterface.GetIStDeviceInfo(j); if (tmpDevInfo.SerialNumber == sTgtCameraSerial) { strTgtDeviceID = tmpDevInfo.ID; uiTgtInterfaceNo = i; bHit = true; break; } } if (bHit) { break; } } if (!bHit) { // Not found, exit program with message. System.Console.WriteLine("Target camera not found."); System.Console.WriteLine("Press Enter to exit."); Console.ReadLine(); return; } // Create IStDevice via using found device ID. using (CStDevice device = system.GetIStInterface(uiTgtInterfaceNo).CreateStDevice(strTgtDeviceID)) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); // Display the information of the acquired image data. Byte[] imageData = stImage.GetByteArray(); Console.Write("BlockId=" + streamBuffer.GetIStStreamBufferInfo().FrameID); Console.Write(" Size:" + stImage.ImageWidth + " x " + stImage.ImageHeight); Console.Write(" First byte =" + imageData[0] + Environment.NewLine); } else { Console.WriteLine("Image data does not exist."); } } } device.AcquisitionStop(); dataStream.StopAcquisition(); } } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }