2014-01-30 3 views
0

회사의 카페테리아 소비를 제어하는 ​​응용 프로그램을 개발 중입니다. 기본적으로 각 직원은 바코드가있는 배지 ID를 가지고 있으며 매일 무료 식사를 제공받을 자격이 있습니다. 응용 프로그램은 배지를 스캔하고 각 직원의 식사를 기록합니다. 통합 스캐너가 있고 Windows CE에서 실행되는 Motorola MK4000 장치에서 실행됩니다.바코드 스캐너 문제 (Windows CE)

기기 스캐너에 문제가 있습니다. 나는 그것을 실행하고 잘 스캔 할 수 있지만 몇 분 동안 유휴 상태를 유지하면 "대기 중"상태가되고 레이저는 꺼지고 다시 켜지지 않습니다. 상태를 모니터링하고 상태가 변경 될 때 새 읽기를 시작하려고 시도했지만 거짓 검색을 무기한으로 계속 읽습니다.

너희들 내가 잘못하고있는 일을 알아낼 수있게 도와 줄 수 있니?

스캐너 기능에 사용하는 클래스입니다. 그것은 나에 의해 개발 된 것이 아니지만, 같은 장치에서 다른 응용 프로그램을 사용하기 시작했습니다 (주로 오류 메시지에 대해 약간 변경했습니다).

using System; 
using System.Linq; 
using System.Collections.Generic; 
using System.Text; 
using System.Windows.Forms; 

namespace MK4000 
{ 
class BarCode 
{ 
    #region Fields 

    private Symbol.Barcode.Reader myReader = null; 
    private Symbol.Barcode.ReaderData myReaderData = null; 
    private System.EventHandler myReadNotifyHandler = null; 
    private System.EventHandler myStatusNotifyHandler = null; 

    #endregion Fields 

    #region Properties 

    /// <summary> 
    /// Provides the access to the Symbol.Barcode.Reader reference. 
    /// The user can use this reference for his additional Reader - related operations. 
    /// </summary> 
    public Symbol.Barcode.Reader Reader 
    { 
     get 
     { 
      return myReader; 
     } 
    } 

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

    #endregion Properties 

    #region Methods 

    /// <summary> 
    /// Attach a ReadNotify handler. 
    /// </summary> 
    public void AttachReadNotify(System.EventHandler ReadNotifyHandler) 
    { 
     // If we have a reader 
     if (myReader != null) 
     { 
      // Attach the read notification handler. 
      myReader.ReadNotify += ReadNotifyHandler; 
      myReadNotifyHandler = ReadNotifyHandler; 
     } 
    } 

    /// <summary> 
    /// Attach a StatusNotify handler. 
    /// </summary> 
    public void AttachStatusNotify(System.EventHandler StatusNotifyHandler) 
    { 
     // If we have a reader 
     if (myReader != null) 
     { 
      // Attach status notification handler. 
      myReader.StatusNotify += StatusNotifyHandler; 
      myStatusNotifyHandler = StatusNotifyHandler; 
     } 
    } 

    /// <summary> 
    /// Detach the ReadNotify handler. 
    /// </summary> 
    public void DetachReadNotify() 
    { 
     if ((myReader != null) && (myReadNotifyHandler != null)) 
     { 
      // Detach the read notification handler. 
      myReader.ReadNotify -= myReadNotifyHandler; 
      myReadNotifyHandler = null; 
     } 
    } 

    /// <summary> 
    /// Detach a StatusNotify handler. 
    /// </summary> 
    public void DetachStatusNotify() 
    { 
     // If we have a reader registered for receiving the status notifications 
     if ((myReader != null) && (myStatusNotifyHandler != null)) 
     { 
      // Detach the status notification handler. 
      myReader.StatusNotify -= myStatusNotifyHandler; 
      myStatusNotifyHandler = null; 
     } 
    } 

    /// <summary> 
    /// Initialize the reader. 
    /// </summary> 
    public bool InitReader() 
    { 
     // If the reader is already initialized then fail the initialization. 
     if (myReader != null) 
     { 
      return false; 
     } 
     else // Else initialize the reader. 
     { 
      try 
      { 
       // Get the device selected by the user. 
       Symbol.Generic.Device MyDevice = 
        Symbol.StandardForms.SelectDevice.Select(
        Symbol.Barcode.Device.Title, 
        Symbol.Barcode.Device.AvailableDevices); 

       if (MyDevice == null) 
       { 
        MessageBox.Show(ErrorMessage); 
        return false; 
       } 

       // Create the reader, based on selected device. 
       myReader = new Symbol.Barcode.Reader(MyDevice); 

       // Create the reader data. 
       myReaderData = new Symbol.Barcode.ReaderData(
        Symbol.Barcode.ReaderDataTypes.Text, 
        Symbol.Barcode.ReaderDataLengths.MaximumLabel); 

       // Enable the Reader. 
       myReader.Actions.Enable(); 

       // In this sample, we are setting the aim type to trigger. 
       switch (myReader.ReaderParameters.ReaderType) 
       { 
        case Symbol.Barcode.READER_TYPE.READER_TYPE_IMAGER: 
         myReader.ReaderParameters.ReaderSpecific.ImagerSpecific.AimType = Symbol.Barcode.AIM_TYPE.AIM_TYPE_TRIGGER; 
         //myReader.Parameters.Feedback.Success.BeepTime = 0; 
         break; 
        case Symbol.Barcode.READER_TYPE.READER_TYPE_LASER: 
         myReader.ReaderParameters.ReaderSpecific.LaserSpecific.AimType = Symbol.Barcode.AIM_TYPE.AIM_TYPE_TRIGGER; 
         break; 
        case Symbol.Barcode.READER_TYPE.READER_TYPE_CONTACT: 
         // AimType is not supported by the contact readers. 
         break; 
       } 
       myReader.Actions.SetParameters(); 

      } 

      catch (Symbol.Exceptions.OperationFailureException ex) 
      { 
       MessageBox.Show(ex.Message); 

       return false; 
      } 
      catch (Symbol.Exceptions.InvalidRequestException ex) 
      { 
       MessageBox.Show(ex.Message); 

       return false; 
      } 
      catch (Symbol.Exceptions.InvalidIndexerException ex) 
      { 
       MessageBox.Show(ex.Message); 

       return false; 
      }; 

      return true; 
     } 
    } 

