Exemplo n.º 1
0
 public void CreateAcqusition(SapAcquisition acq, SapLocation location, string configFileName)
 {
     if (location == null || configFileName == null)
     {
     }
     acq = new SapAcquisition(location, configFileName);
 }
Exemplo n.º 2
0
        //打开相机
        public override void OpenCameraHardTrigger(string DCF_Name)
        {
            if (m_Xfer == null)
            {
                ExampleUtils.configPath = DCF_Name;

                string[] args = null;
                if (!GetOptions(args, acqParams))
                {
                    MessageBox.Show("加载相机CCF文件失败!");
                    return;
                }

                m_ServerLocation = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex);

                CreateNewObjects(m_ServerLocation, acqParams.ConfigFileName);

                if (!CreateObjects())
                {
                    DisposeObjects();
                    return;
                }
            }
            else
            {
                //相机连接着
            }
        }
Exemplo n.º 3
0
 public void CreateAcqDevice(SapAcqDevice camera, SapLocation location, string configFileName)
 {
     if (location == null || configFileName == null)
     {
     }
     camera = new SapAcqDevice(location, configFileName);
 }
Exemplo n.º 4
0
 public void CreateLocation(SapLocation loc, string serverName, int index)
 {
     if (serverName == null || index < 0)
     {
     }
     loc = new SapLocation(serverName, index);
 }
Exemplo n.º 5
0
        private IDalsaTDICam Initialize()
        {
            try
            {
                ServerLocation = new SapLocation(ServerName, ResourceIndex);
                Acquisition    = new SapAcquisition(ServerLocation, ConfigFile);

                if (SapBuffer.IsBufferTypeSupported(ServerLocation, SapBuffer.MemoryType.ScatterGather))
                {
                    Buffers = new SapBufferWithTrash(2, Acquisition, SapBuffer.MemoryType.ScatterGather);
                }
                else
                {
                    Buffers = new SapBufferWithTrash(2, Acquisition, SapBuffer.MemoryType.ScatterGatherPhysical);
                }

                Acquisition.Create();

                Xfer = new SapAcqToBuf(Acquisition, Buffers);
                Xfer.Pairs [0].EventType = SapXferPair.XferEventType.EndOfFrame;
                return(this);
            }
            catch (Exception)
            {
                MessageBox.Show("Camera initialization is fail");
                return(null);
            }
        }
Exemplo n.º 6
0
        public bool init()     //初始化相机
        {
            try
            {
                m_ServerLocation = new SapLocation(m_ServerName, 0);
                // m_Acquisition = new SapAcquisition(m_ServerLocation, filename);
                m_AcqDevice = new SapAcqDevice(m_ServerLocation, filename);
                m_Buffers   = new SapBufferWithTrash(2, m_AcqDevice, SapBuffer.MemoryType.ScatterGather);
                m_Xfer      = new SapAcqDeviceToBuf(m_AcqDevice, m_Buffers);

                // m_Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
                m_Xfer.XferNotify += m_Xfer_XferNotify;

                if (!CreateObjects())
                {
                    DisposeObjects();
                    return(false);
                }
            }
            catch (Exception ex)
            {
                // MessageBox.Show(ex.ToString());
            }
            return(true);
        }
Exemplo n.º 7
0
        public bool CAM_connect()
        {
            try
            {
                //server名称
                int    ServerCount = SapManager.GetServerCount();
                int    ServerIndex = ServerCount - 1;
                string ServerName  = SapManager.GetServerName(ServerIndex);
                //设备Index
                int CameraCount   = SapManager.GetResourceCount(ServerName, SapManager.ResourceType.AcqDevice);
                int ResourceIndex = CameraCount - 1;
                //if (CameraCount == 0) MessageBox.Show("没有相机。");

                loc = new SapLocation(ServerName, ResourceIndex);

                //配置文件
                string   ConfigFileName;
                string   ConfigPath      = Environment.GetEnvironmentVariable("SAPERADIR") + "\\camFiles\\User\\";
                string[] ccffiles        = Directory.GetFiles(ConfigPath, "*.ccf");
                int      configFileCount = ccffiles.Length;
                ConfigFileName = ccffiles[0];
                //创建对象
                if (SapManager.GetResourceCount(ServerName, SapManager.ResourceType.AcqDevice) > 0)
                {
                    AcqDevice = new SapAcqDevice(loc, ConfigFileName);
                    Buffers   = new SapBuffer(1, AcqDevice, SapBuffer.MemoryType.ScatterGather);
                    Xfer      = new SapAcqDeviceToBuf(AcqDevice, Buffers);
                    if (!AcqDevice.Create())
                    {
                        return(false);
                    }
                }

                if (!Buffers.Create())
                {
                    return(false);
                }
                if (!Xfer.Create())
                {
                    return(false);
                }


                ////ManagedBusManager busMgr = new ManagedBusManager();
                ////uint numCameras = busMgr.GetNumOfCameras();
                ////ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0);
                ////m_camera = new ManagedCamera();
                ////m_camera.Connect(guid);
                //m_camera.IsConnected()
                //CameraInfo camInfo = m_camera.GetCameraInfo();
            }
            catch (FC2Exception ex)//要修改
            {
                MessageBox.Show("相机连接失败。");
                MessageBox.Show("Failed to load form successfully: " + ex.Message);
                return(false);
            }
            return(true);
        }
