示例#1
0
        static void Main(string[] args)
        {
            tErr err = 0;

            // Initialize the API.
            if ((err = Pv.Initialize()) == 0)
            {
                tLinkCallback lLinkCB = new tLinkCallback(LinkCB);

                // Register callbacks.
                Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkAdd, IntPtr.Zero);
                Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkRemove, IntPtr.Zero);

                // Wait for the user to terminate or to unplug the camera.
                WaitForEver();

                // Unregister the callbacks.
                Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkAdd);
                Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkRemove);

                // Uninitialize the API.
                Pv.UnInitialize();
            }
            else
            {
                Console.Write("Failed to initialize the API : ");
                Console.WriteLine(err);
            }
        }
示例#2
0
        public tErr InitCamera()
        {
            tErr err = 0;

            if (Inited)
            {
                return(0);
            }
            // Initialize the API.
            if ((err = Pv.Initialize()) == 0)
            {
                lLinkCB = new tLinkCallback(LinkCB);

                // Register callbacks.
                Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkAdd, IntPtr.Zero);
                Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkRemove, IntPtr.Zero);
                Inited = true;
            }
            else
            {
                Console.Write("无法加载相机API,错误代码: ");
                Console.WriteLine(err);
                err_string = "无法加载相机API,错误代码: " + err.ToString();
            }
            return(err);
        }
示例#3
0
        public CameraSerial(uint camera)
        {
            uint[] regAddresses = new uint[4];
            uint[] regValues    = new uint[4];


            regAddresses[0] = REG_SIO_MODE;
            regValues[0]    = 0x00000C09; // 9600, N, 8, 1

            regAddresses[1] = REG_SIO_TX_CONTROL;
            regValues[1]    = 3; // Reset & enable transmitter

            regAddresses[2] = REG_SIO_RX_CONTROL;
            regValues[2]    = 3; // Reset & enable receiver

            regAddresses[3] = REG_SIO_RX_STATUS;
            regValues[3]    = 0xFFFFFFFF; // Clear status bits
            uint written = 0;
            tErr error   = (tErr)Pv.RegisterWrite(camera, 4, regAddresses, regValues, ref written);

            if (error != tErr.eErrSuccess)
            {
                throw new PvException(error);
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            tErr err = 0;

            // Initialize the API.
            if ((err = Pv.InitializeNoDiscovery()) == 0)
            {
                System.Net.IPAddress IP = System.Net.IPAddress.Parse(args[0]);
                tCamera Camera          = new tCamera();

                Camera.S_addr = (uint)IP.Address;

                // Open the camera.
                if (CameraOpen(ref Camera))
                {
                    // List some infomation.
                    DisplayInfo(ref Camera);

                    // Unsetup the camera.
                    CameraClose(ref Camera);
                }
                else
                {
                    Console.WriteLine("Failed to open camera.");
                }

                // Uninitialize the API.
                Pv.UnInitialize();
            }
            else
            {
                Console.WriteLine("Failed to initalize.");
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            tErr err = 0;

            // Initialize the API.
            if ((err = Pv.Initialize()) == 0)
            {
                tLinkCallback lLinkCB = new tLinkCallback(LinkCB);

                // Register callbacks.
                Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkAdd, IntPtr.Zero);
                Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkRemove, IntPtr.Zero);

                WaitForCamera();

                if (CameraGrab())
                {
                    if (CameraSetup())
                    {
                        if (CameraStart())
                        {
                            Console.WriteLine("The camera will be streaming for the next 10 seconds.");
                            Thread.Sleep(10000);
                            CameraStop();
                        }
                        else
                        {
                            Console.WriteLine("The camera failed to start streaming.");
                        }

                        CameraClose();
                    }
                    else
                    {
                        Console.WriteLine("The camera could not be setup.");
                    }
                }
                else
                {
                    Console.WriteLine("The was no camera grabbed.");
                }


                // Unregister the callbacks.
                Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkAdd);
                Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkRemove);

                // Uninitialize the API.
                Pv.UnInitialize();
            }
            else
            {
                Console.Write("Failed to initialize the API : ");
                Console.WriteLine(err);
            }
        }
示例#6
0
        public void AdjustPacketSize()
        {
            if (!camera.HasValue)
            {
                throw new PvException(tErr.eErrUnavailable);
            }
            tErr err = Pv.CaptureAdjustPacketSize(camera.Value, MAX_PACKET_SIZE);

            if (err != tErr.eErrSuccess)
            {
                throw new PvException(err);
            }
        }
