C# windows ce应用程序中的条形码扫描仪问题

C# windows ce应用程序中的条形码扫描仪问题,c#,windows-ce,barcode-scanner,motorola-emdk,C#,Windows Ce,Barcode Scanner,Motorola Emdk,我正在为我的公司开发一个控制自助餐厅消费的应用程序。基本上,每个员工都有一个带有条形码的徽章id,他们每天都有权享受免费用餐。该应用程序将扫描徽章并记录每个员工的用餐情况。它将在摩托罗拉MK4000设备上运行,该设备具有集成扫描仪,并在Windows CE上运行 我的设备扫描仪有问题。我可以让它运行和扫描良好,但如果它保持空闲几分钟,它会进入“等待”状态,激光器关闭,不会重新启动。我尝试过监视状态,并在状态改变时启动新的读取,但它只是无限期地扫描错误读取 你们能帮我找出我做错了什么吗 这是我用于

我正在为我的公司开发一个控制自助餐厅消费的应用程序。基本上,每个员工都有一个带有条形码的徽章id,他们每天都有权享受免费用餐。该应用程序将扫描徽章并记录每个员工的用餐情况。它将在摩托罗拉MK4000设备上运行,该设备具有集成扫描仪,并在Windows CE上运行

我的设备扫描仪有问题。我可以让它运行和扫描良好,但如果它保持空闲几分钟,它会进入“等待”状态,激光器关闭,不会重新启动。我尝试过监视状态,并在状态改变时启动新的读取,但它只是无限期地扫描错误读取

你们能帮我找出我做错了什么吗

这是我用于扫描仪功能的类。它不是我开发的,但它开始用于同一设备上的其他应用程序(我对它做了一些更改,主要是错误消息)


请注意,这仍然是一项正在进行的工作,因此缺少一些功能,但我想在继续之前让扫描仪完全工作。非常感谢您的帮助。

好的,我发现扫描仪进入了一个在空闲和等待状态之间切换的循环,这就是为什么我的StatusNotify事件处理程序反复打开和关闭扫描仪激光器的原因

我通过保存以前的状态解决了这个问题,并且只有当以前的状态不是这两种状态之一时才重新启动扫描仪

case Symbol.Barcode.States.WAITING:
                if (lastScannerStatus != "WAITING" && lastScannerStatus != "INIT" && lastScannerStatus != "IDLE")
                {
                    this.myScanner.StopRead();
                    this.myScanner.StartRead(true);
                }
                this.statusBar1.Text = "Waiting- Scan ID Barcode                    " + MacAddress + " | " + strIPAddress + " | " + version;

                break;