Exemplo n.º 8
0
        public AcquisitionDevice()
        {
            source = Observable.Create <IplImage>((observer, cancellationToken) =>
            {
                return(Task.Factory.StartNew(() =>
                {
                    lock (captureLock)
                    {
                        using (var location = new SapLocation(ServerName, DeviceIndex))
                            using (var device = new SapAcqDevice(location, ConfigFileName))
                                using (var buffer = new SapBufferWithTrash(2, device, SapBuffer.MemoryType.ScatterGather))
                                    using (var transfer = new SapAcqDeviceToBuf(device, buffer))
                                        using (var waitEvent = new AutoResetEvent(false))
                                        {
                                            if (!device.Create())
                                            {
                                                throw new InvalidOperationException("Error opening device.");
                                            }

                                            transfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
                                            transfer.XferNotify += (sender, e) =>
                                            {
                                                int channels;
                                                IplDepth depth;
                                                SapFormat outputFormat;
                                                GetImageDepth(buffer.Format, out depth, out channels, out outputFormat);
                                                var image = new IplImage(new Size(buffer.Width, buffer.Height), depth, channels);
                                                buffer.Write(0, buffer.Width * buffer.Height, image.ImageData);
                                                observer.OnNext(image);
                                                waitEvent.Set();
                                            };

                                            if (!buffer.Create())
                                            {
                                                throw new InvalidOperationException("Error creating buffer.");
                                            }

                                            if (!transfer.Create())
                                            {
                                                throw new InvalidOperationException("Error creating transfer.");
                                            }

                                            while (!cancellationToken.IsCancellationRequested)
                                            {
                                                waitEvent.WaitOne();
                                            }
                                        }
                    }
                },
                                             cancellationToken,
                                             TaskCreationOptions.LongRunning,
                                             TaskScheduler.Default));
            })
                     .PublishReconnectable()
                     .RefCount();
        }
Exemplo n.º 9
0
        void InitCam(int n)
        {
            DestroyObjects();
            DisposeObjects();
            m_ServerLocation = new SapLocation("X64-CL_iPro_1", 0);
            m_ConfigFileName = "IAG3.ccf";
            // define on-line object
            m_Acquisition = new SapAcquisition(m_ServerLocation, m_ConfigFileName);

            m_Buffers = new SapBufferWithTrash(n, m_Acquisition, SapBuffer.MemoryType.ScatterGather);

            m_Buffers.PixelDepth = SystemParam.cmosInfo.PixelDepth;
            m_Buffers.Format     = SapFormat.Mono16;
            m_Buffers.Height     = SystemParam.cmosInfo.ColPixels;
            m_Buffers.Width      = SystemParam.cmosInfo.RowPixels;
            m_Xfer = new SapAcqToBuf(m_Acquisition, m_Buffers);
            m_View = new SapView(m_Buffers);
            m_View.SetScalingMode(true);

            //event for view
            m_Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            m_Xfer.XferNotify        += new SapXferNotifyHandler(xfer_XferNotify1);
            m_Xfer.XferNotifyContext  = this;

            // event for signal status
            m_Acquisition.SignalNotify       += new SapSignalNotifyHandler(GetSignalStatus1);
            m_Acquisition.SignalNotifyContext = this;

            m_ImageBox.View = m_View;
            while (true)
            {
                try
                {
                    if (!CreateObjects())
                    {
                        DisposeObjects();
                        WFNetLib.WFGlobal.WaitMS(20);
                        continue;
                    }
                    break;
                }
                catch
                {
                    WFNetLib.WFGlobal.WaitMS(20);
                }
            }
            float WidthScalor  = (float)(this.Size.Width) / m_Buffers.Width;
            float HeightScalor = (float)(this.Size.Height) / m_Buffers.Height;

            m_View.SetScalingMode(WidthScalor, HeightScalor);
            m_ImageBox.OnSize();
            EnableSignalStatus();
            SystemParam.ByteLen4Pic = SystemParam.Pixel4Pic * m_Buffers.BytesPerPixel;
            m_Xfer.Grab();
        }
Exemplo n.º 10
0
        public void InitDevice(MyAcquisitionParams acqParams = null)
        {
            _acqParams = acqParams;

            if (acqParams == null)
            {
                string[] args = new string[0];
                if (!ExampleUtils.GetOptions(args, acqParams))
                {
                    Console.WriteLine("\nPress any key to terminate\n");
                    Console.ReadKey(true);
                    return;
                }
            }



            _loc = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex);
            if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice) > 0)
            {
                _acqDevice = new SapAcqDevice(_loc, acqParams.ConfigFileName);
                _buffers   = new SapBufferWithTrash(2, _acqDevice, SapBuffer.MemoryType.ScatterGather);
                _transfer  = new SapAcqDeviceToBuf(_acqDevice, _buffers);

                // Create acquisition object
                if (!_acqDevice.Create())
                {
                    Console.WriteLine("Error during SapAcqDevice creation!\n");
                    DestroysObjects(null, _acqDevice, _buffers, _transfer, _view);
                    return;
                }
            }

            _transfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            _transfer.XferNotify        += new SapXferNotifyHandler(xfer_XferNotify);
            _transfer.XferNotifyContext  = _buffers;

            // Create buffer object
            if (!_buffers.Create())
            {
                Console.WriteLine("Error during SapBuffer creation!\n");
                DestroysObjects(null, _acqDevice, _buffers, _transfer, _view);
                return;
            }

            // Create buffer object
            if (!_transfer.Create())
            {
                Console.WriteLine("Error during SapTransfer creation!\n");
                DestroysObjects(null, _acqDevice, _buffers, _transfer, _view);
                return;
            }

            _transfer.Grab();
        }
Exemplo n.º 11
0
 public DalsaCamera(string ServerName, string ConfigFile, int ResourceIndex)
 {
     if (!String.IsNullOrEmpty(ServerName) && !(String.IsNullOrEmpty(ConfigFile)))
     {
         m_ServerName     = ServerName;
         m_ConfigFileName = ConfigFile;
         m_ServerLocation = new SapLocation(ServerName, ResourceIndex);
     }
     else
     {
         throw new SaperaCameraException("No configuration file");
     }
 }
