Ejemplo n.º 1
0
        private void startButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Read UI controls
                string cameraName = cameraComboBox.Text;
                selectedAcquisitionType = (ImaqdxAcquisitionType)acquisitionModeComboBox.SelectedItem;
                numBuffersUsed          = (int)numberOfBuffersControl.Value;
                selectedBufferWaitMode  = bufferWaitMode.Text;

                // Open a new session and configure a grab
                _session = new ImaqdxSession(cameraName);
                _session.Acquisition.Configure(selectedAcquisitionType, numBuffersUsed);
                _session.Acquisition.Start();

                // Update UI state
                startButton.Enabled             = false;
                stopButton.Enabled              = true;
                numberOfBuffersControl.Enabled  = false;
                acquisitionModeComboBox.Enabled = false;
                bufferWaitMode.Enabled          = false;
                cameraComboBox.Enabled          = false;

                // Start up background worker to acquire images
                acquisitionWorker.RunWorkerAsync();
            }
            catch (ImaqdxException ex)
            {
                _session.Close();
                _session = null;
                MessageBox.Show(ex.Message, "NI-IMAQdx Error");
            }
        }
Ejemplo n.º 2
0
        void acquisitionWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Result is ImaqdxException)
            {
                MessageBox.Show(((ImaqdxException)e.Result).ToString(), "NI-IMAQdx Error");
            }
            try
            {
                // Close the camera in case it hasn't already been closed
                if (_session != null)
                {
                    _session.Close();
                    _session = null;
                }
            }
            catch (ImaqdxException error)
            {
                MessageBox.Show(error.ToString(), "NI-IMAQdx Error");
            }

            // Update UI controls
            bufNumTextBox.Text  = "";
            startButton.Enabled = true;
            stopButton.Enabled  = false;
        }
        /// <summary>
        /// 依据相机配置链接相机
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public bool Connectted(CameraConfig config, Module module, Camera cam)
        {
            try
            {
                this.CameraConfig = config;
                if (camera != null)
                {
                    UITimer.Stop();
                    camera.Acquisition.Unconfigure();
                    camera.Dispose();
                }

                camera        = new ImaqdxSession(config.Name);
                this.Exposure = config.DefaultExp;
                this.Gain     = config.DefaultGain;
                this.Timeout  = 1000;

                for (int i = 0; i < config.Mat2D.Count; ++i)
                {
                    config.Mat2D[i].LoadCalib(PathDefine.sPathCamera + $"{module}-{cam}-{i}.bmp");
                }

                bOpen = true;
            }
            catch (Exception ex)
            {
                bOpen = false;
                throw new Exception($"相机[{config.Name}]初始化失败!!! 原因[{ex.StackTrace}]");
            }

            return(bOpen);
        }
Ejemplo n.º 4
0
        private void startButton_Click(object sender, EventArgs e)
        {
            try
            {
                imageScrollBar.Enabled = false;
                int numberOfImages = (int)numImages.Value;

                // Open camera
                _session = new ImaqdxSession(cameraComboBox.Text);

                // Create array of images
                images = new VisionImage[numberOfImages];
                for (int i = 0; i < images.Length; ++i)
                {
                    images[i] = new VisionImage();
                }

                // Acquire the sequence of images
                _session.Sequence(images, numberOfImages);

                // Close the camera
                _session.Close();

                // Update UI controls
                imageViewer.Attach(images[0]);
                imageScrollBar.Minimum = 0;
                imageScrollBar.Value   = imageScrollBar.Minimum;
                imageScrollBar.Maximum = numberOfImages - 1;
                imageScrollBar.Enabled = true;
            }
            catch (ImaqdxException ex)
            {
                MessageBox.Show(ex.Message, "NI-IMAQdx Error");
            }
        }
Ejemplo n.º 5
0
        private void openButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Stop any on-going acquisition
                stopButton.PerformClick();

                // Close the camera if one has already been opened
                if (_session != null)
                {
                    _session.Close();
                    _session = null;
                }

                // Create the session
                _session = new ImaqdxSession(cameraName.Text);

                // Update the tree of attributes
                PopulateTree();

                // Update the UI buttons
                startButton.Enabled = true;
            }
            catch (ImaqdxException error)
            {
                MessageBox.Show(error.ToString(), "NI-IMAQdx Error");
            }
        }