示例#7
0
 public void Open()
 {
     if (!camera.HasValue)
     {
         uint cameraId;
         Pv.CameraClose(cameraInfo.UniqueId);
         tErr err = Pv.CameraOpen(cameraInfo.UniqueId, tAccessFlags.eAccessMaster, out cameraId);
         if (err != tErr.eErrSuccess)
         {
             throw new PvException(err);
         }
         camera = cameraId;
         communicationManager = new CommunicationsManager(cameraId);
         CommunicationManager.TransmitCommand(new ValuelessCommand((byte)CommandCode.Initialize));
     }
 }
示例#8
0
        static void Main(string[] args)
        {
            tErr err = 0;

            tCameraInfo[] List = new tCameraInfo[10];

            // Initialize the API.
            if ((err = Pv.Initialize()) == 0)
            {
                tCamera Camera = new tCamera();

                // Wait for a camera to be detected.
                WaitForCamera();

                // Get info from the camera.
                CameraGet(ref Camera);

                if (CameraGrab())
                {
                    // Open the camera.
                    if (CameraOpen(ref Camera))
                    {
                        // Change some attributes.
                        CameraAdjust(ref Camera);

                        // Unsetup the camera.
                        CameraClose(ref Camera);
                    }

                    else
                    {
                        Console.WriteLine("Failed to open camera.");
                    }
                }
                else
                {
                    Console.WriteLine("Failed to grab camera.");
                }

                // Uninitialize the API.
                Pv.UnInitialize();
            }
            else
            {
                Console.WriteLine("Failed to initalize.");
            }
        }
示例#9
0
        public void Close()
        {
            if (camera.HasValue)
            {
                tErr err = Pv.CameraClose(camera.Value);
                camera = null;
                if (err != tErr.eErrSuccess)
                {
                    throw new PvException(err);
                }
            }

            if (CommunicationManager != null)
            {
                CommunicationManager.Dispose();
            }
        }
示例#10
0
        public GigEVision()
        {
            tErr error = Pv.Initialize();

            this.connectionChangedCallback = OnCameraConnectionChanged;
            if (error == tErr.eErrSuccess)
            {
                error = Pv.LinkCallbackRegister(this.connectionChangedCallback, tLinkEvent.eLinkAdd, IntPtr.Zero);
                if (error == tErr.eErrSuccess)
                {
                    error = Pv.LinkCallbackRegister(this.connectionChangedCallback, tLinkEvent.eLinkRemove, IntPtr.Zero);
                }
            }
            if (error != tErr.eErrSuccess)
            {
                throw new PvException(error);
            }
        }
示例#11
0
        static void Main(string[] args)
        {
            tErr err = 0;

            // initialize the API.
            if ((err = Pv.Initialize()) == 0)
            {
                in_addr Camera = new in_addr();

                ListingCameras(ref Camera);

                // Uninitialize the API.
                Pv.UnInitialize();
            }
            else
            {
                Console.WriteLine("Failed to initialize.");
            }
        }
示例#12
0
        private void FReadMem(uint camera, uint address, byte[] buffer, uint length)
        {
            uint numRegs = (length + 3) / 4;

            uint[] pAddressArray = new uint[numRegs];
            uint[] pDataArray    = new uint[numRegs];
            uint   read          = 0;


            //
            // We want to read an array of bytes from the camera.  To do this, we
            // read sequential registers which contain the data array.  The register
            // MSB is the first byte of the array.
            //

            // 1.  Generate read addresses
            for (uint i = 0; i < numRegs; i++)
            {
                pAddressArray[i] = address + (i * 4);
            }

            // 2.  Execute read.
            tErr error = (tErr)Pv.RegisterRead(camera, numRegs, pAddressArray, pDataArray, ref read);

            if (error != tErr.eErrSuccess)
            {
                throw new PvException(error);
            }

            uint data = 0;

            // 3.  Convert from MSB-packed registers to byte array
            for (uint i = 0; i < length; i++)
            {
                if (i % 4 == 0)
                {
                    data = pDataArray[i / 4];
                }

                buffer[i] = Convert.ToByte((data >> 24) & 0xFF);
                data    <<= 8;
            }
        }