首先确保您拥有最新版本的条形码SDK和来自Symbol的操作系统映像。这可能是他们在新版本中修复的问题。如果这样做没有帮助,请尝试更换StartRead();StopRead();在等待状态下,完全终止并关闭条形码读取器,然后重新初始化。
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MK4000
{
public partial class Form1 : Form
{

    private bool isReaderInitiated;        
    private BarCode myScanner;
    private EventHandler myStatusNotifyHandler = null;
    private EventHandler myReadNotifyHandler = null;
    private String MacAddress = "00-00-00-00-00-00";
    private String strIPAddress = "000.000.000.000";
    private String version = "0.0.0.1";
    public static int TaskbarHeight = Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height;
    private int counter = 0;
    private int itemLimit = 10;

    public String ErrorMessage
    {
        get
        {
            return "Error";
        }
    }

    public Form1()
    {
        InitializeComponent();

        this.Width = Screen.PrimaryScreen.Bounds.Width;
        this.Height = Screen.PrimaryScreen.Bounds.Height - TaskbarHeight;
        this.FormBorderStyle = FormBorderStyle.None;
        this.ControlBox = false;
        this.MinimizeBox = false;
        this.EmpID.Visible = false;
        this.EmpName.Visible = false;
        this.messageLabel.Visible = false;
        this.lblCounter.Text = counter.ToString();
        this.lblCounter.Visible = false;
        this.statusBar1.Text = "Initializing.. Reticulating Splines            " + MacAddress + " | " + strIPAddress + " | " + version;
        this.listView1.View = View.Details;
        this.listView1.Columns.Add("EmployeeID", 150, HorizontalAlignment.Left);
        this.listView1.Columns.Add("EmployeeName", 330, HorizontalAlignment.Left);
        this.listView1.Columns.Add("Time", 250, HorizontalAlignment.Left);


        this.Closing += new CancelEventHandler(Form1_OnClosing);

        this.myScanner = new BarCode();
        this.isReaderInitiated = this.myScanner.InitReader();

        if (!(this.isReaderInitiated))// If the reader has not been initialized
        {
            // Display a message & exit the application.
            MessageBox.Show(ErrorMessage);
            Application.Exit();
        }
        else // If the reader has been initialized
        {
            // Attach a status natification handler.
            myScanner.AttachStatusNotify(myScanner_StatusNotify);
            // Start a read operation & attach a handler.
            myScanner.StartRead(true);
            myScanner.AttachReadNotify(myScanner_ReadNotify);
        }
    }

    private void myScanner_ReadNotify(object Sender, EventArgs e)
    {

        // Get ReaderData
        Symbol.Barcode.ReaderData TheReaderData = this.myScanner.Reader.GetNextReaderData();
        processData(TheReaderData.ToString());


        this.myScanner.StopRead();

        System.Threading.Thread.Sleep(1000);

        this.myScanner.StartRead(true);

    }

    private void processData(string readerData)
    {
        string EmployeeName = "";
        string EmployeeID = readerData;

        hideMessage();


        //This will query the employee database and proceed if employee exists, right now i just give it a random name
        EmployeeName = "John Doe";

        if (EmployeeName != "")
        {
            addToList(EmployeeID, EmployeeName);
            counter += 1;
            this.lblCounter.Text = counter.ToString();
            this.EmpID.Visible = true
            this.EmpName.Visible = true
            this.lblCounter.Visible = true;
            showMessage("Thank You!", System.Drawing.Color.LimeGreen);

        }

    }

    private void showMessage(string messageText, System.Drawing.Color messageColor)
    {
        this.messageLabel.Text = messageText;
        this.messageLabel.BackColor = messageColor;
        this.messageLabel.Visible = true;

    }

    private void hideMessage()
    {
        this.messageLabel.Text = "";
        this.messageLabel.BackColor = System.Drawing.Color.Black;
        this.messageLabel.Visible = false;
    }

    private void addToList(string EmployeeID, string EmployeeName)
    {
        if (this.listView1.Items.Count >= itemLimit)
        {
            this.listView1.Items.RemoveAt(0);
        }
        ListViewItem item = new ListViewItem(EmployeeID);
        //item.Text = EmployeeID;
        item.SubItems.Add(EmployeeName);
        item.SubItems.Add(DateTime.Now.ToString());

        this.listView1.Items.Add(item);
        this.listView1.Refresh();    
    }

    private void myScanner_StatusNotify(object Sender, EventArgs e)
    {
        // Get ReaderData
        Symbol.Barcode.BarcodeStatus TheStatusData = this.myScanner.Reader.GetNextStatus();

        switch (TheStatusData.State)
        {
            case Symbol.Barcode.States.IDLE:
                this.statusBar1.Text = "Idle - Scan ID Barcode                      " + MacAddress + " | " + strIPAddress + " | " + version;
                break;
            case Symbol.Barcode.States.READY:
                this.statusBar1.Text = "Ready - Scan ID Barcode                     " + MacAddress + " | " + strIPAddress + " | " + version;
                break;                
            case Symbol.Barcode.States.WAITING:
                //this.myScanner.StopRead();
                //this.myScanner.StartRead(true);                    
                this.statusBar1.Text = "Waiting- Scan ID Barcode                    " + MacAddress + " | " + strIPAddress + " | " + version;
                break;
            default:
                this.statusBar1.Text = TheStatusData.Text + "                     " + MacAddress + " | " + strIPAddress + " | " + version;
                break;
        }
    }

    private void Form1_OnClosing(object Sender, EventArgs e)
    {
        if (isReaderInitiated)
        {
            myScanner.DetachReadNotify();
            myScanner.DetachStatusNotify();
            myScanner.TermReader();
        }
    }

    private void pictureBox1_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void pictureBox2_Click(object sender, EventArgs e)
    {
        this.myScanner.StopRead();
        this.myScanner.StartRead(true); 
    }



}
}
case Symbol.Barcode.States.WAITING:
                if (lastScannerStatus != "WAITING" && lastScannerStatus != "INIT" && lastScannerStatus != "IDLE")
                {
                    this.myScanner.StopRead();
                    this.myScanner.StartRead(true);
                }
                this.statusBar1.Text = "Waiting- Scan ID Barcode                    " + MacAddress + " | " + strIPAddress + " | " + version;

                break;