Ejemplo n.º 6
0
        public string InitCamera()
        {
            string rtn = string.Empty;

            try
            {
                _Session = new ImaqdxSession(this.Config.DevName);
                using (VisionImage A = new VisionImage())
                {
                    this._Session.Acquisition.Unconfigure();
                    this._Session.Snap(A);
                }

                //this._session.Attributes["CameraAttributes::UserSetControl::UserSetSelector"].SetValue(1);//68
                //this._session.Attributes["CameraAttributes::UserSetControl::UserSetLoad"].SetValue(1);//69

                this._Session.Attributes["AcquisitionAttributes::Timeout"].SetValue(1000);

                this._Session.Attributes["CameraAttributes::ImageFormatControl::Width"].SetValue(this.Config.FOV.Width);
                this._Session.Attributes["CameraAttributes::ImageFormatControl::Height"].SetValue(this.Config.FOV.Height);
                this._Session.Attributes["CameraAttributes::ImageFormatControl::OffsetX"].SetValue(this.Config.FOV.Left);
                this._Session.Attributes["CameraAttributes::ImageFormatControl::OffsetY"].SetValue(this.Config.FOV.Top);
                this.Shutter = this.Config.Expouse;
            }
            catch (Exception ex) { rtn = ex.Message; }
            return(rtn);
        }
Ejemplo n.º 7
0
        void acquisitionWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            // Show the any error result from the Grab operation
            if (e.Result is ImaqdxException)
            {
                MessageBox.Show(((ImaqdxException)e.Result).ToString(), "NI-IMAQdx Error");
            }
            try
            {
                // Close the camera in case it hasn't already been closed
                if (_session != null)
                {
                    _session.Close();
                    _session = null;
                }
            }
            catch (ImaqdxException error)
            {
                MessageBox.Show(error.ToString(), "NI-IMAQdx Error");
            }

            // Update UI controls
            startButton.Enabled             = true;
            stopButton.Enabled              = false;
            numberOfBuffersControl.Enabled  = true;
            acquisitionModeComboBox.Enabled = true;
            bufferWaitMode.Enabled          = true;
            cameraComboBox.Enabled          = true;
        }
Ejemplo n.º 8
0
 internal ImaqdxAcquisition(ImaqdxSession session)
 {
     _session         = session;
     _callbackManager = new CallbackManager();
     _callbackManager.SynchronizeCallbacks = DefaultSynchronizeCallbacks;
     _frameDoneEventHandler            = new EventHandler <ImaqdxImageAcquiredEventArgs>(OnImageAcquired);
     _frameDoneEventHandlers           = new List <EventHandler <ImaqdxImageAcquiredEventArgs> >();
     _frameDoneDriverCallback          = new ImaqdxFrameDoneEventHandler(ImageAcquiredDriverCallback);
     _frameDoneDriverCallbackInstalled = false;
 }
Ejemplo n.º 9
0
 private void initializeCamera()
 {
     try
     {
         imaqdxSession = new ImaqdxSession(cameraName);
     }
     catch (ImaqdxException e)
     {
         MessageBox.Show(e.Message);
         throw new ImaqdxException();
     }
 }
Ejemplo n.º 10
0
        internal ImaqdxAttributeCollection(ImaqdxSession session)
            : base(new List <ImaqdxAttribute>())
        {
            _session = session;
            _attributeLookupTable = new Dictionary <string, int>();

            // Initialize the attribute collection
            ImaqdxAttributeInformation[] attributeInfoArray = ImaqdxAttributeManager.EnumeratePublicAttributes(session.Handle);
            for (int i = 0; i < attributeInfoArray.Length; i++)
            {
                AddAttribute(attributeInfoArray[i]);
            }
        }
Ejemplo n.º 11
0
        private void startButton_Click(object sender, EventArgs e)
        {
            try
            {
                startButton.Enabled = false;
                int numberOfImages = (int)numImages.Value;

                // Open the camera
                _session = new ImaqdxSession(cameraComboBox.Text);

                // Create images
                images = new VisionImage[numberOfImages];
                for (uint i = 0; i < images.Length; ++i)
                {
                    images[i] = new VisionImage();
                }

                // Configure and start the camera
                _session.Acquisition.Configure(ImaqdxAcquisitionType.SingleShot, numberOfImages);
                _session.Acquisition.Start();

                // Get each image in the sequence
                for (uint i = 0; i < images.Length; ++i)
                {
                    _session.Acquisition.GetImageAt(images[i], i);
                }

                // Stop, Unconfigure, and Close the camera
                _session.Acquisition.Stop();
                _session.Acquisition.Unconfigure();
                _session.Close();
                _session = null;

                // Attach the viewer to the first image
                imageViewer.Attach(images[0]);

                // Setup the scroll bar to select the images
                imageScrollBar.Minimum = 0;
                imageScrollBar.Value   = imageScrollBar.Minimum;
                imageScrollBar.Maximum = numberOfImages - 1;
                imageScrollBar.Enabled = true;
            }
            catch (ImaqdxException ex)
            {
                MessageBox.Show(ex.Message, "NI-IMAQdx Error");
            }
            startButton.Enabled = true;
        }