示例#13
0
        private unsafe bool FWriteMem(uint camera, uint address, byte[] buffer, uint length)
        {
            uint numRegs = (length + 3) / 4;

            uint[] pAddressArray = new uint[numRegs];
            uint[] pDataArray    = new uint[numRegs];
            uint   written       = 0;


            //
            // We want to write an array of bytes from the camera.  To do this, we
            // write sequential registers with the data array.  The register MSB
            // is the first byte of the array.
            //

            // 1.  Generate write addresses, and convert from byte array to MSB-packed
            // registers.
            fixed(byte *bufferPointer = buffer)
            {
                byte *incrementablePointer = bufferPointer;

                for (uint i = 0; i < numRegs; i++)
                {
                    pAddressArray[i] = address + (i * 4);

                    pDataArray[i]  = (uint)*(incrementablePointer++) << 24;
                    pDataArray[i] |= (uint)*(incrementablePointer++) << 16;
                    pDataArray[i] |= (uint)*(incrementablePointer++) << 8;
                    pDataArray[i] |= *(incrementablePointer++);
                }

                // 2.  Execute write.
                tErr error = (tErr)Pv.RegisterWrite(camera, numRegs, pAddressArray, pDataArray, ref written);

                if (error != tErr.eErrSuccess)
                {
                    throw new PvException(error);
                }
            }

            return(true);
        }
示例#14
0
        protected void OnCameraConnectionChanged(IntPtr context, tInterface iface, tLinkEvent evt, UInt32 uniqueId)
        {
            bool   connected = (evt == tLinkEvent.eLinkAdd);
            Camera camera;

            if (connected)
            {
                tCameraInfo cameraInfo = new tCameraInfo();
                tErr        err        = Pv.CameraInfo(uniqueId, ref cameraInfo);
                if (err != tErr.eErrSuccess)
                {
                    throw new PvException(err);
                }
                camera = new Camera(cameraInfo);
                cameras.Add(camera);
            }
            else
            {
                camera = cameras.Find(c => c.UniqueId == uniqueId);
            }

            if (camera != null && (CameraConnected != null && connected) || (CameraDisconnected != null && !connected))
            {
                CameraConnectionHandler eventHandler = connected ? CameraConnected : CameraDisconnected;
                Delegate[] delegates = eventHandler.GetInvocationList();
                foreach (CameraConnectionHandler handler in delegates)
                {
                    DispatcherObject dispatcherObject = handler.Target as DispatcherObject;
                    if (dispatcherObject != null && !dispatcherObject.CheckAccess())
                    {
                        dispatcherObject.Dispatcher.Invoke(DispatcherPriority.DataBind, handler, camera);
                    }
                    else
                    {
                        handler(camera);
                    }
                }
            }
        }
示例#15
0
        public bool ReadBytesFromSerialIo(uint camera, byte[] buffer, uint bufferLength,
                                          ref uint receiveLength)
        {
            uint[] lengthData = new uint[1];
            uint   read = 0, written = 0;

            // How many characters to read?
            tErr error = (tErr)Pv.RegisterRead(camera, 1, RegSioRxLengthAddress, lengthData, ref read);

            if (error != tErr.eErrSuccess)
            {
                throw new PvException(error);
            }

            // It must fit in the user's buffer.
            uint dataLength = lengthData[0];

            if (dataLength > bufferLength)
            {
                dataLength = bufferLength;
            }

            if (dataLength > 0)
            {
                // Read the data.
                FReadMem(camera, REG_SIO_RX_BUFFER, buffer, dataLength);

                // Decrement the camera's read index.
                error = (tErr)Pv.RegisterWrite(camera, 1, RegSioRxLengthAddress, lengthData, ref written);
                if (error != tErr.eErrSuccess)
                {
                    throw new PvException(error);
                }
            }

            receiveLength = dataLength;

            return(true);
        }
