コード例 #1
0
        private void ExecuteWorkWithSystem(ManagedSystem system,
                                           Action <ManagedSystem> action,
                                           Action <ManagedSystem> onSuccess = null,
                                           Action <ManagedSystem> onFailure = null)
        {
            using var dbContext = DbContextFactory.CreateDbContext();

            try
            {
                dbContext.Entry(system).Reload();

                action(system);

                system.LastAccessed = DateTime.UtcNow;
                onSuccess?.Invoke(system);
            }
            catch (Exception e)
            {
                dbContext.Entry(system).Reload();

                system.AddProblem($"{system.ProblemDescription}\n\n {DateTime.UtcNow}\n{e.Message}".Trim());

                Logger.LogError(e, "While executing work with {system}: {exception}", system.Name, e.Message);

                onFailure?.Invoke(system);

                throw;
            }
            finally
            {
                dbContext.Update(system);
                dbContext.SaveChanges();
            }
        }
コード例 #2
0
ファイル: GPCam.cs プロジェクト: Isaac320/QVision2
        private void Init()
        {
            ManagedSystem system = new ManagedSystem();

            cam = system.GetCameras()[0];
            cam.Init();
        }
コード例 #3
0
        public void PreparePackagesActions(ManagedSystem system, List <object> actions)
        {
            Logger.LogInformation("Preparing packages actions for {system}.", system.Name);

            ExecuteWorkWithSystem(system, managedSystem =>
            {
                GetDistributionManager(managedSystem).PreparePackagesActions(actions);
            }, managedSystem =>
            {
            });
        }
コード例 #4
0
        public SystemUpdateInfo GetInformationAboutSystemUpdate(ManagedSystem system)
        {
            Logger.LogInformation("Getting update info for {system}.", system.Name);

            SystemUpdateInfo updateInfo = null;

            ExecuteWorkWithSystem(system, managedSystem =>
            {
                updateInfo = GetDistributionManager(managedSystem).GetInformationAboutSystemUpdate();
            });

            return(updateInfo);
        }
コード例 #5
0
        public override bool Connect()
        {
            bool result = false;

            try
            {
                system = new ManagedSystem();
                IList <IManagedCamera> camList = system.GetCameras();

                if (camList.Count != 1)
                {
                    int count = camList.Count;
                    foreach (IManagedCamera mc in camList)
                    {
                        mc.Dispose();
                    }

                    // Clear camera list before releasing system
                    camList.Clear();

                    // Release system
                    system.Dispose();
                    throw new Exception("Only one camera should be connected, but found " + count);
                }

                camera = camList[0];
                // Initialize camera
                camera.Init();

                SerialNumber    = Convert.ToUInt32(camera.DeviceSerialNumber);
                FirmwareVersion = camera.DeviceFirmwareVersion;

                // Retrieve GenICam nodemap
                nodeMap = camera.GetNodeMap();

                //initialise settings
                DefaultSettings();

                ImageWidth  = camera.Width;
                ImageHeight = camera.Height;

                result = true;
            }
            catch (Exception /*ex*/)
            {
                //App.LogEntry.AddEntry("Failed to Connect to Point Grey Camera : " + ex.Message);
                result = false;
            }

            return(result);
        }
コード例 #6
0
        public void RefreshSystemInformation(ManagedSystem system)
        {
            Logger.LogInformation("Refreshing system information for {system}.", system.Name);

            Dictionary <string, string> systemInformation = null;

            ExecuteWorkWithSystem(system, managedSystem =>
            {
                systemInformation = GetDistributionManager(managedSystem).GetSystemInformation();
            }, managedSystem =>
            {
                managedSystem.SystemInformation = JsonSerializer.Serialize(systemInformation);
            });
        }