Ejemplo n.º 12
0
 private void stopButton_Click(object sender, EventArgs e)
 {
     try
     {
         acquisitionWorker.CancelAsync();
         if (_session != null)
         {
             _session.Close();
             _session = null;
         }
         bufNumTextBox.Text = "";
     }
     catch (ImaqdxException ex)
     {
         MessageBox.Show(ex.Message, "NI-IMAQdx Error");
     }
 }
Ejemplo n.º 13
0
        private void startButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Open camera
                _session = new ImaqdxSession(cameraComboBox.Text);

                // Snap an image
                _session.Snap(imageViewer.Image);

                // Close the camera
                _session.Close();
            }
            catch (ImaqdxException ex)
            {
                MessageBox.Show(ex.Message, "NI-IMAQdx Error");
            }
        }
Ejemplo n.º 14
0
        private void stopButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Notify the acquisition worker that we are stopping
                acquisitionWorker.CancelAsync();

                // Close the session
                if (_session != null)
                {
                    _session.Close();
                    _session = null;
                }
            }
            catch (ImaqdxException ex)
            {
                MessageBox.Show(ex.Message, "NI-IMAQdx Error");
            }
        }
Ejemplo n.º 15
0
        private void startButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Open a new session and configure a grab
                _session = new ImaqdxSession(cameraComboBox.Text);
                _session.ConfigureGrab();

                // Update UI state
                startButton.Enabled = false;
                stopButton.Enabled  = true;

                // Start up background worker to acquire images
                acquisitionWorker.RunWorkerAsync();
            }
            catch (ImaqdxException ex)
            {
                MessageBox.Show(ex.Message, "NI-IMAQdx Error");
            }
        }
Ejemplo n.º 16
0
        private void quitButton_Click(object sender, EventArgs e)
        {
            // Stop any acquisition
            stopButton.PerformClick();

            // Close the camera
            if (_session != null)
            {
                try
                {
                    _session.Close();
                    _session = null;
                }
                catch (ImaqdxException)
                {
                    // We might as well ignore errors here since we are quitting
                }
            }
            this.Close();
            Application.Exit();
        }
        /// <summary>
        /// 依据设备名称链接相机
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public bool Connectted(string name)
        {
            try
            {
                if (camera != null)
                {
                    UITimer.Stop();
                    camera.Acquisition.Unconfigure();
                    camera.Dispose();
                }

                camera = new ImaqdxSession(name);
                bOpen  = true;
            }
            catch (Exception ex)
            {
                bOpen = false;
            }

            return(bOpen);
        }
Ejemplo n.º 18
0
        private void startButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Open camera
                _session = new ImaqdxSession(cameraComboBox.Text);

                // Configure and start a single-shot acquisition with 1 image
                _session.Acquisition.Configure(ImaqdxAcquisitionType.SingleShot, 1);
                _session.Acquisition.Start();

                // Get our image
                _session.Acquisition.GetImageAt(image, 0);

                //Stop, unconfigure, and close camera
                _session.Acquisition.Stop();
                _session.Acquisition.Unconfigure();
                _session.Close();
            }
            catch (ImaqdxException ex)
            {
                MessageBox.Show(ex.Message, "NI-IMAQdx Error");
            }
        }
Ejemplo n.º 19
0
 internal ImaqdxUInt32Attribute(ImaqdxSession session, ImaqdxAttributeInformation attributeInfo)
     : base(session, attributeInfo)
 {
     _numericAttribute = new ImaqdxNumericAttribute <uint>(this);
 }
Ejemplo n.º 20
0
 internal ImaqdxDoubleAttribute(ImaqdxSession session, ImaqdxAttributeInformation attributeInfo)
     : base(session, attributeInfo)
 {
     _numericAttribute = new ImaqdxNumericAttribute <double>(this);
 }
Ejemplo n.º 21
0
 internal ImaqdxInt64Attribute(ImaqdxSession session, ImaqdxAttributeInformation attributeInfo)
     : base(session, attributeInfo)
 {
     _numericAttribute = new ImaqdxNumericAttribute <long>(this);
 }
Ejemplo n.º 22
0
 public FlyTool(ImaqdxSession _session)
 {
     this._session = _session;
 }
Ejemplo n.º 23
0
 internal ImaqdxAttribute(ImaqdxSession session, ImaqdxAttributeInformation attributeInfo)
 {
     _session = session;
     _name    = attributeInfo.Name;
     _type    = attributeInfo.Type;
 }
Ejemplo n.º 24
0
 internal ImaqdxCommandAttribute(ImaqdxSession session, ImaqdxAttributeInformation attributeInfo)
     : base(session, attributeInfo)
 {
 }
Ejemplo n.º 25
0
 private void initializeCamera()
 {
     try
     {
         imaqdxSession = new ImaqdxSession(cameraName);
     }
     catch (ImaqdxException e)
     {
         MessageBox.Show(e.Message);
         throw new ImaqdxException();
     }
 }