Exemplo n.º 12
0
        public AcqConfigDlg(SapLocation loc, string productDir, ServerCategory serverCategory)
        {
            m_ProductDir     = productDir;
            m_ServerCategory = serverCategory;

            if (loc != null)
            {
                m_ServerName    = loc.ServerName;
                m_ResourceIndex = loc.ServerIndex;
            }
            // Load parameters from registry
            LoadSettings();
            InitializeComponent();
        }
Exemplo n.º 13
0
        public bool CreateNewObjects(SapLocation location, string fileName, bool Restore)
        {
            if (Online)
            {
                if (!Restore)
                {
                    Location = location;
                }

                if (!SapManager.IsResourceAvailable(location, SapManager.ResourceType.Acq))
                {
                    Debug.WriteLine(fileName + "available");
                    return(false);
                }

                Acquisition = new SapAcquisition(Location, fileName);
                if (SapBuffer.IsBufferTypeSupported(Location, SapBuffer.MemoryType.ScatterGather))
                {
                    Buffers = new SapBufferWithTrash(4, Acquisition, SapBuffer.MemoryType.ScatterGather);
                }
                else
                {
                    Buffers = new SapBufferWithTrash(4, Acquisition, SapBuffer.MemoryType.ScatterGatherPhysical);
                }
                Xfer   = new SapAcqToBuf(Acquisition, Buffers);
                m_View = new SapView(Buffers);

                Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
                Xfer.XferNotify        += xfer_XferNotify;
                Xfer.XferNotifyContext  = this;
            }
            else
            {
                Buffers = new SapBuffer();
            }

            if (!CreateObjects())
            {
                DisposeObjects();
                return(false);
            }

            return(true);
        }
Exemplo n.º 14
0
        public bool CreateNewObjects(SapLocation ServerLocation, string ConfigFile)
        {
            m_Acquisition = new SapAcquisition(m_ServerLocation, ConfigFile);
            if (SapBuffer.IsBufferTypeSupported(m_ServerLocation, SapBuffer.MemoryType.ScatterGather))
            {
                m_Buffers = new SapBufferWithTrash(2, m_Acquisition, SapBuffer.MemoryType.ScatterGather);
            }
            else
            {
                m_Buffers = new SapBufferWithTrash(2, m_Acquisition, SapBuffer.MemoryType.ScatterGatherPhysical);
            }
            m_Xfer = new SapAcqToBuf(m_Acquisition, m_Buffers);


            //event for view
            m_Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            m_Xfer.XferNotify        += new SapXferNotifyHandler(xfer_XferNotify);

            return(true);
        }
Exemplo n.º 15
0
        void CreateCamObj()
        {
            ServerLocation = new SapLocation(ServerName, ResourceIndex);
            Acquisition    = new SapAcquisition(ServerLocation, ConfigFile);

            if (SapBuffer.IsBufferTypeSupported(ServerLocation, SapBuffer.MemoryType.ScatterGather))
            {
                Buffers = new SapBufferWithTrash(2, Acquisition, SapBuffer.MemoryType.ScatterGather);
            }
            else
            {
                Buffers = new SapBufferWithTrash(2, Acquisition, SapBuffer.MemoryType.ScatterGatherPhysical);
            }

            Acquisition.Create();

            Xfer = new SapAcqToBuf(Acquisition, Buffers);
            Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;

            View = new SapView(Buffers);
        }
Exemplo n.º 16
0
 public Boolean Create()
 {
     try
     {
         Params      = new MyAcquisitionParams();
         Location    = new SapLocation(Params.ServerName, Params.ResourceIndex);
         Device      = new SapAcqDevice(Location, Params.ConfigFileName);
         Buffers     = new SapBufferWithTrash(DefaultBuffer, Device, SapBuffer.MemoryType.ScatterGather);
         Acquisition = new SapAcquisition(Location, Params.ConfigFileName);
         Transfer    = new SapAcqToBuf(Acquisition, Buffers);
     }
     catch (SapException CreateException)
     {
         throw new Exception("CreateCamera failed!", CreateException);
     }
     finally
     {
         Console.WriteLine("Camera Created!");
     }
     return(true);
 }
Exemplo n.º 17
0
        /// <summary>
        /// 初始化设备
        /// </summary>
        /// <param name="acConfigDlg"></param>
        /// <param name="Restore"></param>
        /// <returns></returns>
        public bool CreateNewObjects(AcqConfigDlg acConfigDlg, bool Restore)
        {
            if (!Restore)
            {
                m_ServerLocation = acConfigDlg.ServerLocation;
                m_ConfigFileName = acConfigDlg.ConfigFile;
            }
            m_AcqDevice = new SapAcqDevice(m_ServerLocation, m_ConfigFileName);
            if (SapBuffer.IsBufferTypeSupported(m_ServerLocation, SapBuffer.MemoryType.ScatterGather))
            {
                m_Buffers = new SapBufferWithTrash(2, m_AcqDevice, SapBuffer.MemoryType.ScatterGather);
            }
            else
            {
                m_Buffers = new SapBufferWithTrash(2, m_AcqDevice, SapBuffer.MemoryType.ScatterGatherPhysical);
            }
            m_Xfer          = new SapAcqDeviceToBuf(m_AcqDevice, m_Buffers);
            m_View          = new SapView(m_Buffers);
            m_ImageBox.View = m_View;

            m_Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            m_Xfer.XferNotify        += new SapXferNotifyHandler(xfer_XferNotify);
            m_Xfer.XferNotifyContext  = this;
            StatusLabelInfo.Text      = "Online... Waiting grabbed images";

            if (!CreateObjects())
            {
                DisposeObjects();
                return(false);
            }

            // Resize ImagBox to take into account the size of created sapview
            m_ImageBox.OnSize();
            UpdateControls();
            return(true);
        }
