示例#1
0
        public MainForm()
        {
            // dialog controls
            InitializeComponent();

            // init variables
            m_bLive      = false;
            m_bDrawing   = false;
            m_RenderMode = Uc480.IS_RENDER_NORMAL;
            m_DmdWidth   = m_DmdHeight = 1000;
            m_DevId      = UInt32.MaxValue;

            // init our uc480 object
            m_uc480 = new Uc480();

            // enable static messages ( no open camera is needed )
            m_uc480.EnableMessage(Uc480.IS_NEW_DEVICE, this.Handle.ToInt32());
            m_uc480.EnableMessage(Uc480.IS_DEVICE_REMOVAL, this.Handle.ToInt32());

            // Set up the delays for the ToolTip.
            toolTipColor.AutoPopDelay = 5000;
            toolTipColor.InitialDelay = 1000;
            toolTipColor.ReshowDelay  = 500;
            toolTipColor.ShowAlways   = true;
            toolTipColor.SetToolTip(this.DisplayWindow, "");

            // update listbox info
            UpdateInfos();

            // init our image struct and alloc marshall pointers for the uc480 memory
            m_Uc480Images = new UC480IMAGE[IMAGE_COUNT];
            int nLoop = 0;

            for (nLoop = 0; nLoop < IMAGE_COUNT; nLoop++)
            {
                m_Uc480Images[nLoop].pMemory = Marshal.AllocCoTaskMem(4);                       // create marshal object pointers
                m_Uc480Images[nLoop].MemID   = 0;
                m_Uc480Images[nLoop].nSeqNum = 0;
            }
        }
示例#2
0
        // ------------------------  btnInit_Click -------------------------------
        //
        private void btnInit_Click(object sender, System.EventArgs e)
        {
            // if opened before, close now
            if (m_uc480.IsOpen())
            {
                m_uc480.ExitCamera();
            }

            // open a camera
            int nRet = m_uc480.InitCamera(0, DisplayWindow.Handle.ToInt32());

            if (nRet == Uc480.IS_STARTER_FW_UPLOAD_NEEDED)
            {
                /************************************************************************************************/
                /*                                                                                              */
                /*  If the camera returns with "IS_STARTER_FW_UPLOAD_NEEDED", an upload of a new firmware       */
                /*  is necessary. This upload can take several seconds. We recommend to check the required      */
                /*  time with the function is_GetDuration().                                                    */
                /*                                                                                              */
                /*  In this case, the camera can only be opened if the flag "IS_ALLOW_STARTER_FW_UPLOAD"        */
                /*  is "OR"-ed to m_hCam. This flag allows an automatic upload of the firmware.                 */
                /*                                                                                              */
                /************************************************************************************************/

                uint nUploadTime = 25000;
                m_uc480.GetDuration(Uc480.IS_SE_STARTER_FW_UPLOAD, ref nUploadTime);

                String Str;
                Str = "This camera requires a new firmware. The upload will take about " + nUploadTime / 1000 + " seconds. Please wait ...";
                MessageBox.Show(Str, "uc480");

                nRet = m_uc480.InitCamera(0 | Uc480.IS_ALLOW_STARTER_FW_UPLOAD, DisplayWindow.Handle.ToInt32());
            }

            if (nRet != Uc480.IS_SUCCESS)
            {
                MessageBox.Show("Init failed", "uc480");
                return;
            }

            Uc480.SENSORINFO sensorInfo = new Uc480.SENSORINFO();
            m_uc480.GetSensorInfo(ref sensorInfo);

            // Set the image size
            int x = 0;
            int y = 0;

            unsafe
            {
                int    nAOISupported  = -1;
                IntPtr pnAOISupported = (IntPtr)((uint *)&nAOISupported);
                bool   bAOISupported  = true;

                // check if an arbitrary AOI is supported
                //if (m_uc480.ImageFormat(uc480.IMGFRMT_CMD_GET_ARBITRARY_AOI_SUPPORTED, pnAOISupported, 4) == uc480.IS_SUCCESS)
                //{
                //    bAOISupported = (nAOISupported != 0);
                //}

                // If an arbitrary AOI is supported -> take maximum sensor size
                if (bAOISupported)
                {
                    x = sensorInfo.nMaxWidth;
                    y = sensorInfo.nMaxHeight;
                }
                // Take the image size of the current image format
                else
                {
                    x = m_uc480.SetImageSize(Uc480.IS_GET_IMAGE_SIZE_X, 0);
                    y = m_uc480.SetImageSize(Uc480.IS_GET_IMAGE_SIZE_Y, 0);
                }

                m_uc480.SetImageSize(x, y);
            }

            // alloc images
            m_uc480.ClearSequence();
            int nLoop = 0;

            for (nLoop = 0; nLoop < IMAGE_COUNT; nLoop++)
            {
                // alloc memory
                m_uc480.AllocImageMem(x, y, 32, ref m_Uc480Images[nLoop].pMemory, ref m_Uc480Images[nLoop].MemID);
                // add our memory to the sequence
                m_uc480.AddToSequence(m_Uc480Images[nLoop].pMemory, m_Uc480Images[nLoop].MemID);
                // set sequence number
                m_Uc480Images[nLoop].nSeqNum = nLoop + 1;
            }

            m_uc480.SetColorMode(Uc480.IS_SET_CM_RGB32);
            m_uc480.EnableMessage(Uc480.IS_FRAME, this.Handle.ToInt32());

            btnInitCam.Enabled = false;
            btnExit.Enabled    = true;
            btnLive.Enabled    = true;
            btnFreeze.Enabled  = true;

            UpdateInfos();

            // free image
            if (DisplayWindow.Image != null)
            {
                DisplayWindow.Image.Dispose();
                DisplayWindow.Image = null;
            }

            // capture a single image
            m_uc480.FreezeVideo(Uc480.IS_WAIT);
            Refresh();
        }