示例#1
0
        //
        // Exposure helpers
        //

        /// <summary>
        /// Waits for any exposure in progress to complete, ends it, and reads it out into a 2D ushort array
        /// </summary>
        public static ushort[,] WaitEndAndReadoutExposure(StartExposureParams2 sep)
        {
            // wait for the exposure to be done
            QueryCommandStatusParams  qcsp = new QueryCommandStatusParams(Cmd.CC_START_EXPOSURE);
            QueryCommandStatusResults qcsr = new QueryCommandStatusResults(Error.CE_NO_ERROR);

            while (Error.CE_NO_EXPOSURE_IN_PROGRESS != qcsr.status)
            {
                qcsr = UnivDrvCommand <QueryCommandStatusResults>(Cmd.CC_QUERY_COMMAND_STATUS, qcsp);
            }

            // prepare the CCD for readout
            UnivDrvCommand(Cmd.CC_END_EXPOSURE, new EndExposureParams(CCD.Imaging));
            // then telling it where and how we're going to read
            StartReadoutParams srp = new StartReadoutParams();

            srp.ccd         = CCD.Imaging;
            srp.readoutMode = 0;
            srp.left        = 0;
            srp.top         = 0;
            srp.width       = sep.width;
            srp.height      = sep.height;
            UnivDrvCommand(Cmd.CC_START_READOUT, srp);

            // allocate the image buffer
            ushort[,] data = new ushort[sep.height, sep.width];
            GCHandle datagch = GCHandle.Alloc(data, GCHandleType.Pinned);
            IntPtr   dataptr = datagch.AddrOfPinnedObject();

            // put the data into it
            ReadoutLineParams rlp = new ReadoutLineParams();

            rlp.ccd         = CCD.Imaging;
            rlp.pixelStart  = 0;
            rlp.pixelLength = sep.width;
            rlp.readoutMode = 0;
            GCHandle rlpgch = GCHandle.Alloc(rlp, GCHandleType.Pinned);

            // get the image from the camera, line by line
            for (int i = 0; i < sep.height; i++)
            {
                SBIGUnivDrvCommand(Cmd.CC_READOUT_LINE, rlpgch.AddrOfPinnedObject(), dataptr + (i * sep.width * sizeof(ushort)));
            }

            // cleanup our memory goo
            rlpgch.Free();
            datagch.Free();

            /*Bitmap b3 = new Bitmap(sep.width, sep.height, PixelFormat.Format16bppGrayScale);
             * BitmapData bd = b3.LockBits(new Rectangle(0, 0, sep.width, sep.height), ImageLockMode.WriteOnly, PixelFormat.Format16bppGrayScale);
             * bd.Scan0 = datagch.AddrOfPinnedObject();
             * b3.UnlockBits(bd);
             * Color c2 = b3.GetPixel(0, 0);
             * Bitmap bmp = new Bitmap(sep.width, sep.height, sep.width * sizeof(ushort), PixelFormat.Format16bppGrayScale, datagch.AddrOfPinnedObject());
             * bmp.Save("foo.bmp");
             * bmp.Dispose();*/

            return(data);
        }
示例#2
0
        static void Main(string[] args)
        {
            #region 初始化
            // initialize the driver
            UnivDrvCommand(PAR_COMMAND.CC_OPEN_DRIVER);
            // connect to the camera
            UnivDrvCommand(
                PAR_COMMAND.CC_OPEN_DEVICE,
                new OpenDeviceParams
            {
                deviceType = SBIG_DEVICE_TYPE.DEV_USB
            });
            var cameraType = EstablishLink();

            // start an exposure
            StartExposureParams2 sep2 = new StartExposureParams2
            {
                ccd          = CCD_REQUEST.CCD_IMAGING,
                abgState     = ABG_STATE7.ABG_LOW7,
                openShutter  = SHUTTER_COMMAND.SC_LEAVE_SHUTTER,
                readoutMode  = READOUT_BINNING_MODE.RM_1X1,
                exposureTime = 10,
                left         = 1648, // 3296/2
                top          = 1236, // 2472/2
                width        = 100,
                height       = 100,
            };
            #endregion

            var s_expo = DateTime.Now;
            Exposure(sep2);
            WaitExposure();
            var e_expo = DateTime.Now;
            Console.WriteLine($"Exposure {e_expo - s_expo}");

            var s_sr = DateTime.Now;
            AbortExposure(sep2);
            var srp = new StartReadoutParams
            {
                ccd         = sep2.ccd,
                readoutMode = sep2.readoutMode,
                left        = sep2.left,
                top         = sep2.top,
                width       = sep2.width,
                height      = sep2.height
            };
            UnivDrvCommand(PAR_COMMAND.CC_START_READOUT, srp);
            var e_sr = DateTime.Now;
            Console.WriteLine($"StartReadout { e_sr - s_sr}");

            // read a TDI line
            // input params
            var rlp = new ReadoutLineParams
            {
                ccd         = sep2.ccd,
                readoutMode = sep2.readoutMode,
                pixelStart  = srp.left,
                pixelLength = srp.width
            };
            // output
            var data = new ushort[rlp.pixelLength];
            // do it a lot
            var s_rl = DateTime.Now;
            for (int i = 0; i < srp.height; i++)
            {
                UnivDrvCommand(PAR_COMMAND.CC_READOUT_LINE, rlp, out data);
            }
            var e_rl = DateTime.Now;
            Console.WriteLine($"Read Line {e_rl - s_rl}");

            #region 結束
            // clean up
            UnivDrvCommand(PAR_COMMAND.CC_CLOSE_DEVICE);
            UnivDrvCommand(PAR_COMMAND.CC_CLOSE_DRIVER);
            #endregion
        }