public unsafe static void CaptureAndSaveTestImage(string fileName) { //Create a BitmapData and Lock all pixels to be written var imageSize = GetImageSize(); var monochromeBitDepths = GetSupportedBitDepths().Where(x => x < 24).ToArray(); if (!monochromeBitDepths.Any()) { throw new NotSupportedException("The camera does not support acquiring monochrome images"); } short maxMonoBitDepth = monochromeBitDepths.Max(); unsafe { Debug.Assert(SpotCamReturnCode.Success == SpotCamService.SpotSetValue(CoreParameter.BitDepth, new IntPtr(&maxMonoBitDepth))); } var bmp = new Bitmap(imageSize.Width, imageSize.Height, maxMonoBitDepth <= 8 ? PixelFormat.Format8bppIndexed : PixelFormat.Format16bppGrayScale); var bmpData = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.WriteOnly, bmp.PixelFormat); var getImageReturnCode = SpotCamService.SpotGetImage(0, 0, 0, bmpData.Scan0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); bmp.UnlockBits(bmpData); if (SpotCamReturnCode.Success != getImageReturnCode) { throw new InvalidOperationException(String.Format("Error capturing image - {0}.", getImageReturnCode)); } // WinForms draws the image buffer to screen in descending Y order (bottom to top) // To correct for this just flip the Y axis bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); SaveToTiffFile(bmp, fileName); }
private static void Main(string[] args) { try { CameraFactory.Initialize(); foreach (var device in CameraFactory.DeviceList) { Console.WriteLine("Found device: {0}", device.Description); } SpotVersionDetails versionInfo; SpotCamService.SpotGetVersionInfo2(out versionInfo); Console.WriteLine("Connected to driver:\n{0} {1}.{2}.{3} - {4}", versionInfo.ProductName, versionInfo.VerMajor, versionInfo.VerMinor, versionInfo.VerUpdate, versionInfo.BuildDetails); Console.WriteLine(versionInfo.Copyright); } catch (Exception ex) { Console.WriteLine("Fatal Error: {0}", ex); } var camera = CameraFactory.DeviceList.Last().Create(); Console.WriteLine("Camera Details:"); Console.WriteLine("Model:{0}, SN:{1}, Firmware Rev: {2}, Hardware Rev: {3}", camera.Model, camera.SerialNumber, camera.FirmwareVersion, camera.HardwareVersion); Console.WriteLine("Capturing test TIFF image"); CaptureAndSaveTestImage("SampleImage.tif"); Console.WriteLine("SpotShutDown returned: {0}", SpotCamService.SpotShutDown()); }
/// <summary> /// Initializes the factory. Must be called before any operations are performed. /// </summary> public static void Initialize() { var returnCode = SpotCamService.SpotStartUp(IntPtr.Zero); if (!(SpotCamReturnCode.Success == returnCode || SpotCamReturnCode.ErrorStartupAlreadyDone == returnCode)) { throw SpotCamService.MakeException(returnCode); } }
private unsafe static Size GetImageSize() { SPOT_SIZE imageSize; unsafe { var returnCode = SpotCamService.SpotGetValue(CoreParameter.AcquiredImageSize, new IntPtr(&imageSize)); Debug.Assert(SpotCamReturnCode.Success == returnCode, "Unable to query device for the final image resolution", "SpotCamReturnCode: {0}", returnCode); } return(new Size((int)imageSize.Width, (int)imageSize.Height)); }
private static short[] GetSupportedBitDepths() { var buffer = Marshal.AllocHGlobal(SpotCamService.SpotGetValueSize(CoreParameter.BitDepths)); var returnCode = SpotCamService.SpotGetValue(CoreParameter.BitDepths, buffer); Debug.Assert(SpotCamReturnCode.Success == returnCode, "Unable to query device for available bit depths", "SpotCamReturnCode: {0}", returnCode); var availableBitDepths = SpotCamService.MarshalLengthPrefixArray <short>(buffer); Marshal.FreeHGlobal(buffer); return(availableBitDepths); }
internal Camera(Device device) { if (null == device) { throw new ArgumentNullException(); } this.device = device; unsafe { ulong devUid = device.DeviceUID; var serviceException = SpotCamService.MakeException(SpotCamService.SpotSetValue(CoreParameter.DeviceUid, new IntPtr(&devUid))); if (serviceException != null) { throw new InvalidOperationException("Unable to set the device identifier", serviceException); } SpotCamService.MakeException(SpotCamService.SpotInit()).ThrowIfNotNull(); isConnected = true; SpotVersionDetails cameraDetails; SpotCamService.SpotGetVersionInfo2(out cameraDetails); this.Model = cameraDetails.CameraModelNum; this.SerialNumber = cameraDetails.CameraSerialNum; Version tempVersion = new Version(); if (Version.TryParse(cameraDetails.CameraHadrwareRevNum, out tempVersion)) { this.HardwareVersion = tempVersion; } else { this.HardwareVersion = new Version(); } if (Version.TryParse(cameraDetails.CameraFirmwareRevNum, out tempVersion)) { this.FirmwareVersion = tempVersion; } else { this.FirmwareVersion = new Version(); } CameraAttributes attibutes; SpotCamService.SpotGetCameraAttributes(out attibutes); this.Attributes = attibutes; ImageSensorType sensorType; SpotCamService.SpotGetValue(CoreParameter.ImageSensorType, new IntPtr(&sensorType)); ImageSensorType = sensorType; } }
public static void Reconnect(Camera camera) { if (null == camera) { throw new ArgumentNullException(); } lock (deviceLock) { ulong devUid = camera.DeviceUid; unsafe { var serviceException = SpotCamService.MakeException(SpotCamService.SpotSetValue(CoreParameter.DeviceUid, new IntPtr(&devUid))); if (serviceException != null) { throw new InvalidOperationException("Unable to set the device identifier", serviceException); } } SpotCamService.MakeException(SpotCamService.SpotInit()).ThrowIfNotNull(); currentCamera = camera; } camera.HandleConnection(); }
/// <summary> /// Shuts down the factory. Initialize must be called again to restart the factory. /// </summary> public static void Shutdown() { System.Diagnostics.Debug.Assert(SpotCamReturnCode.Success == SpotCamService.SpotShutDown()); currentCamera = null; }