Question

This is my first time working with an RFID motorola handheld device. The point of this application is to be able to take pictures with the device and save each picture the "trigger" is pulled. For some reason, I can only get the StartCapture() method to fire once thus only saving one picture and the method will not fire again will application is running. Any advice from someone who has experience with the Symbol.Imaging2 class library would be great.

    using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using Symbol;
using Symbol.ResourceCoordination;
using Symbol.RFID3;
using Symbol.Imaging2;


namespace TagReaderMobile
{
    public partial class Form1 : Form
    {
       // private RFIDReader _reader = null;
        private Trigger _trigger = null;
        private Imaging2 Imager = new Imaging2(); //initializes available camera
        private int fileNumber = 0;
        //private TabPage _openTagPage = null;

        public Form1()
        {
            InitializeComponent();
        }

        public Trigger Trigger
        {
            get
            {
                if (_trigger == null)
                {
                    _trigger =
                        new Trigger(new TriggerDevice(TriggerID.ALL_TRIGGERS, new ArrayList()));
                }

                return _trigger;
            }
        }

        private void InitializeAllTriggers()
        {
            if (!Trigger.IsStage2InUse)
            {
                Trigger.Stage2Notify += (_trigger_Stage2Notify);
            }
        }

        private void DisconnectTriggers()
        {
            if (_trigger != null)
            {
                _trigger.Dispose();
                _trigger = null;
            }
        }

        private void _trigger_Stage2Notify(object sender, TriggerEventArgs e)
        {
            if (e.NewState == TriggerState.STAGE2)
            {
                UpdateTriggerState(true);
            }
            else
            {
                UpdateTriggerState(false);
            }
        }

        private void UpdateTriggerState(bool triggerPulled)
        {
            var workToDo = new Func<bool, bool>(x =>
            {
                if (x)
                {
                    picTrigger1.Image = Properties.Resources.go;
                    picTrigger2.Image = Properties.Resources.go;
                }
                else
                {
                    picTrigger1.Image = Properties.Resources.stop;
                    picTrigger2.Image = Properties.Resources.stop;
                }
                return true;
            });

            if (InvokeRequired)
            {
                Invoke(workToDo, new object[] { triggerPulled });
            }
            else
            {
                workToDo(triggerPulled);
            }
        }

        private void Form1_Activated(object sender, EventArgs e)
        {
            UpdateTriggerState(false);
            //InitializeAllTriggers();

            ConfigureImager();
        }

        private void Form1_Deactivate(object sender, EventArgs e)
        {
            DisconnectTriggers();

        }

        private void ConfigureImager() // Image Capture Method
        {
            if (Imager != null)
            {
                Imager.Enable();
                Imager.StartAcquisition(pictureBox1);
                Imager.OnStatus += new Imaging2.OnStatusHandler(Image_OnStatus);
                Imager.OnCapture += new Imaging2.OnCaptureHandler(Image_OnCapture);

                StartCapture();

            }
        }

        private void StartCapture()
        {
            Imager.Config.Activators.FreezeTimeout = 3000;
            Imager.Config.Activators.Triggers = new[] { Triggers.ALLTRIGGERS };
            IMGResults result = Imager.CaptureImage();
        }

        void Image_OnCapture(ImageData imageData)
        {
            Imager.Enable();
            Debug.WriteLine("Path=" + Program.AppPath);

            System.Drawing.Image bitmap = imageData.GetBitmap();
            bitmap.Save(@"\My Documents\My Pictures\Image" + fileNumber + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            try
            {
                bitmap.Save(@"\My Documents\My Pictures\Image" + fileNumber + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch(Exception e)
            {
                Debug.WriteLine(e.Message); 
                Debug.WriteLine(e.StackTrace);
            }
            fileNumber++;
            Debug.WriteLine("OnCapture: " + imageData.Results.ToString());
        }

        private void Image_OnStatus(StatusData statusData)
        {
            Debug.WriteLine("Status: " + statusData.EventType);
        }
    }
}
Was it helpful?

Solution

Because when your trigger is fired, ConfigureImager is called. On the first time, the Imager object is created and StartCapture called. On the second time, the Imager already exists, so it is not created, but StartCapture is also not called because of the if block.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top