示例#16
0
        static void Main(string[] args)
        {
            tErr err = 0;

            // Initialize the API.
            if ((err = Pv.Initialize()) == 0)
            {
                tCamera Camera     = new tCamera();
                UInt32  FrameCount = 600;

                // Wait for a camera to be detected.
                WaitForCamera();

                if (CameraGet(ref Camera))
                {
                    // Open the first camera.
                    if (CameraOpen(ref Camera))
                    {
                        // Set the camera up for streaming.
                        if (CameraSetup(ref Camera))
                        {
                            UInt32 Count = 0;


                            while (Count <= FrameCount)
                            {
                                // Start streaming.
                                if (CameraSnap(ref Camera))
                                {
                                    Console.Write("[{0:000}]", Count);
                                    UInt32 status = (UInt32)(Camera.Frame.Status);
                                    Console.WriteLine(" Status = {0:00} ", status);
                                    Count++;
                                }
                            }
                            CameraStop(ref Camera);
                        }
                        else
                        {
                            Console.WriteLine("Failed to setup the camera.");
                        }

                        CameraClose(ref Camera);
                    }
                    else
                    {
                        Console.WriteLine("Camera {0} failed to be open.", Camera.UID);
                    }
                }
                else
                {
                    Console.WriteLine("Failed to get a camera.");
                }

                Pv.UnInitialize();
            }
            else
            {
                Console.Write("Failed to initialize the API : ");
                Console.WriteLine(err);
            }

            Thread.Sleep(800);
        }
示例#17
0
        static void Main(string[] args)
        {
            tErr err = 0;

            // Initialize the API.
            if ((err = Pv.Initialize()) == 0)
            {
                tCamera       Camera  = new tCamera();
                tLinkCallback lLinkCB = new tLinkCallback(LinkCB);


                // Add callbacks for camera events.
                if (Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkAdd, IntPtr.Zero) != 0)
                {
                    Console.WriteLine("Failed to register the callback.");
                }
                if (Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkRemove, IntPtr.Zero) != 0)
                {
                    Console.WriteLine("Failed to register the callback.");
                }

                // Wait for a camera to be plugged in.
                WaitForCamera();

                // Grab a camera from the list.
                if (CameraGrab(ref Camera))
                {
                    // Setup the camera.
                    if (CameraSetup(ref Camera))
                    {
                        DoSnap(ref Camera);
                        DoSnap(ref Camera);
                        DoStream(ref Camera);
                        DoStream(ref Camera);
                        DoSnap(ref Camera);
                        DoStream(ref Camera);
                        DoStream(ref Camera);

                        // Unsetup the camera.
                        CameraUnsetup(ref Camera);
                    }

                    else
                    {
                        Console.WriteLine("Camera {0} failed to be setup.", Camera.UID);
                    }
                }
                else
                {
                    Console.WriteLine("Failed to find a camera.");
                }

                // Remove callbacks.
                if (Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkAdd) != 0)
                {
                    Console.WriteLine("Failed to unregister the callback.");
                }
                if (Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkRemove) != 0)
                {
                    Console.WriteLine("Failed to unregister the callback.");
                }

                // Uninitialize the API.
                Pv.UnInitialize();
            }
            else
            {
                Console.Write("Failed to initialize the API.");
                Console.WriteLine(err);
            }
        }
示例#18
0
 internal PvException(tErr error)
 {
     switch (error)
     {
         case tErr.eErrAccessDenied:
             this.Message = "Camera cannot be opened in the specified mode.";
             break;
         case tErr.eErrBadHandle:
             this.Message = "Camera handle is invalid.";
             break;
         case tErr.eErrBadParameter:
             this.Message = "Bad parameter to API call.";
             break;
         case tErr.eErrBadSequence:
             this.Message = "Sequence of API calls is incorrect.";
             break;
         case tErr.eErrBandwidth:
             this.Message = "1394 bandwidth not available.";
             break;
         case tErr.eErrBufferTooSmall:
             this.Message = "Frame buffer is too small.";
             break;
         case tErr.eErrCameraFault:
             this.Message = "Unexpected camera fault.";
             break;
         case tErr.eErrCancelled:
             this.Message = "Frame cancelled by user.";
             break;
         case tErr.eErrDataLost:
             this.Message = "The data for the frame was lost.";
             break;
         case tErr.eErrDataMissing:
             this.Message = "Some data in the frame is missing.";
             break;
         case tErr.eErrForbidden:
             this.Message = "Attribute write forbidden at this time.";
             break;
         case tErr.eErrInternalFault:
             this.Message = "Unexpected fault in PvApi or driver.";
             break;
         case tErr.eErrInvalidSetup:
             this.Message = "Setup is invalid (an attribute is invalid).";
             break;
         case tErr.eErrNotFound:
             this.Message = "Camera or attribute not found.";
             break;
         case tErr.eErrOutOfRange:
             this.Message = "Attribute value is out of the expected range.";
             break;
         case tErr.eErrQueueFull:
             this.Message = "Too many frames on queue.";
             break;
         case tErr.eErrResources:
             this.Message = "System/network resources or memory not available.";
             break;
         case tErr.eErrTimeout:
             this.Message = "Timeout during wait.";
             break;
         case tErr.eErrSuccess:
             this.Message = "No error. This should not appear.";
             break;
         case tErr.eErrUnavailable:
             this.Message = "Attribute is not available at this time.";
             break;
         case tErr.eErrUnplugged:
             this.Message = "Camera was unplugged.";
             break;
         case tErr.eErrWrongType:
             this.Message = "Attribute is not this type (wrong access function).";
             break;
         default:
             this.Message = "An unknown exception has occured.";
             break;
     }
 }
