コード例 #1
0
 public void Dispose()
 {
     if (!_disposed && _handle != IntPtr.Zero)
     {
         _disposed = true;
         RGB.StopCapture(_handle);
         RGB.SetFrameCapturedFn(_handle, null, IntPtr.Zero);
         RGB.CloseInput(_handle);
     }
 }
コード例 #2
0
        public void InitializeVisionDB()
        {
            // get the installed rgb executable path
            //if (Properties.Settings.Default.VisionPath == string.Empty)
            //{
            // auto search the rgb exe
            foreach (String matchPath in Utils.Files.DirSearch(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "rgbxcmd.com"))
            {
                rgbExecutablePath = matchPath;
                break;
            }

            if (rgbExecutablePath == String.Empty)
            {
                foreach (String matchPath in Utils.Files.DirSearch(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "rgbxcmd.com"))
                {
                    rgbExecutablePath = matchPath;
                    break;
                }
            }

            //Properties.Settings.Default.VisionPath = rgbExecutablePath;
            //Properties.Settings.Default.Save();
            //}

            // check if the db has data
            // if have return and do nothing, else proceed initialization
            if (GetAllVisionInputs().Count() > 0)
            {
                Trace.WriteLine("Already initialize");
                return;
            }

            // get number of input from API
            uint numberInputs = GetNumberOfInputs();

            if (numberInputs == 0)
            {
                Trace.WriteLine("Failed to get input count: initialize");
                return;
            }

            // contruct default input entry in DB
            RGBERROR error = RGBERROR.NO_ERROR;

            for (uint i = 1; i <= numberInputs; i++)
            {
                // get the input type
                SIGNALTYPE signalType;
                uint       captureWidth;
                uint       captureHeight;
                uint       refreshRate;
                if ((error = RGB.GetInputSignalType(i, out signalType, out captureWidth, out captureHeight, out refreshRate)) != RGBERROR.NO_ERROR)
                {
                    Trace.WriteLine("failed to get signal of input: " + i);
                }

                IntPtr hRgb;
                uint   croppingMode = 0;
                int    top          = 0;
                int    left         = 0;
                uint   width        = 0;
                uint   height       = 0;
                if ((error = RGB.OpenInput(i, out hRgb)) != RGBERROR.NO_ERROR)
                {
                    if ((error = RGB.IsCroppingEnabled(hRgb, out croppingMode)) != RGBERROR.NO_ERROR)
                    {
                        RGB.GetCropping(hRgb, out top, out left, out width, out height);
                    }

                    // clean up
                    RGB.CloseInput(hRgb);
                }

                Input visionInput = new Input()
                {
                    InputNumber        = i,
                    LabelName          = String.Format("{0}:{1}", System.Enum.GetName(typeof(Input.EInputType), signalType), i),
                    InputCaptureWidth  = captureWidth,
                    InputCaptureHeight = captureHeight,
                    InputCropping      = croppingMode > 0 ? true:false,
                    InputCropLeft      = left,
                    InputCropTop       = top,
                    InputCropWidth     = width,
                    InputCropHeight    = height
                };

                // get windows and OSD details
                Window          visionWnd = new Window();
                OnScreenDisplay visionOSD = new OnScreenDisplay();

                AddVisionInput(visionWnd, visionInput, visionOSD);
            }

            ServerDbHelper.GetInstance().AddSystemInputCount((int)numberInputs);
        }