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()) // ============================================================================================= // Note: Creating system will generate a broadcast device scan. using (CStSystem system = new CStSystem(eStSystemVendor.Sentech, eStInterfaceType.GigEVision)) { // Input target IP address for scanning. Console.Write("Please input camera IP address for unicast camera scanning: "); string value = Console.ReadLine(); IPAddress ipaddr; // Try parse the input address, if failed exit program. if (!IPAddress.TryParse(value.Trim(), out ipaddr)) { Console.WriteLine("IP address is not valid."); Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); Environment.Exit(0); } // Convert the IP address string to a 32-bit number. byte[] bytes = ipaddr.GetAddressBytes(); uint uiTgtDevIPAddress = (uint)(IPAddress.NetworkToHostOrder(BitConverter.ToUInt32(bytes, 0)) >> 32); // Acquire interface counts uint uiCntInterface = system.InterfaceCount; for (uint i = 0; i < uiCntInterface; i++) { IStInterface pInterface = system.GetIStInterface(i); // Set Discovery Command Distination IP Address to enable the unicast camera scanning. // *This is 255.255.255.255 in default for boradcast device scanning. INodeMap nodeMapInterface = pInterface.GetIStPort().GetINodeMap(); IInteger intDistiantionIPAddress = nodeMapInterface.GetNode <IInteger>("GevDeviceDiscoveryCommandDestinationIPAddress"); intDistiantionIPAddress.SetValue(uiTgtDevIPAddress, false); // After setting distination IP, call update for actual scanning process. // Unicast scanning package will be sent via this function. pInterface.UpdateDeviceList(); } using (CStDevice device = system.CreateFirstStDevice()) { // Print out information of device if found and connected. // Otherwise it will goes into exception handling. Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); Console.WriteLine("Device found and connected."); } } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
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(); } }