示例#19
0
        static void Main(string[] args)
        {
            tErr err = 0;


            // Initialize the API.
            if ((err = Pv.Initialize()) == 0)
            {
                tCamera       Camera  = new tCamera();
                tLinkCallback lLinkCB = new tLinkCallback(LinkCB);


                // Add callbacks for camera events.
                if (Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkAdd, IntPtr.Zero) != 0)
                {
                    Console.WriteLine("Failed to register callback.");
                }
                if (Pv.LinkCallbackRegister(lLinkCB, tLinkEvent.eLinkRemove, IntPtr.Zero) != 0)
                {
                    Console.WriteLine("Failed to register callback.");
                }


                WaitForCamera();

                if (CameraGrab(ref Camera))
                {
                    if (CameraSetup(ref Camera))
                    {
                        // Stream as long as CTRL C isn't pressed.
                        while (close == false)
                        {
                            if (CameraStart(ref Camera))
                            {
                                Console.WriteLine("Camera is now streaming.");

                                // Stream the Camera until the use stops it.
                                Abort();
                                CameraStop(ref Camera);
                            }

                            else
                            {
                                Console.WriteLine("Failed to start the streaming process.");
                            }

                            CameraClose(ref Camera);
                        }
                    }

                    else
                    {
                        Console.WriteLine("Camera {0} failed to be setup.", Camera.UID);
                    }
                }
                else
                {
                    Console.WriteLine("Failed to find a camera.");
                }

                //remove callbacks
                if (Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkAdd) != 0)
                {
                    Console.WriteLine("Failed to unregister the callback.");
                }
                if (Pv.LinkCallbackUnregister(lLinkCB, tLinkEvent.eLinkRemove) != 0)
                {
                    Console.WriteLine("Failed to unregister the callback.");
                }


                Pv.UnInitialize();
            }
            else
            {
                Console.Write("Failed to initialize the API : ");
                Console.WriteLine(err);
            }

            Thread.Sleep(800);
        }
示例#20
0
        internal PvException(tErr error)
        {
            switch (error)
            {
            case tErr.eErrAccessDenied:
                this.Message = "Camera cannot be opened in the specified mode.";
                break;

            case tErr.eErrBadHandle:
                this.Message = "Camera handle is invalid.";
                break;

            case tErr.eErrBadParameter:
                this.Message = "Bad parameter to API call.";
                break;

            case tErr.eErrBadSequence:
                this.Message = "Sequence of API calls is incorrect.";
                break;

            case tErr.eErrBandwidth:
                this.Message = "1394 bandwidth not available.";
                break;

            case tErr.eErrBufferTooSmall:
                this.Message = "Frame buffer is too small.";
                break;

            case tErr.eErrCameraFault:
                this.Message = "Unexpected camera fault.";
                break;

            case tErr.eErrCancelled:
                this.Message = "Frame cancelled by user.";
                break;

            case tErr.eErrDataLost:
                this.Message = "The data for the frame was lost.";
                break;

            case tErr.eErrDataMissing:
                this.Message = "Some data in the frame is missing.";
                break;

            case tErr.eErrForbidden:
                this.Message = "Attribute write forbidden at this time.";
                break;

            case tErr.eErrInternalFault:
                this.Message = "Unexpected fault in PvApi or driver.";
                break;

            case tErr.eErrInvalidSetup:
                this.Message = "Setup is invalid (an attribute is invalid).";
                break;

            case tErr.eErrNotFound:
                this.Message = "Camera or attribute not found.";
                break;

            case tErr.eErrOutOfRange:
                this.Message = "Attribute value is out of the expected range.";
                break;

            case tErr.eErrQueueFull:
                this.Message = "Too many frames on queue.";
                break;

            case tErr.eErrResources:
                this.Message = "System/network resources or memory not available.";
                break;

            case tErr.eErrTimeout:
                this.Message = "Timeout during wait.";
                break;

            case tErr.eErrSuccess:
                this.Message = "No error. This should not appear.";
                break;

            case tErr.eErrUnavailable:
                this.Message = "Attribute is not available at this time.";
                break;

            case tErr.eErrUnplugged:
                this.Message = "Camera was unplugged.";
                break;

            case tErr.eErrWrongType:
                this.Message = "Attribute is not this type (wrong access function).";
                break;

            default:
                this.Message = "An unknown exception has occured.";
                break;
            }
        }