コード例 #7
0
        public static SshClient CreateSshClient(ManagedSystem system)
        {
            ConnectionInfo connectionInfo;

            if (!string.IsNullOrEmpty(system.OneTimePassword) && !string.IsNullOrEmpty(system.OneTimeLogin))
            {
                KeyboardInteractiveAuthenticationMethod keyboardAuth = new KeyboardInteractiveAuthenticationMethod(system.OneTimeLogin);
                PasswordAuthenticationMethod            passwordAuth = new PasswordAuthenticationMethod(system.OneTimeLogin, system.OneTimePassword);

                keyboardAuth.AuthenticationPrompt += (sender, args) =>
                {
                    foreach (Renci.SshNet.Common.AuthenticationPrompt prompt in args.Prompts)
                    {
                        if (prompt.Request.IndexOf("Password:"******"Could not create authentication for system {system.Name}.");
            }


            var client = new SshClient(connectionInfo);

            client.HostKeyReceived += (sender, hostKeyArgs) =>
            {
                var receivedFingerprint = new Fingerprint(hostKeyArgs.FingerPrint);
                hostKeyArgs.CanTrust = system.Fingerprint.Matches(receivedFingerprint);

                if (string.IsNullOrEmpty(system.SystemFingerprint))
                {
                    system.SystemFingerprint = receivedFingerprint.Text;
                    throw new AuthenticationException("System fingerprint was filled automatically.");
                }
            };
            client.Connect();

            return(client);
        }
コード例 #8
0
        public List <PackageInformation> GetListOfPackages(ManagedSystem system)
        {
            Logger.LogInformation("Getting packages list for {system}.", system.Name);

            List <PackageInformation> updates = null;

            ExecuteWorkWithSystem(system, managedSystem =>
            {
                updates = GetDistributionManager(managedSystem).GetListOfPackages();
            }, managedSystem =>
            {
            });

            return(updates);
        }
コード例 #9
0
        public override bool Init(int index = 0)
        {
            bool ret = false;

            try
            {
                // Retrieve singleton reference to system object
                ManagedSystem system = new ManagedSystem();
                // Retrieve list of cameras from the system
                IList <IManagedCamera> camList = system.GetCameras();

                LogHelper.AppLoger.DebugFormat("Number of cameras detected: {0}", camList.Count);
                if (camList.Count == 0)
                {
                    LogHelper.AppLoger.Error("没有发现相机!");
                    return(ret);
                }

                m_Camera = camList[index];
                // Retrieve TL device nodemap and print device information
                INodeMap nodeMapTLDevice = m_Camera.GetTLDeviceNodeMap();

                // Initialize camera
                m_Camera.Init();
                // Retrieve GenICam nodemap
                m_NodeMap = m_Camera.GetNodeMap();

                //if (!m_camera.DeviceConnectionStatus.IsRegister)
                //{
                //    Dialogs.Show("连接相机失败!");
                //    return ret;
                //}
                //CameraInfo camInfo = m_camera.GetCameraInfo();
                IString iDeviceSerialNumber = nodeMapTLDevice.GetNode <IString>("DeviceSerialNumber");
                LogHelper.AppLoger.DebugFormat("camera serial number:{0}", iDeviceSerialNumber);
                //Set embedded timestamp to on
                //EmbeddedImageInfo embeddedInfo = m_camera.GetEmbeddedImageInfo();
                //embeddedInfo.timestamp.onOff = true;
                //m_camera.SetEmbeddedImageInfo(embeddedInfo);
                SetAcquisitionMode("Continuous");
                ret = true;
            }
            catch (Exception ex)
            {
                LogHelper.AppLoger.Error(ex);
            }
            return(ret);
        }
コード例 #10
0
        public List <object> GetPackagesActions(ManagedSystem system)
        {
            Logger.LogInformation("Getting packages actions for {system}.", system.Name);

            List <object> updates = null;

            ExecuteWorkWithSystem(system, managedSystem =>
            {
                updates = GetDistributionManager(managedSystem).GetPackagesActions();
            }, managedSystem =>
            {
                managedSystem.UpdatesFetchedAt = DateTime.UtcNow;
            });

            return(updates);
        }
コード例 #11
0
        public static ulong GetCameraSerialNumber()
        {
            using (var system = new ManagedSystem())
            {
                var cameraList = system.GetCameras();
                if (cameraList.Count != 1)
                {
                    throw new InvalidOperationException($"Please disconnect all other imaging devices from the computer before configuring the {nameof(FP3002)}.");
                }

                var camera       = cameraList.GetByIndex(0);
                var nodeMap      = camera.GetTLDeviceNodeMap();
                var serialNumber = nodeMap.GetNode <SpinnakerNET.GenApi.IString>(nameof(camera.DeviceSerialNumber));
                return(ulong.Parse(serialNumber.Value));
            }
        }
コード例 #12
0
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            var values = new List <string>();

            using (var system = new ManagedSystem())
            {
                var cameraList = system.GetCameras();
                for (int i = 0; i < cameraList.Count; i++)
                {
                    var camera           = cameraList[i];
                    var nodeMap          = camera.GetTLDeviceNodeMap();
                    var serialNumberNode = nodeMap.GetNode <StringReg>("Std::DeviceSerialNumber");
                    if (serialNumberNode != null)
                    {
                        values.Add(serialNumberNode.Value);
                    }
                }
            }

            return(new StandardValuesCollection(values));
        }
コード例 #13
0
ファイル: MainWindow.xaml.cs プロジェクト: xiaopi3/camera3D
        public MainWindow()
        {
            InitializeComponent();

            ManagedSystem ms = new ManagedSystem();

            IList <IManagedCamera> camList = ms.GetCameras();

            IManagedCamera cam = camList[0];

            GUIFactory AcquisitionGUI = new GUIFactory();

            cam.Init();
            //AcquisitionGUI.ConnectGUILibrary(cam);

            ImageDrawingWindow AcquisitionDrawing = AcquisitionGUI.GetImageDrawingWindow();

            //AcquisitionDrawing.Connect(cam);

            //AcquisitionDrawing.Start();
            //AcquisitionDrawing.Stop();

            AcquisitionDrawing.ShowModal();
        }
コード例 #14
0
 private ISystemManager GetDistributionManager(ManagedSystem managedSystem)
 {
     return(new FreeBsdManager(DbContextFactory, managedSystem));
 }
コード例 #15
0
        public IObservable <SpinnakerDataFrame> Generate <TSource>(IObservable <TSource> start)
        {
            return(Observable.Create <SpinnakerDataFrame>((observer, cancellationToken) =>
            {
                return Task.Factory.StartNew(async() =>
                {
                    IManagedCamera camera;
                    lock (systemLock)
                    {
                        using (var system = new ManagedSystem())
                        {
                            var index = Index;
                            var cameraList = system.GetCameras();
                            if (index < 0 || index >= cameraList.Count)
                            {
                                throw new InvalidOperationException("No Spinnaker camera with the specified index was found.");
                            }

                            camera = cameraList[index];
                            cameraList.Clear();
                        }
                    }

                    try
                    {
                        camera.Init();
                        Configure(camera);
                        camera.BeginAcquisition();
                        await start;

                        var imageFormat = default(PixelFormatEnums);
                        var converter = default(Func <IManagedImage, IplImage>);
                        using (var cancellation = cancellationToken.Register(camera.EndAcquisition))
                        {
                            while (!cancellationToken.IsCancellationRequested)
                            {
                                using (var image = camera.GetNextImage())
                                {
                                    if (image.IsIncomplete)
                                    {
                                        // drop incomplete frames
                                        continue;
                                    }

                                    if (converter == null || image.PixelFormat != imageFormat)
                                    {
                                        converter = GetConverter(image.PixelFormat, ColorProcessing);
                                        imageFormat = image.PixelFormat;
                                    }

                                    var output = converter(image);
                                    observer.OnNext(new SpinnakerDataFrame(output, image.ChunkData));
                                }
                            }
                        }
                    }
                    catch (SEHException ex) { observer.OnError(ex); throw; }
                    catch (InvalidOperationException ex) { observer.OnError(ex); throw; }
                    catch (SpinnakerException ex) { observer.OnError(ex); throw; }
                    finally
                    {
                        camera.DeInit();
                        camera.Dispose();
                    }
                },
                                             cancellationToken,
                                             TaskCreationOptions.LongRunning,
                                             TaskScheduler.Default);
            }));
        }
コード例 #16
0
        public override bool Connect()
        {
            bool result = false;

            //try
            //{
            //    CameraSelectionDialog m_selDlg = new CameraSelectionDialog();
            //    if (m_selDlg.ShowModal())
            //    {
            //        ManagedPGRGuid[] guids = m_selDlg.GetSelectedCameraGuids();
            //        if (guids.Length == 0)
            //        {
            //            //MessageBox.Show("Please select a camera", "No camera selected");
            //            return false;
            //        }

            //        camera = new ManagedCamera();
            //        m_ctldlg = new CameraControlDialog();
            //        camera.Connect(guids[0]);

            //        //initialise settings
            //        InitializeSettings();
            //        InitializeSettingsWB();

            //        CameraInfo ci = camera.GetCameraInfo();
            //        SerialNumber = ci.serialNumber;

            //        result = true;
            //    }
            //}
            //catch (Exception /*ex*/)
            //{
            //    //App.LogEntry.AddEntry("Failed to Connect to Point Grey Camera : " + ex.Message);
            //    result = false;
            //}
            system = new ManagedSystem();
            IList <IManagedCamera> camList = system.GetCameras();

            if (camList.Count != 1)
            {
                int count = camList.Count;
                foreach (IManagedCamera mc in camList)
                {
                    mc.Dispose();
                }

                // Clear camera list before releasing system
                camList.Clear();

                // Release system
                system.Dispose();
                throw new Exception("Only one camera should be connected, but found " + count);
            }

            camera = camList[0];
            // Initialize camera
            camera.Init();

            // Retrieve GenICam nodemap
            nodeMap = camera.GetNodeMap();

            SerialNumber = Convert.ToUInt32(camera.DeviceSerialNumber);

            //initialise settings
            try
            {
                InitializeSettings();
                InitializeSettingsWB();
                result = true;
            }
            catch (SpinnakerException ex)
            {
                result = false;
                Debug.WriteLine("PtGrey connect failed: " + ex.Message);
            }

            return(result);
        }
コード例 #17
0
ファイル: CameraControl.cs プロジェクト: wpiyong/fancy
        public bool Connect()
        {
            bool result = false;

            try
            {
                system = new ManagedSystem();
                IList <IManagedCamera> camList = system.GetCameras();

                if (camList.Count != 2)
                {
                    int count = camList.Count;
                    foreach (IManagedCamera mc in camList)
                    {
                        mc.Dispose();
                    }

                    // Clear camera list before releasing system
                    camList.Clear();

                    // Release system
                    system.Dispose();
                    throw new Exception("2 cameras needed but found " + camList.Count);
                }
                for (int i = 0; i < camList.Count; i++)
                {
                    var cam = camList[i];
                    // Initialize camera
                    cam.Init();
                    // Retrieve GenICam nodemap
                    var  nodemap      = cam.GetNodeMap();
                    uint SerialNumber = Convert.ToUInt32(cam.DeviceSerialNumber);
                    if (SerialNumber == App.Settings.SideCameraSerialNum)
                    {
                        cameraSide = new PtGreyCamera(cam, CameraType.Side);
                    }
                    else
                    {
                        cameraTop = new PtGreyCamera(cam, CameraType.Top);
                    }
                }

                if (cameraSide != null && cameraTop != null)
                {
                    cameras.Add(cameraTop);
                    cameras.Add(cameraSide);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception ex)
            {
                result = false;
                if (cameraTop != null)
                {
                    cameraTop.Disconnect();
                }
                if (cameraSide != null)
                {
                    cameraSide.Disconnect();
                }
            }
            return(result);
        }
コード例 #18
0
        // Example entry points; this function sets up the system and retrieves
        // interfaces to retrieves interfaces for the example.
        public static int Start()
        {
            int result = 0;

            Program program = new Program();

            //
            // Retrieve singleton reference to system object
            //
            // *** NOTES ***
            // Everything originates with the system object. It is important to
            // notice that it has a singleton implementation, so it is impossible
            // to have multiple system objects at the same time.
            //
            // *** LATER ***
            // The system object should be cleared prior to program completion.
            // If not released explicitly, it will be released automatically
            // when all system objects go out of scope.
            //
            ManagedSystem system = new ManagedSystem();

            // Print out current library version
            LibraryVersion spinVersion = system.GetLibraryVersion();

            Console.WriteLine("Spinnaker library version: {0}.{1}.{2}.{3}\n\n",
                              spinVersion.major,
                              spinVersion.minor,
                              spinVersion.type,
                              spinVersion.build);

            //
            // Retrieve list of interfaces from the system
            //
            // *** NOTES ***
            // Interface lists are retrieved from the system object.
            //
            // *** LATER ***
            // Interface lists are constructed using list objects of
            // IManagedInterface objects. Lists are native to C# and must be
            // cleared after use.
            //
            List <IManagedInterface> interfaceList = system.GetInterfaces();

            Console.WriteLine("Number of interfaces detected: {0}\n", interfaceList.Count);

            //
            // Retrieve list of cameras from the system
            //
            // *** NOTES ***
            // Camera lists are retrieved from the system object.
            //
            // *** LATER ***
            // Camera lists are constructed using list objects of IManagedCamera
            // objects. Lists are native to C# and must be cleared after use.
            //
            List <IManagedCamera> camList = system.GetCameras();

            Console.WriteLine("Number of cameras detected: {0}\n", camList.Count);

            // Finish if there are no cameras
            if (camList.Count == 0 || interfaceList.Count == 0)
            {
                // Clear camera list before releasing system
                camList.Clear();

                // Clear interface list before releasing system
                interfaceList.Clear();

                // Release system
                system.Dispose();

                Console.WriteLine("Not enough cameras!");
                Console.WriteLine("Done! Press Enter to exit...");
                Console.ReadLine();

                return(-1);
            }

            Console.WriteLine("\n*** QUERYING INTERFACES ***\n");

            //
            // Run example on each interface
            //
            // *** NOTES ***
            // Managed interfaces will need to be disposed of after use in order
            // to fully clean up. Using-statements help ensure that this is taken
            // care of; otherwise, interfaces can be disposed of manually by calling
            // Dispose().
            //
            foreach (IManagedInterface managedInterface in interfaceList)
            {
                using (managedInterface) {
                    try {
                        // Run example
                        result = result | program.QueryInterface(managedInterface);
                    } catch (SpinnakerException ex) {
                        Console.WriteLine("Error: {0}", ex.Message);
                        result = -1;
                    }
                }
            }

            //
            // Clear camera list before releasing system
            //
            // *** NOTES ***
            // If a camera list is not cleaned up
            // manually, the system will do so when System.Dispose() is
            // called.
            //
            camList.Clear();

            //
            // Clear interface list before releasing system
            //
            // *** NOTES ***
            // If an interface list is not cleaned up
            // manually, the system will do so when System.Dispose() is
            // called.
            //
            interfaceList.Clear();

            //
            // Release system
            //
            // *** NOTES ***
            // The system should be released, but if it is not, it will do so
            // itself. It is often at the release of the system (whether manual
            // or automatic) that unbroken references and still registered
            // events will throw an exception.
            //
            system.Dispose();

            Console.WriteLine("\nDone!");
            //Console.ReadLine();

            return(result);
        }
コード例 #19
0
ファイル: PtGreyCamera.cs プロジェクト: wpiyong/n3
        public bool Open(ConcurrentQueue <PtGreyCameraImage> imageQ, out string message)
        {
            bool result = false;

            message = "";

            system = new ManagedSystem();

            // Retrieve list of cameras from the system
            camList = system.GetCameras();

            // Finish if there are no cameras
            if (camList.Count != 1)
            {
                foreach (IManagedCamera mc in camList)
                {
                    mc.Dispose();
                }

                // Clear camera list before releasing system
                camList.Clear();

                // Release system
                system.Dispose();
                message = "Camera count is " + camList.Count;
            }
            else
            {
                try
                {
                    managedCamera = camList[0];

                    if (managedCamera.TLDevice.DeviceDisplayName != null && managedCamera.TLDevice.DeviceDisplayName.IsReadable)
                    {
                        message = managedCamera.TLDevice.DeviceDisplayName.ToString();
                    }

                    // Initialize camera
                    managedCamera.Init();

                    // Retrieve GenICam nodemap
                    nodeMap = managedCamera.GetNodeMap();

                    imageQueue = imageQ;
                    result     = true;
                }
                catch (SpinnakerException ex)
                {
                    Debug.WriteLine("Error: {0}", ex.Message);
                    message = ex.Message;
                    result  = false;;
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    result  = false;
                }
            }

            return(result);
        }
コード例 #20
0
ファイル: Form1.cs プロジェクト: blobology/FetchRig6
        public Form1()
        {
            InitializeComponent();

            system = new ManagedSystem();

            // Print current Spinnaker library version info:
            LibraryVersion spinVersion = system.GetLibraryVersion();

            Console.WriteLine(
                "Spinnaker library version: {0}.{1}.{2}.{3}\n\n",
                spinVersion.major,
                spinVersion.minor,
                spinVersion.type,
                spinVersion.build);

            // Find all Flir cameras on the system:
            managedCameras = system.GetCameras();

            // Assert that exactly two cameras are found:
            int nCamsFound = managedCameras.Count;

            if (nCamsFound != nCameras)
            {
                Console.WriteLine("Need exactly two cameras, but {0} cameras were found. Disposing system.", nCamsFound.ToString());
                managedCameras.Clear();
                system.Dispose();
            }

            // Create or select folder to write video data:
            sessionPaths = Util.SetDataWritePaths(animalName: Util.AnimalName.Charlie);

            // Initialize OryxSetupInfo Object to pass to camera constructors upon initialization:
            oryxSetupInfos = new Util.OryxSetupInfo[nCameras];
            for (int i = 0; i < nCameras; i++)
            {
                oryxSetupInfos[i] = new Util.OryxSetupInfo();
            }

            bool areAllCamSettingsIdentical = true;

            if (areAllCamSettingsIdentical)
            {
                Console.WriteLine("\n\n");
                Console.WriteLine("Cameras have identical settings, shown here:");
                oryxSetupInfos[0].PrintSettingsToLoad();
                Console.WriteLine("\n\n");
            }

            StreamArchitecture architecture = StreamArchitecture.ThreeLevelBasic;

            threadManager = new ThreadManager(architecture: architecture, sessionPaths: sessionPaths,
                                              managedCameras: managedCameras, oryxSetups: oryxSetupInfos);

            xBoxController = new XBoxController(mainForm: this,
                                                messageQueues: threadManager.managerBundle.messageQueues, streamGraph: threadManager.streamGraph);

            displayTimer          = new System.Windows.Forms.Timer();
            displayTimer.Interval = 2;
            displayTimer.Tick    += DisplayTimerEventProcessor;
            displayTimer.Enabled  = true;

            displayQueue = threadManager.managerBundle.mergeStreamsManager.output.displayQueue;
            threadManager.StartThreads();
        }
        // Example entry point; please see Enumeration_CSharp example for more
        // in-depth comments on preparing and cleaning up the system.
        public static int Start()
        {
            int result = 0;

            Program program = new Program();

            // Since this application saves images in the current folder
            // we must ensure that we have permission to write to this folder.
            // If we do not have permission, fail right away.
            FileStream fileStream;

            try {
                fileStream = new FileStream(@"test.txt", FileMode.Create);
                fileStream.Close();
                File.Delete("test.txt");
            } catch {
                Console.WriteLine("Failed to create file in current folder. Please check permissions.");
                Console.WriteLine("Press enter to exit...");
                Console.ReadLine();
                return(-1);
            }

            // Retrieve singleton reference to system object
            ManagedSystem system = new ManagedSystem();

            // Print out current library version
            LibraryVersion spinVersion = system.GetLibraryVersion();

            Console.WriteLine("Spinnaker library version: {0}.{1}.{2}.{3}\n\n",
                              spinVersion.major,
                              spinVersion.minor,
                              spinVersion.type,
                              spinVersion.build);

            // Retrieve list of cameras from the system
            IList <IManagedCamera> camList = system.GetCameras();

            Console.WriteLine("Number of cameras detected: {0}\n\n", camList.Count);

            // Finish if there are no cameras
            if (camList.Count == 0)
            {
                // Clear camera list before releasing system
                camList.Clear();

                // Release system
                system.Dispose();

                Console.WriteLine("Not enough cameras!");
                Console.WriteLine("Done! Press Enter to exit...");
                Console.ReadLine();

                return(-1);
            }

            //
            // Run example on each camera
            //
            // *** NOTES ***
            // Cameras can either be retrieved as their own IManagedCamera
            // objects or from camera lists using the [] operator and an index.
            //
            // Using-statements help ensure that cameras are disposed of when
            // they are no longer needed; otherwise, cameras can be disposed of
            // manually by calling Dispose(). In C#, if cameras are not disposed
            // of before the system is released, the system will do so
            // automatically.
            //
            int index = 0;

            foreach (IManagedCamera managedCamera in camList)
            {
                using (managedCamera) {
                    Console.WriteLine("Running example for camera {0}...", index);

                    try {
                        // Run example
                        result = result | program.RunSingleCamera(managedCamera);
                    } catch (SpinnakerException ex) {
                        Console.WriteLine("Error: {0}", ex.Message);
                        result = -1;
                    }

                    Console.WriteLine("Camera {0} example complete...\n", index++);
                }
            }

            // Clear camera list before releasing system
            camList.Clear();

            // Release system
            system.Dispose();

            Console.WriteLine("\nDone! Press Enter to exit...");
            Console.ReadLine();

            return(result);
        }
コード例 #22
0
        // Example entry point; please see Enumeration_CSharp example for more
        // in-depth comments on preparing and cleaning up the system.
        public static int Start()
        {
            int result = 0;

            Program program = new Program();

            // Ensure write permissions to current folder
            try {
                FileStream fileStream = new FileStream(@"test.txt", FileMode.Create);
                fileStream.Close();
                File.Delete("test.txt");
            } catch {
                Console.WriteLine("Failed to create file in current folder.  Please check permissions.\n");
                Console.WriteLine("\nDone! Press enter to exit...");
                Console.ReadLine();
                return(-1);
            }

            // Retrieve singleton reference to system object
            ManagedSystem system = new ManagedSystem();

            // Print out current library version
            LibraryVersion spinVersion = system.GetLibraryVersion();

            Console.WriteLine("Spinnaker library version: {0}.{1}.{2}.{3}\n\n",
                              spinVersion.major,
                              spinVersion.minor,
                              spinVersion.type,
                              spinVersion.build);

            // Retrieve list of cameras from the system
            List <IManagedCamera> camList = system.GetCameras();

            Console.WriteLine("Number of cameras detected: {0}\n", camList.Count);

            // Finish if there are no cameras
            if (camList.Count == 0)
            {
                // Clear camera list before releasing system
                camList.Clear();

                // Release system
                system.Dispose();

                Console.WriteLine("Not enough cameras!");
                Console.WriteLine("Done! Press Enter to exit...");
                Console.ReadLine();

                return(-1);
            }

            // Run example on each camera
            int index = 0;

            foreach (IManagedCamera managedCamera in camList)
            {
                using (managedCamera) {
                    Console.WriteLine("Running example for camera {0}...", index);

                    try {
                        // Run example
                        result = result | program.RunSingleCamera(managedCamera);
                    } catch (SpinnakerException ex) {
                        Console.WriteLine("Error: {0}", ex.Message);
                        result = -1;
                    }

                    Console.WriteLine("Camera {0} example complete...\n", index++);
                }
            }

            // Clear camera list before releasing system
            camList.Clear();

            // Release system
            system.Dispose();

            Console.WriteLine("\nDone! Press Enter to exit...");
            Console.ReadLine();

            return(result);
        }
コード例 #23
0
        public bool Open(ConcurrentQueue <PtGreyCameraImage> imageQ, out string message, out long width, out long height)
        {
            bool result = false;

            message = "";
            width   = height = 0;

            system = new ManagedSystem();

            // Retrieve list of cameras from the system
            camList = system.GetCameras();

            // Finish if there are no cameras
            if (camList.Count != 1)
            {
                foreach (IManagedCamera mc in camList)
                {
                    mc.Dispose();
                }

                // Clear camera list before releasing system
                camList.Clear();

                // Release system
                system.Dispose();
                message = "Camera count is " + camList.Count;
            }
            else
            {
                try
                {
                    #region FlyCaptureAPI
                    FlyCapture2Managed.ManagedBusManager busMgr = new FlyCapture2Managed.ManagedBusManager();
                    var guid = busMgr.GetCameraFromIndex(0);
                    flycapManagedCamera = new FlyCapture2Managed.ManagedCamera();
                    flycapManagedCamera.Connect(guid);
                    #endregion

                    managedCamera = camList[0];

                    if (managedCamera.TLDevice.DeviceDisplayName != null && managedCamera.TLDevice.DeviceDisplayName.IsReadable)
                    {
                        message = managedCamera.TLDevice.DeviceDisplayName.ToString();
                    }

                    // Initialize camera
                    managedCamera.Init();

                    width  = managedCamera.Width.Value;
                    height = managedCamera.Height.Value;

                    // Retrieve GenICam nodemap
                    nodeMap = managedCamera.GetNodeMap();

                    imageQueue = imageQ;
                    result     = true;
                }
                catch (SpinnakerException ex)
                {
                    Debug.WriteLine("Error: {0}", ex.Message);
                    message = ex.Message;
                    result  = false;;
                }
                catch (Exception ex)
                {
                    message = ex.Message;
                    result  = false;
                }
            }

            return(result);
        }
コード例 #24
0
 public static List <ScheduledAction> GetQueuedAndStartedScheduledActionsForSystem(this DbSet <ScheduledAction> updates, ManagedSystem managedSystem)
 {
     return(updates
            .Where(x => managedSystem.Id == x.ManagedSystemId && x.ScheduledAt <= DateTime.Now && (x.ScheduledActionStatus == ScheduledActionStatus.Queued || x.ScheduledActionStatus == ScheduledActionStatus.Started))
            .Include(x => x.ManagedSystem)
            .ToList());
 }
コード例 #25
0
 public static List <ScheduledAction> GetScheduledActionsForSystem(this DbSet <ScheduledAction> updates, ManagedSystem managedSystem)
 {
     return(updates
            .Where(x => managedSystem.Id == x.ManagedSystemId)
            .Include(x => x.ManagedSystem)
            .ToList());
 }
コード例 #26
0
        // Entry point of the Acquisition Example
        public void AcquisitionExample()
        {
            int result = 0;

            // Since this application saves images in the current folder
            // we must ensure that we have permission to write to this folder.
            // If we do not have permission, fail right away.
            FileStream fileStream;

            try
            {
                fileStream = new FileStream(@"test.txt", FileMode.Create);
                fileStream.Close();
                File.Delete("test.txt");
            }
            catch
            {
                writeLog(String.Format(
                             "Failed to create file in current folder. Please check permissions."));
            }

            // Retrieve singleton reference to system object
            ManagedSystem system = new ManagedSystem();

            // Retrieve list of cameras from the system
            IList <IManagedCamera> camList = system.GetCameras();

            writeLog(String.Format("Number of cameras detected: {0}\n\n", camList.Count));

            // Finish if there are no cameras
            if (camList.Count == 0)
            {
                // Clear camera list before releasing system
                camList.Clear();

                // Release system
                system.Dispose();

                writeLog(String.Format("Not enough cameras!"));
                writeLog(String.Format("Done!"));
            }

            //
            // Run example on each camera
            //
            // *** NOTES ***
            // Cameras can either be retrieved as their own IManagedCamera
            // objects or from camera lists using the [] operator and an index.
            //
            // Using-statements help ensure that cameras are disposed of when
            // they are no longer needed; otherwise, cameras can be disposed of
            // manually by calling Dispose(). In C#, if cameras are not disposed
            // of before the system is released, the system will do so
            // automatically.
            //
            int index = 0;

            foreach (IManagedCamera managedCamera in camList)
            {
                using (managedCamera)
                {
                    writeLog(String.Format("Running example for camera {0}...\n", index));

                    try
                    {
                        // Run example
                        result = result | RunSingleCamera(managedCamera);
                    }
                    catch (SpinnakerException ex)
                    {
                        writeLog(String.Format("Error: {0}\n", ex.Message));
                        result = -1;
                    }
                    writeLog(String.Format("Camera {0} example complete...\n", index++));
                }
            }

            // Clear camera list before releasing system
            camList.Clear();

            // Release system
            system.Dispose();

            writeLog(String.Format("Done!\n"));
        }
コード例 #27
0
 public static bool SystemHasNotFinishedUpdate(this DbSet <ScheduledAction> updates, ManagedSystem managedSystem)
 {
     return(updates.Any(x => x.ManagedSystemId == managedSystem.Id &&
                        (x.ScheduledActionStatus == ScheduledActionStatus.Queued ||
                         x.ScheduledActionStatus == ScheduledActionStatus.Started ||
                         x.ScheduledActionStatus == ScheduledActionStatus.Unknown)));
 }
コード例 #28
0
 public FreeBsdManager(IDbContextFactory <ApplicationDbContext> dbContextFactory, ManagedSystem system)
 {
     DbContextFactory = dbContextFactory;
     System           = system;
 }
コード例 #29
0
        public IManagedImage RetrieveMonoImage()
        {
            IManagedImage imgResult = null;

            // Retrieve singleton reference to system object
            ManagedSystem system = new ManagedSystem();

            // Retrieve list of cameras from the system
            IList <IManagedCamera> camList = system.GetCameras();

            if (camList.Count < 1)
            {
                writeLog(String.Format("No camera detected. Aborted.\n\n"));
                return(null);
            }
            else
            {
                writeLog(String.Format("Number of cameras detected: {0}\n\n", camList.Count));
            }
            // Use the first camera
            using (camList[0])
            {
                writeLog(String.Format("Running example for the 1st camera...\n"));

                IManagedCamera cam = camList[0];

                try
                {
                    // Run for a camera

                    // Retrieve TL device nodemap and print device information
                    INodeMap nodeMapTLDevice = cam.GetTLDeviceNodeMap();

                    PrintDeviceInfo(nodeMapTLDevice);

                    // Initialize camera
                    cam.Init();

                    // Retrieve GenICam nodemap
                    INodeMap nodeMap = cam.GetNodeMap();

                    /*****  Acquire single BW image from the camera  *****/

                    writeLog(String.Format("\n*** BW IMAGE ACQUISITION ***\n\n"));
                    SetNodeMapItem(nodeMap, "AcquisitionMode", "Continuous");
                    cam.BeginAcquisition();
                    using (IManagedImage rawImage = cam.GetNextImage())
                    {
                        if (rawImage.IsIncomplete)
                        {
                            writeLog(String.Format(
                                         "Image incomplete with image status {0}...\n", rawImage.ImageStatus));
                            imgResult = null;
                        }
                        else
                        {
                            // TODO: Need to return the acquired rawImage here.
                            //IManagedImage monoImage = rawImage.Convert(
                            //    PixelFormatEnums.Mono16, ColorProcessingAlgorithm.EDGE_SENSING);
                            IManagedImage monoImage = rawImage.Convert(PixelFormatEnums.Mono8);
                            imgResult = monoImage;
                        }
                    }
                    cam.EndAcquisition();

                    /*****  Acquiring Complete  *****/

                    // Deinitialize camera
                    cam.DeInit();
                }
                catch (SpinnakerException ex)
                {
                    writeLog(String.Format("Error: {0}\n", ex.Message));
                    imgResult = null;
                }
                writeLog(String.Format("Camera example complete...\n"));
            }

            // Clear camera list before releasing system
            camList.Clear();

            // Release system
            system.Dispose();

            writeLog(String.Format("Done!\n"));

            return(imgResult);
        }
コード例 #30
0
        public void AddSystem(ManagedSystem managedSystem)
        {
            GetDistributionManager(managedSystem).SetupSystem();

            DbContextFactory.Upsert(managedSystem);
        }