public void Connect() { api = new CStApiAutoInit(); system = new CStSystem(); StDevice = new CStDevice[0]; dataStream = new CStDataStream[0]; cameraIDStringArray = new string[0]; cameraNameStringArray = new string[0]; }
static void Main(string[] args) { try { // Initialize StApi before using. using (CStApiAutoInit api = new CStApiAutoInit()) // Create a system object for device scan and connection. using (CStSystem system = new CStSystem()) // Create a camera device object and connect to first detected device. using (CStDevice device = system.CreateFirstStDevice()) #if ENABLED_ST_GUI // If using GUI for display, create a display window here. using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) #endif // Create a DataStream object for handling image stream data. using (CStDataStream dataStream = device.CreateStDataStream(0)) { // Displays the DisplayName of the device. Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // Register callback method. Note that by different usage, we pass different kinds/numbers of parameters in. #if ENABLED_ST_GUI object[] param = { wnd }; dataStream.RegisterCallbackMethod(OnCallback, param); #else dataStream.RegisterCallbackMethod(OnCallback); #endif // Start the image acquisition of the host (local machine) side. dataStream.StartAcquisition(); // Start the image acquisition of the camera side. device.AcquisitionStart(); // Keep getting image until Enter key pressed. Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); // Stop the image acquisition of the camera side. device.AcquisitionStop(); // Stop the image acquisition of the host side. dataStream.StopAcquisition(); } } catch (Exception e) { // If any exception occurred, display the description of the error here. Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } }
public void Close() { if (dataStream != null) { // 停止主機取像 for (int i = 0; i < uCamCnt; i++) { dataStream[i].Dispose(); dataStream[i] = null; } } if (StDevice != null) { // 停止相機取像 for (int i = 0; i < uCamCnt; i++) { StDevice[i].Dispose(); StDevice[i] = null; } } if (api != null) { api.Dispose(); api = null; } if (system != null) { system.Dispose(); system = null; } foreach (var camera in this.cameras) { camera.Value.Dispose(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of PixelFormat change. // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Set Pixel Format to Mono8. IEnum enumPixelFormat = nodeMap.GetNode <IEnum>("PixelFormat"); enumPixelFormat.FromString("Mono8"); // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } 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(); } }
static void Main(string[] args) { try { // Initialize StApi before using. using (CStApiAutoInit api = new CStApiAutoInit()) // Create a system object for device scan and connection. using (CStSystem system = new CStSystem()) // Create a camera device object and connect to first detected device. using (CStDevice device = system.CreateFirstStDevice()) // Create a DataStream object for handling image stream data. using (CStDataStream dataStream = device.CreateStDataStream(0)) { // Displays the DisplayName of the device. Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // Start the image acquisition of the host (local machine) side. dataStream.StartAcquisition(nCountOfImagesToGrab); // Start the image acquisition of the camera side. device.AcquisitionStart(); // Get the path of the image files. string fileNameHeader = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); fileNameHeader += @"\" + device.GetIStDeviceInfo().DisplayName + @"\" + device.GetIStDeviceInfo().DisplayName; bool isImageSaved = false; // Get the file name of the image file of the StApiRaw file format string fileNameRaw = fileNameHeader + ".StApiRaw"; // Retrieve the buffer of image data with a timeout of 5000ms. using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { // Check if the acquired data contains image data. if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { // If yes, we create a IStImage object for further image handling. IStImage stImage = streamBuffer.GetIStImage(); Byte[] imageData = stImage.GetByteArray(); // Display the information of the acquired image data. Console.Write("BlockId=" + streamBuffer.GetIStStreamBufferInfo().FrameID); Console.Write(" Size:" + stImage.ImageWidth + " x " + stImage.ImageHeight); Console.Write(" First byte =" + imageData[0] + Environment.NewLine); // Create a still image file handling class object (filer) for still image processing. using (CStStillImageFiler stillImageFiler = new CStStillImageFiler()) { // Save the image file as StApiRaw file format with using the filer we created. Console.Write(Environment.NewLine + "Saving " + fileNameRaw + "... "); stillImageFiler.Save(stImage, eStStillImageFileFormat.StApiRaw, fileNameRaw); Console.Write("done" + Environment.NewLine); isImageSaved = true; } } else { // If the acquired data contains no image data. Console.WriteLine("Image data does not exist."); } } // Stop the image acquisition of the camera side. device.AcquisitionStop(); // Stop the image acquisition of the host side. dataStream.StopAcquisition(); // The following code shows how to load the saved StApiRaw and process it. if (isImageSaved) { // Create a buffer for storing the image data from StApiRaw file. using (CStImageBuffer imageBuffer = CStApiDotNet.CreateStImageBuffer()) // Create a still image file handling class object (filer) for still image processing. using (CStStillImageFiler stillImageFiler = new CStStillImageFiler()) // Create a data converter object for pixel format conversion. using (CStPixelFormatConverter pixelFormatConverter = new CStPixelFormatConverter()) { // Load the image from the StApiRaw file into buffer. Console.Write(Environment.NewLine + "Loading " + fileNameRaw + "... "); stillImageFiler.Load(imageBuffer, fileNameRaw); Console.Write("done" + Environment.NewLine); // Convert the image data to BGR8 format. pixelFormatConverter.DestinationPixelFormat = eStPixelFormatNamingConvention.BGR8; pixelFormatConverter.Convert(imageBuffer.GetIStImage(), imageBuffer); // Get the IStImage interface to the converted image data. IStImage stImage = imageBuffer.GetIStImage(); // Save as Bitmap { // Bitmap file extension. string imageFileName = fileNameHeader + ".bmp"; // Save the image file in Bitmap format. Console.Write(Environment.NewLine + "Saving " + imageFileName + "... "); stillImageFiler.Save(stImage, eStStillImageFileFormat.Bitmap, imageFileName); Console.Write("done" + Environment.NewLine); } // Save as Tiff { // Tiff file extension. string imageFileName = fileNameHeader + ".tif"; // Save the image file in Tiff format. Console.Write(Environment.NewLine + "Saving " + imageFileName + "... "); stillImageFiler.Save(stImage, eStStillImageFileFormat.TIFF, imageFileName); Console.Write("done" + Environment.NewLine); } // Save as PNG { // PNG file extension. string imageFileName = fileNameHeader + ".png"; // Save the image file in PNG format. Console.Write(Environment.NewLine + "Saving " + imageFileName + "... "); stillImageFiler.Save(stImage, eStStillImageFileFormat.PNG, imageFileName); Console.Write("done" + Environment.NewLine); } // Save as JPEG { // JPEG file extension. string imageFileName = fileNameHeader + ".jpg"; // Save the image file in JPEG format. stillImageFiler.Quality = 75; Console.Write(Environment.NewLine + "Saving " + imageFileName + "... "); stillImageFiler.Save(stImage, eStStillImageFileFormat.JPEG, imageFileName); Console.Write("done" + Environment.NewLine); } // Save as CSV { // CSV file extension. string imageFileName = fileNameHeader + ".csv"; // Save the image file in CSV format. Console.Write(Environment.NewLine + "Saving " + imageFileName + "... "); stillImageFiler.Save(stImage, eStStillImageFileFormat.CSV, imageFileName); Console.Write("done" + Environment.NewLine); } } } } } catch (Exception e) { // If any exception occurred, display the description of the error here. Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { // Wait until the Enter key is pressed. 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)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of changing acquisition frame rate (FPS) // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Switch off exposure auto. If exposure auto is on, FPS setting may not able to implemented. IEnum enumExposureAuto = nodeMap.GetNode <IEnum>("ExposureAuto"); enumExposureAuto.FromString("Off"); // Also switch Exposure Mode to Off for not letting exposure time to influence the actual FPS. IEnum enumExposureMode = nodeMap.GetNode <IEnum>("ExposureMode"); enumExposureMode.FromString("Off"); // Get Node for Acquisition Frame Rate then set FPS to 2. IFloat floatFPS = nodeMap.GetNode <IFloat>("AcquisitionFrameRate"); floatFPS.SetValue(2, false); // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } 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(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of set digital Gain to 2 times. // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Switch off gain auto. If gain auto is on, gain value cannot be set. IEnum enumGainAuto = nodeMap.GetNode <IEnum>("GainAuto"); enumGainAuto.FromString("Off"); // For setting digital gain, gain selector need to be set to DigitalAll to access digital gain. IEnum enumGainSelector = nodeMap.GetNode <IEnum>("GainSelector"); enumGainSelector.FromString("DigitalAll"); // Get Node for Gain IFloat floatGain = nodeMap.GetNode <IFloat>("Gain"); // Set digital gain to 2 times(128). floatGain.Value = 128; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } 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(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of Setting Hardware Trigger ON with active high // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Switch BalanceWhiteAuto to Preset0 for manual input value IEnum enumBalanceWhiteAuto = nodeMap.GetNode <IEnum>("BalanceWhiteAuto"); enumBalanceWhiteAuto.FromString("Preset0"); // Switch balance ration selector to Red for access Red ratio value IEnum enumBalanceRatioSelector = nodeMap.GetNode <IEnum>("BalanceRatioSelector"); enumBalanceRatioSelector.FromString("Red"); // Get Node for BalanceRatio IFloat floatBalanceRatio = nodeMap.GetNode <IFloat>("BalanceRatio"); // Set BalanceRatio to 10 floatBalanceRatio.Value = 10; // Switch balance ration selector to Blue for access Blue ratio value enumBalanceRatioSelector.FromString("Blue"); // Set BalanceRatio to 10 floatBalanceRatio.Value = 10; // Switch balance ration selector to Green for access Green ratio value enumBalanceRatioSelector.FromString("Green"); // Set BalanceRatio to 10 floatBalanceRatio.Value = 10; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } 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(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of changing exposure time(us) of camera. // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Switch off exposure auto. If exposure auto is on, exposure time cannot be set. IEnum enumExposureAuto = nodeMap.GetNode <IEnum>("ExposureAuto"); enumExposureAuto.FromString("Off"); // For setting camera exposure time, exposure mode must set to Timed to enable value input IEnum enumExpoMode = nodeMap.GetNode <IEnum>("ExposureMode"); enumExpoMode.FromString("Timed"); // Get Node for ExposureTime IFloat floatExpoTime = nodeMap.GetNode <IFloat>("ExposureTime"); // Set Exposure time to 100,000 usec floatExpoTime.Value = 100000; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } 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(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of using Filter to rotate image clock wise 90 degree. // Create an ReverseConverter filter object. CStReverseConverter filter = new CStReverseConverter(); // Set ReverseConverter reverse to clock wise 90 degree. filter.RotationMode = eStRotationMode.Clockwise90; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } // ============================================================================================================== // Create another buffer for storing rotated image CStImageBuffer imageBuffer = CStApiDotNet.CreateStImageBuffer(); // Rotate original image and output to another buffer filter.Convert(stImage, imageBuffer); // Display rotated image wnd.RegisterIStImage(imageBuffer.GetIStImage()); // ============================================================================================================== } 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(); } }
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(); } }
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)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of Setting Line2 as Strobe Out // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Set Line2 to output IEnum enumLineSelector = nodeMap.GetNode <IEnum>("LineSelector"); enumLineSelector.FromString("Line2"); IEnum enumLineMode = nodeMap.GetNode <IEnum>("LineMode"); enumLineMode.FromString("Output"); // Switch Line2 output source to Timer 0 Active IEnum enumLineSource = nodeMap.GetNode <IEnum>("LineSource"); enumLineSource.FromString("Timer0Active"); // Set Timer 0 trigger source to Exposure Start, which means Timer 0 will output signal when camera start exposure IEnum enumTimerSelector = nodeMap.GetNode <IEnum>("TimerSelector"); enumTimerSelector.FromString("Timer0"); // Set exposure start as the trigger source of Timer0 IEnum enumTimerTriggerSource = nodeMap.GetNode <IEnum>("TimerTriggerSource"); enumTimerTriggerSource.FromString("ExposureStart"); // Set Timer0 output duration to 1000us IFloat floatTimerDuration = nodeMap.GetNode <IFloat>("TimerDuration"); floatTimerDuration.Value = 1000; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } 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(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of Setting Software Trigger ON // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Switch on Trigger Mode(IEnumeration). IEnum enumTriggerMode = nodeMap.GetNode <IEnum>("TriggerMode"); enumTriggerMode.FromString("On"); // Set Trigger Source to Software IEnum enumTriggerSource = nodeMap.GetNode <IEnum>("TriggerSource"); enumTriggerSource.FromString("Software"); // Prepear Software Trigger Command for later calling ICommand cmdTriggerSoftware = nodeMap.GetNode <ICommand>("TriggerSoftware"); // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { // =============================================================================== // Demostration sending software trigger cmdTriggerSoftware.Execute(); Console.WriteLine("Software Trigger Sent."); // =============================================================================== using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } else { Console.WriteLine("Image data does not exist."); } } } device.AcquisitionStop(); dataStream.StopAcquisition(); // ============================================================================================================== // Set Software Trigger OFF after using // Switch off Trigger Mode(IEnumeration) after acquiring. enumTriggerMode.FromString("Off"); // ============================================================================================================== } } 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 { // Initialize StApi before using. using (CStApiAutoInit api = new CStApiAutoInit()) // Create a system object for device scan and connection. using (CStSystem system = new CStSystem()) // Create a camera device object and connect to first detected device by using the function of system object. using (CStDevice device = system.CreateFirstStDevice()) #if ENABLED_ST_GUI // If using GUI for display, create a display window here. using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) #endif // Create a DataStream object for handling image stream data. using (CStDataStream dataStream = device.CreateStDataStream(0)) { // Displays the DisplayName of the device. Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // Start the image acquisition of the host (local machine) side. dataStream.StartAcquisition(nCountOfImagesToGrab); // Start the image acquisition of the camera side. device.AcquisitionStart(); // A while loop for acquiring data and checking status. // Here, the acquisition runs until it reaches the assigned numbers of frames. while (dataStream.IsGrabbing) { // Retrieve the buffer of image data with a timeout of 5000ms. // Use the 'using' statement for automatically managing the buffer re-queue action when it's no longer needed. using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { // Check if the acquired data contains image data. if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { // If yes, we create a IStImage object for further image handling. IStImage stImage = streamBuffer.GetIStImage(); #if ENABLED_ST_GUI // Acquire detail information of received image and display it onto the status bar of the display window. string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); // Check if display window is visible. if (!wnd.IsVisible) { // Set the position and size of the window. wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); // Create a new thread to display the window. wnd.Show(eStWindowMode.ModalessOnNewThread); } // Register the image to be displayed. // This will have a copy of the image data and original buffer can be released if necessary. wnd.RegisterIStImage(stImage); #else // 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); #endif } else { // If the acquired data contains no image data. Console.WriteLine("Image data does not exist."); } } } // Stop the image acquisition of the camera side. device.AcquisitionStop(); // Stop the image acquisition of the host side. dataStream.StopAcquisition(); } } catch (Exception e) { // If any exception occurred, display the description of the error here. Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { // Wait until the Enter key is pressed. Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }
static void Main(string[] args) { try { // Initialize StApi before using. using (CStApiAutoInit api = new CStApiAutoInit()) // Create a system object for device scan and connection. using (CStSystem system = new CStSystem()) // Create a camera device list object to store all the cameras. using (CStDeviceArray deviceList = new CStDeviceArray()) // Create a DataStream list object to store all the data stream object related to the cameras. using (CStDataStreamArray dataStreamList = new CStDataStreamArray()) { { CStDevice device = null; while (true) { try { // Create a camera device object and connect to first detected device. device = system.CreateFirstStDevice(); } catch { if (deviceList.GetSize() == 0) { throw; } break; } // Add the camera into device object list for later usage. deviceList.Register(device); // Displays the DisplayName of the device. Console.WriteLine("Device" + deviceList.GetSize() + "=" + device.GetIStDeviceInfo().DisplayName); // Create a DataStream object for handling image stream data then add into DataStream list for later usage. dataStreamList.Register(device.CreateStDataStream(0)); } // Start the image acquisition of the host side. dataStreamList.StartAcquisition(nCountOfImagesToGrab); // Start the image acquisition of the camera side. deviceList.AcquisitionStart(); // A while loop for acquiring data and checking status. // Here we use DataStream list function to check if any cameras in the list is on grabbing. while (dataStreamList.IsGrabbingAny) { // Retrieve data buffer of image data from any camera with a timeout of 5000ms. using (CStStreamBuffer streamBuffer = dataStreamList.RetrieveBuffer(5000)) { // Check if the acquired data contains image data. if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { Console.Write(streamBuffer.GetIStDataStream().GetIStDevice().GetIStDeviceInfo().DisplayName); Console.Write(" : BlockId=" + streamBuffer.GetIStStreamBufferInfo().FrameID); Console.Write(" " + streamBuffer.GetIStDataStream().CurrentFPS.ToString("F") + "FPS" + Environment.NewLine); } else { // If the acquired data contains no image data. Console.WriteLine("Image data does not exist"); } } } // Stop the image acquisition of the camera side. deviceList.AcquisitionStop(); // Stop the image acquisition of the host side. dataStreamList.StopAcquisition(); } } } catch (Exception e) { // If any exception occurred, display the description of the error here. Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { // Wait until the Enter key is pressed. 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)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of setting ROI to 640 x 480 with offset (100, 200). // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Get Node for Width IInteger intWidth = nodeMap.GetNode <IInteger>("Width"); // Set Width to 640 intWidth.Value = 640; // Get Node for Height IInteger intHeight = nodeMap.GetNode <IInteger>("Height"); // Set Height to 480 intHeight.Value = 480; // Get Node for Offset X IInteger intOffsetX = nodeMap.GetNode <IInteger>("OffsetX"); // Set Offset X to 100 intOffsetX.Value = 100; // Get Node for Offset Y IInteger intOffsetY = nodeMap.GetNode <IInteger>("OffsetY"); // Set Offset Y to 200 intOffsetY.Value = 200; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } 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(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Demostration of Setting Auto Gain Control with dedicated range. // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Switch on Gain Auto(IEnumeration). IEnum enumGainAuto = nodeMap.GetNode <IEnum>("GainAuto"); enumGainAuto.FromString("Continuous"); // Get Node for Auto Luminance Target(IInteger) IInteger intAutoLuminTgt = nodeMap.GetNode <IInteger>("AutoLuminanceTarget"); // Set Auto Luminance Target to 128 intAutoLuminTgt.Value = 128; // For setting analog gain, gain selector need to be set to AnalogAll to access analog gain. IEnum enumGainSelector = nodeMap.GetNode <IEnum>("GainSelector"); enumGainSelector.FromString("AnalogAll"); // Get Node for GainAutoLimitMin(IFloat). IFloat floatGainAutoMin = nodeMap.GetNode <IFloat>("GainAutoLimitMin"); // Set Auto Gain Min to 0 dB (0). floatGainAutoMin.Value = 20; // Get Node for GainAutoLimitMax(IFloat). IFloat floatGainAutoMax = nodeMap.GetNode <IFloat>("GainAutoLimitMax"); // Set Auto Gain Max to 10 dB (100). floatGainAutoMax.Value = 100; // ============================================================================================================== dataStream.StartAcquisition(nCountOfImagesToGrab); device.AcquisitionStart(); while (dataStream.IsGrabbing) { using (CStStreamBuffer streamBuffer = dataStream.RetrieveBuffer(5000)) { if (streamBuffer.GetIStStreamBufferInfo().IsImagePresent) { IStImage stImage = streamBuffer.GetIStImage(); string strText = device.GetIStDeviceInfo().DisplayName + " "; strText += stImage.ImageWidth + " x " + stImage.ImageHeight + " "; strText += string.Format("{0:F2}[fps]", dataStream.CurrentFPS); wnd.SetUserStatusBarText(strText); if (!wnd.IsVisible) { wnd.SetPosition(0, 0, (int)stImage.ImageWidth, (int)stImage.ImageHeight); wnd.Show(eStWindowMode.ModalessOnNewThread); } wnd.RegisterIStImage(stImage); } 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(); } }
static void Main(string[] args) { try { using (CStApiAutoInit api = new CStApiAutoInit()) using (CStSystem system = new CStSystem(eStSystemVendor.Sentech)) using (CStDevice device = system.CreateFirstStDevice()) using (CStImageDisplayWnd wnd = new CStImageDisplayWnd()) using (CStDataStream dataStream = device.CreateStDataStream(0)) { Console.WriteLine("Device=" + device.GetIStDeviceInfo().DisplayName); // ============================================================================================================== // Saving current setting to UserSet1 of camera, with setting it as default when camera power on. // Please notice the UserSet saving can be only avaliable when camera is not in acquiring. // Create NodeMap pointer for accessing parameters INodeMap nodeMap = device.GetRemoteIStPort().GetINodeMap(); // Select which UserSet to save the setting (UserSet1) IEnum enumUserSetSelector = nodeMap.GetNode <IEnum>("UserSetSelector"); enumUserSetSelector.FromString("UserSet1"); // Acquire and execute saving setting to UserSet ICommand cmdSaveToUserSet = nodeMap.GetNode <ICommand>("UserSetSave"); cmdSaveToUserSet.Execute(); Console.WriteLine("Save Current setting to UserSet1 succeed."); // Set UserSetDefault to UsetSet1 for using this setting when camera power on. IEnum enumUserSetDefault = nodeMap.GetNode <IEnum>("UserSetDefault"); enumUserSetDefault.FromString("UserSet1"); Console.WriteLine("Set UserSetDefault to UserSet1 succeed."); // ============================================================================================================== } } catch (Exception e) { Console.Error.WriteLine("An exception occurred. \r\n" + e.Message); } finally { Console.WriteLine("\r\nPress Enter to exit."); Console.ReadLine(); } }