示例#21
0
        static void Main(string[] args)
        {
            tErr err = 0;

            // Initialize the API.
            if ((err = Pv.Initialize()) == 0)
            {
                // Wait for a camera to be detected.
                WaitForCamera();

                // Obtains a camera from the list.
                if (CameraGet())
                {
                    // Open the first camera detected.
                    if (CameraOpen())
                    {
                        // Set the camera up for triggering.
                        if (CameraSetup())
                        {
                            // Allows the user to terminate program.
                            SpawnAbortThread();

                            UInt32 Count = 0;
                            String filename;

                            Console.WriteLine("The camera is ready now, press 'X' to terminate program.");
                            while (close == false)
                            {
                                // Snaps a frame.
                                if (CameraSnap())
                                {
                                    filename  = "Snap";
                                    filename += Count++;
                                    filename += ".bmp";

                                    if (close == false)
                                    {
                                        // Saves the snapped frame.
                                        if (FrameSave(filename) == false)
                                        {
                                            Console.WriteLine("Failed to save the image.");
                                        }

                                        else
                                        {
                                            Console.WriteLine("Frame saved under filename: {0}", filename);
                                        }
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("Failed to snap an image.");
                                }
                            }

                            // Stop the streaming.
                            CameraStop();
                        }
                        else
                        {
                            Console.WriteLine("Failed to setup the camera.");
                        }

                        // Close the camera.
                        CameraClose();
                    }
                    else
                    {
                        Console.WriteLine("Camera {0} failed to be open.", GCamera.UID);
                    }
                }
                else
                {
                    Console.WriteLine("Failed to get a camera.");
                }

                Pv.UnInitialize();
            }
            else
            {
                Console.Write("Failed to initialize the API : ");
                Console.WriteLine(err);
            }

            Thread.Sleep(800);
        }
示例#22
0
        static void Main(string[] args)
        {
            tErr err = 0;

            // Initialize the API.
            if ((err = Pv.Initialize()) == 0)
            {
                tCamera Camera = new tCamera();

                // Wait for a camera to be detected.
                WaitForCamera();

                if (CameraGet(ref Camera))
                {
                    // Open the first camera detected.
                    if (CameraOpen(ref Camera))
                    {
                        // Set the camera up for triggering.
                        if (CameraSetup(ref Camera))
                        {
                            UInt32 Count = 0;
                            String filename;

                            Console.WriteLine("The camera is ready now. Press Q to quit or S to take a picture.");

                            while (WaitForUserToQuitOrSnap())
                            {
                                if (CameraSnap(ref Camera))
                                {
                                    filename  = "Snap";
                                    filename += Count++;
                                    filename += ".bmp";

                                    if (FrameSave(ref Camera, filename) == false)
                                    {
                                        Console.WriteLine("Failed to save the image.");
                                    }
                                    else
                                    {
                                        Console.WriteLine("Frame saved.");
                                    }
                                    Console.WriteLine("The camera is waiting for a trigger. Press Q to quit or S to take a picture.");
                                }
                                else
                                {
                                    Console.WriteLine("Failed to snap an image.");
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("Failed to setup the camera.");
                        }

                        CameraClose(ref Camera);
                    }
                    else
                    {
                        Console.WriteLine("Camera {0} failed to be open.", Camera.UID);
                    }
                }
                else
                {
                    Console.WriteLine("Failed to get a camera.");
                }

                Pv.UnInitialize();
            }
            else
            {
                Console.Write("Failed to initialize the API : ");
                Console.WriteLine(err);
            }

            Thread.Sleep(800);
        }