0

这是我第一次使用 RFID 摩托罗拉手持设备。这个应用程序的重点是能够使用设备拍照并保存每张“触发器”被拉动的照片。出于某种原因,我只能让 StartCapture() 方法触发一次,因此只能保存一张图片,并且该方法不会在应用程序运行时再次触发。任何对 Symbol.Imaging2 类库有经验的人的建议都会很棒。

    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);
        }
    }
}
4

1 回答 1

1

因为当你的触发器被触发时,ConfigureImager被调用。第一次,Imager对象被创建和StartCapture调用。第二次,Imager已经存在,所以它没有被创建,但StartCapture也没有因为if块而被调用。

于 2012-05-16T21:26:45.670 回答