    /// <summary> 
    /// Start a read on the reader. 
    /// </summary> 
    public void StartRead(bool toggleSoftTrigger) 
    { 
     // If we have both a reader and a reader data 
     if ((myReader != null) && 
      (myReaderData != null)) 

      try 
      { 
       if (!myReaderData.IsPending) 
       { 
        // Submit a read. 
        myReader.Actions.Read(myReaderData); 

        if (toggleSoftTrigger && myReader.Info.SoftTrigger == false) 
        { 
         myReader.Info.SoftTrigger = true; 
        } 
       } 
      } 

      catch (Symbol.Exceptions.OperationFailureException ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
      catch (Symbol.Exceptions.InvalidRequestException ex) 
      { 
       MessageBox.Show(ex.Message); 

      } 
      catch (Symbol.Exceptions.InvalidIndexerException ex) 
      { 
       MessageBox.Show(ex.Message); 

      }; 
    } 

    /// <summary> 
    /// Stop all reads on the reader. 
    /// </summary> 
    public void StopRead() 
    { 
     //If we have a reader 
     if (myReader != null) 
     { 
      try 
      { 
       // Flush (Cancel all pending reads). 
       if (myReader.Info.SoftTrigger == true) 
       { 
        myReader.Info.SoftTrigger = false; 
       } 
       myReader.Actions.Flush(); 
      } 

      catch (Symbol.Exceptions.OperationFailureException ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
      catch (Symbol.Exceptions.InvalidRequestException ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
      catch (Symbol.Exceptions.InvalidIndexerException ex) 
      { 
       MessageBox.Show(ex.Message); 
      }; 
     } 
    } 

    /// <summary> 
    /// Stop reading and disable/close the reader. 
    /// </summary> 
    public void TermReader() 
    { 
     // If we have a reader 
     if (myReader != null) 
     { 
      try 
      { 
       // stop all the notifications. 
       StopRead(); 

       //Detach all the notification handler if the user has not done it already. 
       DetachReadNotify(); 
       DetachStatusNotify(); 

       // Disable the reader. 
       myReader.Actions.Disable(); 

       // Free it up. 
       myReader.Dispose(); 

       // Make the reference null. 
       myReader = null; 
      } 

      catch (Symbol.Exceptions.OperationFailureException ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
      catch (Symbol.Exceptions.InvalidRequestException ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
      catch (Symbol.Exceptions.InvalidIndexerException ex) 
      { 
       MessageBox.Show(ex.Message); 
      }; 
     } 

     // After disposing the reader, dispose the reader data. 
     if (myReaderData != null) 
     { 
      try 
      { 
       // Free it up. 
       myReaderData.Dispose(); 

       // Make the reference null. 
       myReaderData = null; 
      } 

      catch (Symbol.Exceptions.OperationFailureException ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
      catch (Symbol.Exceptions.InvalidRequestException ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
      catch (Symbol.Exceptions.InvalidIndexerException ex) 
      { 
       MessageBox.Show(ex.Message); 
      }; 
     } 
    } 

    #endregion Methods 

} 
} 

그리고 이것은 실제 양식에 대한 코드입니다

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



} 
} 

이 여전히 진행중인 작품, 마음이, 그래서이없는 일부 기능은,하지만 난 스캐너 workingfull을 갖고 싶어 앞으로 나아 가기 전에. 어떤 도움이라도 대단히 감사하겠습니다. 감사합니다.

+0

먼저 Symbol에서 최신 버전의 바코드 SDK 및 OS 이미지를 가지고 있는지 확인하십시오. 최신 릴리스에서 수정 된 문제 일 수 있습니다. 그래도 도움이되지 않으면 StartRead(); StopRead(); 바코드 리더를 완전히 종료하고 닫은 다음 다시 초기화해야합니다. – PaulH

답변

0

좋아요, 스캐너가 Idle 상태와 Waiting 상태 사이를 전환하는 사이클에 들어가는 것을 알아 냈습니다. 이것이 내 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;