Exemplo n.º 1
0
        // Gig-E System을 초기화 한다.
        public int Initialize()
        {
            //====================================================================
            // Camera System 초기화
            m_System = new BGAPI.System();
            m_State  = new BGAPI.BGAPI_FeatureState();

            // check system.
            m_iResult = BGAPI.EntryPoint.countSystems(ref m_iSystemNo);
            if (m_iResult != BGAPI.Result.OK)
            {   // BGAPI.EntryPoint.CountSystems failed
                return(GenerateErrorCode(ERR_VISION_SYSTEM_CHECK_FAIL));
            }
            // create system.
            m_iResult = BGAPI.EntryPoint.createSystem(m_iSystemIndex, ref m_System);
            if (m_iResult != BGAPI.Result.OK)
            {   // BGAPI.EntryPoint.createSystems failed
                return(GenerateErrorCode(ERR_VISION_SYSTEM_CREATE_FAIL));
            }
            // open system
            m_iResult = m_System.open();
            if (m_iResult != BGAPI.Result.OK)
            {   // System open failed
                return(GenerateErrorCode(ERR_VISION_SYSTEM_OPEN_FAIL));
            }

            // get camera num
            m_iResult = m_System.countCameras(ref m_iCheckCamNo);
            if (m_iResult != BGAPI.Result.OK)
            {   // System count cameras failed!
                return(GenerateErrorCode(ERR_VISION_SYSTEM_CHECK_CAM_FAIL));
            }

            //====================================================================
            // Library System 초기화

            //MIL.MappAllocDefault(MIL.M_DEFAULT, ref m_MilApp, ref m_MilSystem, ref m_MilDisplay, MIL.M_NULL, MIL.M_NULL);

            MIL.MappAlloc(MIL.M_NULL, MIL.M_DEFAULT, ref m_MilApp);

            // Allocate a MIL system.
            MIL.MsysAlloc(MIL.M_DEFAULT, "M_DEFAULT", MIL.M_DEFAULT, MIL.M_DEFAULT, ref m_MilSystem);

            // System Init 결과 저장
            m_iResult = SUCCESS;

            return(SUCCESS);
        }
        private static int init_camera(int system_count, ref BGAPI.System[] externppSystem, ref int pCurrSystem, ref BGAPI.Camera externppCamera)
        {
            int res = BGAPI.Result.FAIL;
            int i   = 0;
            int cam = 0;

            int[] cameras      = new int[system_count];
            int   camera_count = 0;

            BGAPI.BGAPI_FeatureState state            = new BGAPI_FeatureState();
            BGAPI.BGAPIX_CameraInfo  cameradeviceinfo = new BGAPIX_CameraInfo();
            int inputVal = 0;

            for (i = 0; i < system_count; i++)
            {
                //this is an example how to count available cameras for all available systems
                res = externppSystem[i].countCameras(ref cameras[i]);
                if (res != BGAPI.Result.OK)
                {
                    MessageBox.Show(string.Format("countCameras Systemnumber {0} Errorcode: {1}\n", i, res));
                    return(0);
                }

                for (cam = 0; cam < cameras[i]; cam++)
                {
                    camera_count++;

                    //this is an example how to create a camera
                    res = externppSystem[i].createCamera(cam, ref externppCamera);
                    if (res != BGAPI.Result.OK)
                    {
                        MessageBox.Show(string.Format("\n"));
                        MessageBox.Show(string.Format("createCamera Systemnumber {0} Errorcode: {1}\n", i, res));
                        return(res);
                    }

                    //this is an example how to get the device information for a camera
                    res = externppCamera.getDeviceInformation(ref state, ref cameradeviceinfo);

                    if (res != BGAPI.Result.OK)
                    {
                        MessageBox.Show(string.Format("\n"));
                        MessageBox.Show(string.Format("getDeviceInformation Errorcode: {0}\n", res));
                        return(0);
                    }
                    MessageBox.Show(string.Format("{0} select Camera {1} of system {2} - {3} SN: {4}\n", camera_count, cam, i, cameradeviceinfo.modelName, cameradeviceinfo.serialNumber));
                    externppSystem[i].releaseCamera(ref externppCamera);
                }
            }

            do
            {
                //[TODO] CUSTOM SELECTOR
                inputVal = 1;
                //inputVal = Convert.ToInt32(Console.ReadLine(), 10);
            }while (inputVal < 0 || inputVal > camera_count);

            camera_count = 0;
            for (i = 0; i < system_count; i++)
            {
                for (cam = 0; cam < cameras[i]; cam++)
                {
                    camera_count++;

                    if (camera_count == inputVal)
                    {
                        pCurrSystem = i;

                        //this is an example how to create a camera
                        res = externppSystem[pCurrSystem].createCamera(cam, ref externppCamera);
                        if (res != BGAPI.Result.OK)
                        {
                            MessageBox.Show(string.Format("createCamera Systemnumber {0} Errorcode: {1}\n", i, res));
                            return(res);
                        }

                        //this is an example how to open a camera
                        res = externppCamera.open();
                        if (res != BGAPI.Result.OK)
                        {
                            MessageBox.Show(string.Format("open Systemnumber {0} Errorcode: {1}\n", i, res));
                            return(res);
                        }
                        break;
                    }
                }
            }
            return(res);
        }