示例#1
0
        public override bool SanityCheck()
        {
            bool result = false;

            try
            {
                systemList = SystemList.Instance;
                //systemList = SystemList.CreateInstanceFromPath("");

                // Collect usable systems.
                // FIXME: This lists all systems and initializes them, including non Baumer GenAPI implementations.
                // This prevents other modules based on GenAPI from initializing properly.
                // We need a way to uninitialize the other systems without uninitializing the Baumer systems.
                systemList.Refresh();
                foreach (KeyValuePair <string, BGAPI2.System> systemPair in systemList)
                {
                    BGAPI2.System system = systemPair.Value;
                    if (!system.Vendor.Contains("Baumer"))
                    {
                        continue;
                    }

                    if (!system.IsOpen)
                    {
                        system.Open();
                    }

                    if (string.IsNullOrEmpty(system.Id))
                    {
                        continue;
                    }

                    systems.Add(systemPair.Key, system);
                }

                result = systems.Count > 0;
            }
            catch (Exception e)
            {
                log.DebugFormat("Baumer Camera subsystem not available.");
                log.ErrorFormat(e.Message);
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Open a specific device and allocate buffers.
        /// </summary>
        public bool Open(string systemKey, string interfaceKey, string deviceKey)
        {
            Close();

            try
            {
                // Look for the device.
                SystemList systemList = SystemList.Instance;
                systemList.Refresh();
                foreach (KeyValuePair <string, BGAPI2.System> systemPair in systemList)
                {
                    if (systemPair.Key != systemKey)
                    {
                        continue;
                    }

                    system = systemPair.Value;
                    if (!system.IsOpen)
                    {
                        system.Open();
                    }

                    break;
                }

                if (system == null || !system.IsOpen)
                {
                    return(false);
                }

                system.Interfaces.Refresh(100);
                foreach (KeyValuePair <string, BGAPI2.Interface> interfacePair in system.Interfaces)
                {
                    if (interfacePair.Key != interfaceKey)
                    {
                        continue;
                    }

                    interf = interfacePair.Value;
                    if (!interf.IsOpen)
                    {
                        interf.Open();
                    }
                    break;
                }

                if (interf == null || !interf.IsOpen)
                {
                    return(false);
                }


                interf.Devices.Refresh(100);
                foreach (KeyValuePair <string, BGAPI2.Device> devicePair in interf.Devices)
                {
                    if (devicePair.Key != deviceKey)
                    {
                        continue;
                    }

                    device = devicePair.Value;
                    if (!device.IsOpen)
                    {
                        device.Open();
                    }
                    break;
                }

                if (device == null || !device.IsOpen)
                {
                    return(false);
                }

                DataStreamList dataStreamList = device.DataStreams;
                dataStreamList.Refresh();
                foreach (KeyValuePair <string, BGAPI2.DataStream> dataStreamPair in dataStreamList)
                {
                    if (string.IsNullOrEmpty(dataStreamPair.Key))
                    {
                        continue;
                    }

                    dataStream = dataStreamPair.Value;
                    dataStream.Open();
                    break;
                }

                if (dataStream == null)
                {
                    CloseDevice();
                    return(false);
                }

                // Use buffers internal to the API.
                bufferList = dataStream.BufferList;
                int countBuffers = 4;
                for (int i = 0; i < countBuffers; i++)
                {
                    BGAPI2.Buffer buffer = new BGAPI2.Buffer();
                    bufferList.Add(buffer);
                    //ulong memSize = buffer.MemSize;
                    //log.DebugFormat("Buffer mem size: {0}", memSize);
                }

                // Make buffers available to the Baumer producer.
                if (bufferList != null && bufferList.Count == countBuffers)
                {
                    foreach (KeyValuePair <string, BGAPI2.Buffer> bufferPair in bufferList)
                    {
                        bufferPair.Value.QueueBuffer();
                    }
                }

                opened = true;
            }
            catch (Exception e)
            {
                log.ErrorFormat("Failed to open device. {0}", e);
                DiscardBuffers();
                CloseDataStream();
                CloseDevice();
            }

            return(opened);
        }
示例#3
0
        public override List <CameraSummary> DiscoverCameras(IEnumerable <CameraBlurb> blurbs)
        {
            List <CameraSummary> summaries = new List <CameraSummary>();
            List <CameraSummary> found     = new List <CameraSummary>();

            //---------------------------------------------
            // Lifecycles of objects in the Baumer API:
            // - systemList: entire application. Will initialize all systems, not clear how to uninitialize non Baumer systems.
            // - system: entire application. Should be kept open.
            // - interface: entire application. Allow listing of devices even if they are opened by another application.
            // - device: camera session.
            //---------------------------------------------

            try
            {
                foreach (KeyValuePair <string, BGAPI2.System> systemPair in systems)
                {
                    BGAPI2.System system = systemPair.Value;
                    if (!system.Vendor.Contains("Baumer"))
                    {
                        continue;
                    }

                    if (!system.IsOpen)
                    {
                        system.Open();
                    }

                    if (string.IsNullOrEmpty(system.Id))
                    {
                        continue;
                    }

                    system.Interfaces.Refresh(200);
                    foreach (KeyValuePair <string, BGAPI2.Interface> interfacePair in system.Interfaces)
                    {
                        BGAPI2.Interface iface = interfacePair.Value;
                        //log.DebugFormat("Opening interface {0}", iface.DisplayName);
                        if (!iface.IsOpen)
                        {
                            iface.Open();
                        }

                        if (string.IsNullOrEmpty(iface.Id))
                        {
                            continue;
                        }

                        iface.Devices.Refresh(200);
                        //log.DebugFormat("Devices found in interface {0}: {1}.", iface.DisplayName, iface.Devices.Count);
                        foreach (KeyValuePair <string, BGAPI2.Device> devicePair in iface.Devices)
                        {
                            BGAPI2.Device device = devicePair.Value;
                            //log.DebugFormat("Found device: {0} ({1})", device.DisplayName, device.SerialNumber);

                            string identifier = device.SerialNumber;
                            bool   cached     = cache.ContainsKey(identifier);
                            if (cached)
                            {
                                // We've already seen this camera in the current Kinovea session.
                                //deviceIds[identifier] = device.GetDeviceID();
                                //log.DebugFormat("Known device from current session.");
                                summaries.Add(cache[identifier]);
                                found.Add(cache[identifier]);
                                continue;
                            }

                            string             alias            = device.DisplayName;
                            Bitmap             icon             = null;
                            SpecificInfo       specific         = new SpecificInfo();
                            Rectangle          displayRectangle = Rectangle.Empty;
                            CaptureAspectRatio aspectRatio      = CaptureAspectRatio.Auto;
                            ImageRotation      rotation         = ImageRotation.Rotate0;
                            bool mirror = false;

                            // Check if we already know this camera from a previous Kinovea session.
                            if (blurbs != null)
                            {
                                foreach (CameraBlurb blurb in blurbs)
                                {
                                    if (blurb.CameraType != this.CameraType || blurb.Identifier != identifier)
                                    {
                                        continue;
                                    }

                                    // We know this camera from a previous Kinovea session, restore the user custom values.
                                    log.DebugFormat("Known device from previous session.");
                                    alias            = blurb.Alias;
                                    icon             = blurb.Icon ?? defaultIcon;
                                    displayRectangle = blurb.DisplayRectangle;
                                    if (!string.IsNullOrEmpty(blurb.AspectRatio))
                                    {
                                        aspectRatio = (CaptureAspectRatio)Enum.Parse(typeof(CaptureAspectRatio), blurb.AspectRatio);
                                    }
                                    if (!string.IsNullOrEmpty(blurb.Rotation))
                                    {
                                        rotation = (ImageRotation)Enum.Parse(typeof(ImageRotation), blurb.Rotation);
                                    }
                                    mirror   = blurb.Mirror;
                                    specific = SpecificInfoDeserialize(blurb.Specific);
                                    break;
                                }
                            }

                            // Keep temporary info in order to find it back later.
                            specific.SystemKey    = systemPair.Key;
                            specific.InterfaceKey = interfacePair.Key;
                            specific.DeviceKey    = devicePair.Key;
                            specific.Device       = null;

                            icon = icon ?? defaultIcon;
                            CameraSummary summary = new CameraSummary(alias, device.DisplayName, identifier, icon, displayRectangle, aspectRatio, rotation, mirror, specific, this);

                            summaries.Add(summary);
                            found.Add(summary);
                            cache.Add(identifier, summary);
                        }

                        //iface.Close();
                    }

                    //system.Close();
                }
            }
            catch (Exception e)
            {
                log.ErrorFormat("Error while scanning for devices. {0}", e.Message);
            }

            List <CameraSummary> lost = new List <CameraSummary>();

            foreach (CameraSummary summary in cache.Values)
            {
                if (!found.Contains(summary))
                {
                    lost.Add(summary);
                }
            }

            foreach (CameraSummary summary in lost)
            {
                log.DebugFormat("Lost device: {0}", summary.Name);
                cache.Remove(summary.Identifier);
            }

            return(summaries);
        }
示例#4
0
        protected override Result Open()
        {
            #region system
            BGAPI2.SystemList.Instance.Refresh();

            foreach (KeyValuePair <string, BGAPI2.System> kv in BGAPI2.SystemList.Instance)
            {
                if (kv.Value.TLType == "U3V")
                {
                    _usbSystem = kv.Value;
                    break;
                }
            }
            if (_usbSystem == null)
            {
                return(new Result("Fail", "Failed to get usb system"));
            }
            #endregion
            #region interface
            _usbSystem.Open();
            _usbSystem.Interfaces.Refresh(100);

            foreach (KeyValuePair <string, BGAPI2.Interface> kv in _usbSystem.Interfaces)
            {
                if (kv.Value.TLType == "U3V")
                {
                    _usbInterface = kv.Value;
                    break;
                }
            }
            if (_usbInterface == null)
            {
                _usbSystem.Close();
                return(new Result("Fail", "Failed to get usb interface"));
            }
            #endregion
            #region device
            _usbInterface.Open();
            _usbInterface.Devices.Refresh(100);

            foreach (KeyValuePair <string, BGAPI2.Device> kv in _usbInterface.Devices)
            {
                if (kv.Value.TLType == "U3V")
                {
                    _usbDevice = kv.Value;
                    break;
                }
            }
            if (_usbDevice == null)
            {
                _usbInterface.Close();
                _usbSystem.Close();
                return(new Result("Fail", "Failed to find usb device"));
            }
            else if (_usbInterface.Devices.Count > 1)
            {
                _log.Warn("More than 1 usb devices found");
            }
            #endregion
            #region datastream
            _usbDevice.Open();
            _usbDevice.RemoteNodeList["TriggerMode"].Value = "Off";
            _usbDevice.DataStreams.Refresh();

            _usbDataStream = _usbDevice.DataStreams["Stream0"];
            _usbDataStream.Open();
            _bufList = _usbDataStream.BufferList;
            for (int i = 0; i < BUF_NUM; i++)
            {
                _bufList.Add(new BGAPI2.Buffer());
            }
            foreach (KeyValuePair <string, BGAPI2.Buffer> buf in _bufList)
            {
                buf.Value.QueueBuffer();
            }
            #endregion

            _usbDataStream.StartAcquisition();
            _usbDevice.RemoteNodeList["AcquisitionStart"].Execute();

            return(new Result("Ok"));
        }