Exemplo n.º 18
0
        private void btn_findcamera_Click(object sender, EventArgs e)
        {
            Console.WriteLine(cb_cameraselect.SelectedIndex);
            switch (cb_cameraselect.SelectedIndex)
            {
            case 0:
                Console.WriteLine("\n\nCameras listed by User Defined Name:\n");

                for (int serverIndex = 0; serverIndex < serverCount; serverIndex++)
                {
                    if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.AcqDevice) != 0)
                    {
                        SapLocation location = new SapLocation(SapManager.GetServerName(serverIndex), 0);
                        acqDevice = new SapAcqDevice(location);

                        // Create acquisition device object
                        bool status = acqDevice.Create();
                        if (status && acqDevice.FeatureCount > 0)
                        {
                            // Get User Defined Name Feature Value
                            status = acqDevice.GetFeatureValue("DeviceUserID", new SapLut(tx_commandparameter.Text.ToString()));
                            Console.WriteLine("{0}/ {1}", cameraIndex + 1, status ? userDefinedName : "N/A");
                            cameraIndex++;
                        }

                        // Destroy acquisition device object
                        acqDevice.Destroy();
                    }
                }
                if (cameraIndex == 0)
                {
                    Console.WriteLine("No camera found !");
                }
                if (acqDevice != null)
                {
                    acqDevice.Dispose();
                }
                break;

            case 1:
                Console.WriteLine("\n\nCameras listed by Serial Number:\n");
                string serialNumberName = "";

                for (int serverIndex = 0; serverIndex < serverCount; serverIndex++)
                {
                    if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.AcqDevice) != 0)
                    {
                        SapLocation location = new SapLocation(SapManager.GetServerName(serverIndex), 0);
                        acqDevice = new SapAcqDevice(location);

                        // Create acquisition device object
                        bool status = acqDevice.Create();
                        if (status && acqDevice.FeatureCount > 0)
                        {
                            // Get Serial Number Feature Value
                            status = acqDevice.GetFeatureValue("DeviceID", out serialNumberName);
                            Console.WriteLine("{0}/ {1}", cameraIndex + 1, status ? serialNumberName : "N/A");
                            cameraIndex++;
                        }

                        // Destroy acquisition device object
                        acqDevice.Destroy();
                    }
                }
                if (cameraIndex == 0)
                {
                    Console.WriteLine("No camera found !");
                }
                if (acqDevice != null)
                {
                    acqDevice.Dispose();
                }
                break;

            case 2:
                Console.WriteLine("\n\nCameras listed by Server Name:\n");

                for (int serverIndex = 0; serverIndex < serverCount; serverIndex++)
                {
                    if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.AcqDevice) != 0)
                    {
                        SapLocation location = new SapLocation(SapManager.GetServerName(serverIndex), 0);
                        acqDevice = new SapAcqDevice(location);

                        // Create acquisition device object
                        bool status = acqDevice.Create();
                        if (status && acqDevice.FeatureCount > 0)
                        {
                            // Get Server Name Value
                            Console.WriteLine("{0}/ {1}", cameraIndex + 1, SapManager.GetServerName(serverIndex));
                            cameraIndex++;
                        }

                        // Destroy acquisition device object
                        acqDevice.Destroy();
                    }
                }
                if (cameraIndex == 0)
                {
                    Console.WriteLine("No camera found !");
                }
                if (acqDevice != null)
                {
                    acqDevice.Dispose();
                }
                break;

            case 3:
                Console.WriteLine("\n\nCameras listed by Model Name:\n");
                string deviceModelName = "";

                for (int serverIndex = 0; serverIndex < serverCount; serverIndex++)
                {
                    if (SapManager.GetResourceCount(serverIndex, SapManager.ResourceType.AcqDevice) != 0)
                    {
                        SapLocation location = new SapLocation(SapManager.GetServerName(serverIndex), 0);
                        acqDevice = new SapAcqDevice(location);

                        // Create acquisition device object
                        bool status = acqDevice.Create();
                        if (status && acqDevice.FeatureCount > 0)
                        {
                            // Get Model Name Feature Value
                            status = acqDevice.GetFeatureValue("DeviceModelName", out deviceModelName);
                            Console.WriteLine("{0}/ {1}", cameraIndex + 1, status ? deviceModelName : "N/A");
                            cameraIndex++;
                        }

                        // Destroy acquisition device object
                        acqDevice.Destroy();
                    }
                }
                if (cameraIndex == 0)
                {
                    Console.WriteLine("No camera found !");
                }
                if (acqDevice != null)
                {
                    acqDevice.Dispose();
                }
                break;

            case 4:
                Console.WriteLine("Please type the user defined name:\n");
                userDefinedName = Console.ReadLine();
                serverName      = SapManager.GetServerName(userDefinedName);
                if (serverName.Length > 0)
                {
                    Console.WriteLine("\nServer name for {0} is {1}", userDefinedName, serverName);
                }
                else
                {
                    Console.WriteLine("\nNo server found for {0}", userDefinedName);
                }
                break;

            case 5:
                Console.Write("\nDetecting new CameraLink camera servers... ");
                if (SapManager.DetectAllServers(SapManager.DetectServerType.All))
                {
                    // let time for the detection to execute
                    Thread.Sleep(5000);

                    // get the new server count
                    serverCount = SapManager.GetServerCount();

                    Console.WriteLine("complete\n");
                }
                else
                {
                    Console.WriteLine("failed\n");
                }
                break;
            }
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            SapAcquisition Acq = null;
            SapAcqDevice AcqDevice = null;
            SapBuffer Buffers = null;
            SapTransfer Xfer = null;
            SapView View = null;

            //Console.WriteLine("Sapera Console Grab Example (C# version)\n");

            MyAcquisitionParams acqParams = new MyAcquisitionParams();

            // Call GetOptions to determine which acquisition device to use and which config
            // file (CCF) should be loaded to configure it.
            if (!GetOptions(args, acqParams))
            {
                Console.WriteLine("\nPress any key to terminate\n");
                Console.ReadKey(true);
                return;
            }

            SapLocation loc = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex);

            if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.Acq) > 0)
            {
                Acq         = new SapAcquisition(loc, acqParams.ConfigFileName);
                Buffers     = new SapBuffer(1, Acq, SapBuffer.MemoryType.ScatterGather);
                Xfer = new SapAcqToBuf(Acq, Buffers);

               // Create acquisition object
                if (!Acq.Create())
                {
                    Console.WriteLine("Error during SapAcquisition creation!\n");
                    DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                    return;
                }
            }

            if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice) > 0)
            {
                AcqDevice   = new SapAcqDevice(loc, acqParams.ConfigFileName);
                Buffers = new SapBuffer(1, AcqDevice, SapBuffer.MemoryType.ScatterGather);
                Xfer = new SapAcqDeviceToBuf(AcqDevice, Buffers);

               // Create acquisition object
                if (!AcqDevice.Create())
                {
                    Console.WriteLine("Error during SapAcqDevice creation!\n");
                    DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                    return;
                }
            }

            View = new SapView(Buffers);
            // End of frame event
            Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            Xfer.XferNotify += new SapXferNotifyHandler(xfer_XferNotify);
            Xfer.XferNotifyContext = View;

            //Console.WriteLine("gggggwhat is new line");
            // Create buffer object
            if (!Buffers.Create())
            {
                Console.WriteLine("Error during SapBuffer creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Create buffer object
            if (!Xfer.Create())
            {
                Console.WriteLine("Error during SapTransfer creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Create buffer object
            if (!View.Create())
            {
                Console.WriteLine("Error during SapView creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Grab as fast as possible, wait for a key to be pressed, if it's p,
            // write the file, otherwise if it's q exit the program. Designed to be run by and monitored
            // through a pipe

            Boolean stop_snap = false;
            int curr_code = 0;
            string new_cmd = "";
            while (stop_snap == false)
            {
                Console.WriteLine("Press a key to trigger snap");
                new_cmd = Console.ReadLine();
                Xfer.Snap();

                Console.WriteLine("Press a key to trigger save");
                new_cmd = Console.ReadLine();
                View.Buffer.Save("test.raw", "-format raw");

                var dsb = new StringBuilder("frame: " + frame_count);
                Console.WriteLine(dsb);
                frame_count = frame_count + 1;

                Console.WriteLine("File saved, Press a key to repeat, q to quit:");
                new_cmd = Console.ReadLine();
                if (new_cmd == "q") { stop_snap = true; }
                //if (curr_code == 113) { stop_snap = true; }

            }

            DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
            loc.Dispose();
        }
Exemplo n.º 20
0
        //static void Main(string[] args)
        public static void Done()
        {
            SapAcqDevice camera   = null;
            SapView      view     = null;
            SapTransfer  transfer = null;
            SapBuffer    buffer   = null;

            Console.WriteLine("Sapera Console GigE Cameras AutoWhiteBalance Example (C# version)\n");

            MyAcquisitionParams acqParams = new MyAcquisitionParams();

            /*if (!GetOptions(args, acqParams))
             * {
             *  Console.WriteLine("\nPress any key to terminate\n");
             *  Console.ReadKey();
             *  return;
             * }*/
            SapLocation location = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex);


            camera   = new SapAcqDevice(location, acqParams.ConfigFileName);
            buffer   = new SapBufferWithTrash(2, camera, SapBuffer.MemoryType.ScatterGather);
            transfer = new SapAcqDeviceToBuf(camera, buffer);
            view     = new SapView(buffer);

            // End of frame event
            transfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            transfer.XferNotify        += new SapXferNotifyHandler(Xfer_XferNotify);
            transfer.XferNotifyContext  = view;

            if (!camera.Create())
            {
                Console.WriteLine("Error during SapAcquisition creation!\n");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            // Monochrome models are not supported for White Balance Calibration.
            int  colorType   = 0;
            bool isAvailable = false;

            if (isAvailable = camera.IsFeatureAvailable("ColorType"))
            {
                if (camera.GetFeatureValue("ColorType", out colorType))
                {
                    if (colorType == 0)
                    {
                        Console.WriteLine("This camera model does not support Auto White Balance calibration.\n");
                        DestroysObjects(camera, buffer, transfer, view);
                        return;
                    }
                }
            }


            //activate feature only if camera has 3 separate gains

            Boolean bRedGain   = false;
            Boolean bGreenGain = false;
            Boolean bBlueGain  = false;

            bRedGain   = camera.IsFeatureAvailable("GainRed");
            bGreenGain = camera.IsFeatureAvailable("GainGreen");
            bBlueGain  = camera.IsFeatureAvailable("GainBlue");
            if (!bRedGain && !bGreenGain && !bBlueGain)
            {
                Console.WriteLine("This camera model does not support Auto White Balance calibration.\n");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            // Create buffer object
            if (!buffer.Create())
            {
                Console.WriteLine("Error during SapBuffer creation!\n");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            // Create transfer object
            if (!transfer.Create())
            {
                Console.WriteLine("Error during SapTransfer creation!\n");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            // Create view object
            if (!view.Create())
            {
                Console.WriteLine("Error during SapView creation!\n");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            Console.WriteLine("Press any key to start Grab. Press 'q' to quit.");
            ConsoleKeyInfo info = Console.ReadKey(true);
            char           key  = info.KeyChar;

            if (key != 0)
            {
                if (key == 'q')
                {
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }
            }

            // Start continous grab
            transfer.Grab();

            Console.WriteLine("Press any key to stop grab\n");
            Console.ReadKey();

            // Stop grab
            transfer.Freeze();
            transfer.Wait(5000);

            Console.WriteLine("Press any key to start Auto White Balance calibration. Press 'q' to quit.\n");
            info = Console.ReadKey(true);
            key  = info.KeyChar;
            if (key != 0)
            {
                if (key == 'q')
                {
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }
            }

            int oldPixelFormat = 0;

            isAvailable = false;
            if (isAvailable = camera.IsFeatureAvailable("PixelFormat"))
            {
                camera.GetFeatureValue("PixelFormat", out oldPixelFormat);
            }
            else
            {
                Console.WriteLine("This camera model does not support Auto White Balance calibration.\n");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            if (oldPixelFormat != GVSP_PIX_BAYRG8)
            {
                // Camera Pixel Format defined is not Raw Bayer.
                // We change the value

                DestroysObjects(null, buffer, transfer, view);

                camera.SetFeatureValue("PixelFormat", GVSP_PIX_BAYRG8);

                // Instantiation of new buffer object
                buffer = new SapBufferWithTrash(2, camera, SapBuffer.MemoryType.ScatterGather);
                // Instantiation of new view object
                view = new SapView(buffer);
                // Instantiation of new transfer object
                transfer = new SapAcqDeviceToBuf(camera, buffer);

                // End of frame event
                transfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
                transfer.XferNotify        += new SapXferNotifyHandler(Xfer_XferNotify);
                transfer.XferNotifyContext  = view;

                if (!camera.Create())
                {
                    Console.WriteLine("Error during SapAcquisition creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }

                // Create buffer object
                if (!buffer.Create())
                {
                    Console.WriteLine("Error during SapBuffer creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }

                // Create transfer object
                if (!transfer.Create())
                {
                    Console.WriteLine("Error during SapTransfer creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }

                // Create view object
                if (!view.Create())
                {
                    Console.WriteLine("Error during SapView creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }
            }


            if (!AutoWhiteBalanceOperations(camera, buffer, transfer))
            {
                Console.WriteLine("Auto WhiteBalamce has failed");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            if (oldPixelFormat != GVSP_PIX_BAYRG8)
            {
                // Camera Pixel Format was changed for Raw Bayer.
                // We set the original value.
                DestroysObjects(null, buffer, transfer, view);

                camera.SetFeatureValue("PixelFormat", oldPixelFormat);

                // Instantiation of new buffer object
                buffer = new SapBufferWithTrash(2, camera, SapBuffer.MemoryType.ScatterGather);
                // Instantiation of new view object
                view = new SapView(buffer);
                // Instantiation of new transfer object
                transfer = new SapAcqDeviceToBuf(camera, buffer);

                // End of frame event
                transfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
                transfer.XferNotify        += new SapXferNotifyHandler(Xfer_XferNotify);
                transfer.XferNotifyContext  = view;

                // Create buffer object
                if (!buffer.Create())
                {
                    Console.WriteLine("Error during SapBuffer creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }

                // Create transfer object
                if (!transfer.Create())
                {
                    Console.WriteLine("Error during SapTransfer creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }

                // Create view object
                if (!view.Create())
                {
                    Console.WriteLine("Error during SapView creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }
            }

            Console.WriteLine("Press any key to start Grab. Press 'q' to quit.\n");
            info = Console.ReadKey(true);
            key  = info.KeyChar;
            if (key != 0)
            {
                if (key == 'q')
                {
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }
            }

            // Start continous grab
            transfer.Grab();

            Console.WriteLine("Press any key to stop grab\n");
            Console.ReadKey();

            // Stop grab
            transfer.Freeze();
            transfer.Wait(5000);

            DestroysObjects(camera, buffer, transfer, view);
            location.Dispose();
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            SapAcquisition Acq       = null;
            SapAcqDevice   AcqDevice = null;
            SapBuffer      Buffers   = null;
            SapTransfer    Xfer      = null;
            SapView        View      = null;

            Console.WriteLine("Sapera Console Grab Example (C# version)\n");

            MyAcquisitionParams acqParams = new MyAcquisitionParams();

            // Call GetOptions to determine which acquisition device to use and which config
            // file (CCF) should be loaded to configure it.
            if (!GetOptions(args, acqParams))
            {
                Console.WriteLine("\nPress any key to terminate\n");
                Console.ReadKey(true);
                return;
            }

            SapLocation loc = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex);

            if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.Acq) > 0)
            {
                Acq     = new SapAcquisition(loc, acqParams.ConfigFileName);
                Buffers = new SapBufferWithTrash(2, Acq, SapBuffer.MemoryType.ScatterGather);
                Xfer    = new SapAcqToBuf(Acq, Buffers);

                // Create acquisition object
                if (!Acq.Create())
                {
                    Console.WriteLine("Error during SapAcquisition creation!\n");
                    DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                    return;
                }
                Acq.EnableEvent(SapAcquisition.AcqEventType.StartOfFrame);
            }

            else if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice) > 0)
            {
                AcqDevice = new SapAcqDevice(loc, acqParams.ConfigFileName);
                Buffers   = new SapBufferWithTrash(2, AcqDevice, SapBuffer.MemoryType.ScatterGather);
                Xfer      = new SapAcqDeviceToBuf(AcqDevice, Buffers);

                // Create acquisition object
                if (!AcqDevice.Create())
                {
                    Console.WriteLine("Error during SapAcqDevice creation!\n");
                    DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                    return;
                }
            }

            View = new SapView(Buffers);

            // End of frame event
            Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            Xfer.XferNotify        += new SapXferNotifyHandler(xfer_XferNotify);
            Xfer.XferNotifyContext  = View;

            // Create buffer object
            if (!Buffers.Create())
            {
                Console.WriteLine("Error during SapBuffer creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Create buffer object
            if (!Xfer.Create())
            {
                Console.WriteLine("Error during SapTransfer creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Create buffer object
            if (!View.Create())
            {
                Console.WriteLine("Error during SapView creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }


            Xfer.Grab();
            Console.WriteLine("\n\nGrab started, press a key to freeze");
            Console.ReadKey(true);
            Xfer.Freeze();
            Xfer.Wait(1000);

            DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
            loc.Dispose();
        }
Exemplo n.º 22
0
        void InitCam(int n)
        {
            while (true)
            {
                try
                {
                    DestroyObjects();
                    DisposeObjects();
                    if (m_online)
                    {
                        m_ServerLocation = new SapLocation("X64-CL_iPro_1", 0);
                        m_ConfigFileName = SystemParam.cmosInfo.ccfPath;//@"C:\Program Files\Teledyne DALSA\Sapera\CamFiles\User\w512x512.ccf";
                        // define on-line object
                        m_Acquisition = new SapAcquisition(m_ServerLocation, m_ConfigFileName);

                        m_Buffers = new SapBufferWithTrash(n, m_Acquisition, SapBuffer.MemoryType.ScatterGather);


                        m_Xfer = new SapAcqToBuf(m_Acquisition, m_Buffers);
                        //                 m_View = new SapView(m_Buffers);
                        //                 m_View.SetScalingMode(true);

                        //event for view
                        m_Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
                        m_Xfer.XferNotify        += new SapXferNotifyHandler(xfer_XferNotify);
                        m_Xfer.XferNotifyContext  = this;

                        // event for signal status
                        m_Acquisition.SignalNotify       += new SapSignalNotifyHandler(GetSignalStatus);
                        m_Acquisition.SignalNotifyContext = this;
                    }
                    else
                    {
                        m_Buffers = new SapBuffer(1, SystemParam.cmosInfo.RowPixels, SystemParam.cmosInfo.ColPixels, SapFormat.Mono16, SapBuffer.MemoryType.ScatterGather);
                        //                 m_View = new SapView(m_Buffers);
                        //                 m_View.SetScalingMode(true);
                        StatusLabelInfo.Text = "offline... Load images";
                    }

                    //m_ImageBox.View = m_View;
                    while (true)
                    {
                        try
                        {
                            if (!CreateObjects())
                            {
                                DisposeObjects();
                                WFNetLib.WFGlobal.WaitMS(20);
                                continue;
                            }
                            break;
                        }
                        catch
                        {
                            WFNetLib.WFGlobal.WaitMS(20);
                        }
                    }
                    SystemParam.cmosInfo.PixelDepth = m_Buffers.PixelDepth;
                    SystemParam.cmosInfo.ColPixels  = m_Buffers.Height;
                    SystemParam.cmosInfo.RowPixels  = m_Buffers.Width;
                    if (SystemParam.cmosInfo.bRGB != 0)
                    {
                        wfSapGUI.GetRGBPixelInfo(SystemParam.cmosInfo.RowPixels, SystemParam.cmosInfo.ColPixels, SystemParam.cmosInfo.RGB1, SystemParam.cmosInfo.RGB2, SystemParam.cmosInfo.RGB3, SystemParam.cmosInfo.RGB4);
                    }
                    SystemParam.Pixel4Pic = (int)SystemParam.cmosInfo.ColPixels * SystemParam.cmosInfo.RowPixels;
                    float WidthScalor  = (float)(splitContainer1.Panel2.Size.Width) / m_Buffers.Width;
                    float HeightScalor = (float)(splitContainer1.Panel2.Size.Height) / m_Buffers.Height;
                    //m_View.SetScalingMode(WidthScalor, HeightScalor);
                    //m_ImageBox.OnSize();
                    EnableSignalStatus();
                    SystemParam.ByteLen4Pic = SystemParam.Pixel4Pic * m_Buffers.BytesPerPixel;
                    m_Xfer.Freeze();
                    return;
                }
                catch
                {
                }
            }
        }
Exemplo n.º 23
0
        public override bool DoInit()
        {
            int DalsaCardCount = SapManager.GetServerCount(); //获取图像采集卡的数量

            for (int i = 0; i < DalsaCardCount; i++)
            {
                bool bAcq       = false;
                bool bAcqDevice = false;
                if (SapManager.GetResourceCount(i, SapManager.ResourceType.Acq) > 0)
                {
                    bAcq = true;                                                                     //卡的数量大于0
                }
                if (SapManager.GetResourceCount(i, SapManager.ResourceType.AcqDevice) > 0)
                {
                    bAcqDevice = true;                                                                    //相机数量大于0
                }
                if (bAcq)
                {
                    string ServerName = SapManager.GetServerName(i);
                    if (this.myCamPara.ServerName == ServerName)
                    {
                        bServerFound = true; //发现图像采集卡
                        string DeviceName = SapManager.GetResourceName(ServerName, SapManager.ResourceType.Acq, 0);
                        if (this.myCamPara.DeviceName != DeviceName)
                        {
                            Logger.PopError("采集卡上找到的相机名字和campara里的名字不同");
                            return(false);
                        }
                    }
                }
                else if (bAcqDevice) //没有采集卡,相机直接传给电脑
                {
                    CameraIsFound = true;
                    string serverName = SapManager.GetServerName(i);
                }
            }
            if (!bServerFound && !CameraIsFound)  //至少需要一张采集卡,或者相机装置
            {
                m_Buffers = new SapBuffer();
                return(false);
            }
            else
            {
                SapLocation location = new SapLocation(this.myCamPara.ServerName, 0);
                if (SapManager.GetResourceCount(this.myCamPara.ServerName, SapManager.ResourceType.Acq) > 0)
                {
                    m_Acquisition = new SapAcquisition(location, System.Windows.Forms.Application.StartupPath + "\\ccf\\" + this.myCamPara.CcfPath + ".ccf");
                    //m_AcqDevice = new SapAcqDevice(location, System.Windows.Forms.Application.StartupPath + "\\ccf\\" + this.myCamPara.CcfPath + ".ccf");
                    if (SapBuffer.IsBufferTypeSupported(location, SapBuffer.MemoryType.ScatterGather))
                    {
                        m_Buffers = new SapBuffer(m_RingBufCount, m_Acquisition, SapBuffer.MemoryType.ScatterGather); //buffer里有10段内存,用来循环存储从相机采集的图片
                    }
                    else
                    {
                        m_Buffers = new SapBufferWithTrash(m_RingBufCount, m_Acquisition, SapBuffer.MemoryType.ScatterGatherPhysical);
                    }
                    m_Xfer = new SapAcqToBuf(m_Acquisition, m_Buffers);
                    m_Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
                    m_Xfer.XferNotify        += new SapXferNotifyHandler(AcqCallback1);
                    m_Xfer.XferNotifyContext  = this;
                    // event for signal status
                    if (!SeparaInterface_CreateObjects())
                    {
                        Logger.PopError(" 创建 相关的采集、传输、缓存对象失败");
                        this.SeparaInterface_DisposeObjects();
                        return(false);
                    }
                    this.FrameImgHei = this.SeparaInterface_GetImageHeight();
                    this.FrameImgWid = this.SeparaInterface_GetImageWidth();
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            SapAcquisition Acq       = null;
            SapAcqDevice   AcqDevice = null;
            SapBuffer      Buffers   = null;
            SapTransfer    Xfer      = null;
            SapView        View      = null;

            //Console.WriteLine("Sapera Console Grab Example (C# version)\n");

            MyAcquisitionParams acqParams = new MyAcquisitionParams();

            // Call GetOptions to determine which acquisition device to use and which config
            // file (CCF) should be loaded to configure it.
            if (!GetOptions(args, acqParams))
            {
                Console.WriteLine("\nPress any key to terminate\n");
                Console.ReadKey(true);
                return;
            }

            SapLocation loc = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex);

            if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.Acq) > 0)
            {
                Acq     = new SapAcquisition(loc, acqParams.ConfigFileName);
                Buffers = new SapBuffer(1, Acq, SapBuffer.MemoryType.ScatterGather);
                Xfer    = new SapAcqToBuf(Acq, Buffers);

                // Create acquisition object
                if (!Acq.Create())
                {
                    Console.WriteLine("Error during SapAcquisition creation!\n");
                    DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                    return;
                }
            }

            if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice) > 0)
            {
                AcqDevice = new SapAcqDevice(loc, acqParams.ConfigFileName);
                Buffers   = new SapBuffer(1, AcqDevice, SapBuffer.MemoryType.ScatterGather);
                Xfer      = new SapAcqDeviceToBuf(AcqDevice, Buffers);

                // Create acquisition object
                if (!AcqDevice.Create())
                {
                    Console.WriteLine("Error during SapAcqDevice creation!\n");
                    DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                    return;
                }
            }

            View = new SapView(Buffers);
            // End of frame event
            Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            Xfer.XferNotify        += new SapXferNotifyHandler(xfer_XferNotify);
            Xfer.XferNotifyContext  = View;

            //Console.WriteLine("gggggwhat is new line");
            // Create buffer object
            if (!Buffers.Create())
            {
                Console.WriteLine("Error during SapBuffer creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Create buffer object
            if (!Xfer.Create())
            {
                Console.WriteLine("Error during SapTransfer creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Create buffer object
            if (!View.Create())
            {
                Console.WriteLine("Error during SapView creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Grab as fast as possible, wait for a key to be pressed, if it's p,
            // write the file, otherwise if it's q exit the program. Designed to be run by and monitored
            // through a pipe

            Boolean stop_snap = false;
            int     curr_code = 0;
            string  new_cmd   = "";

            while (stop_snap == false)
            {
                Console.WriteLine("Press a key to trigger snap");
                new_cmd = Console.ReadLine();
                Xfer.Snap();

                Console.WriteLine("Press a key to trigger save");
                new_cmd = Console.ReadLine();
                View.Buffer.Save("test.raw", "-format raw");

                var dsb = new StringBuilder("frame: " + frame_count);
                Console.WriteLine(dsb);
                frame_count = frame_count + 1;


                Console.WriteLine("File saved, Press a key to repeat, q to quit:");
                new_cmd = Console.ReadLine();
                if (new_cmd == "q")
                {
                    stop_snap = true;
                }
                //if (curr_code == 113) { stop_snap = true; }
            }

            DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
            loc.Dispose();
        }