示例#1
0
 /// <summary>
 /// 定时器到期的事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void timer_Tick(object sender, EventArgs e)
 {
     //约定条码最少5位
     if (_scanCode.Length >= 5)
     {
         _scanCode = _scanCode.Trim((char)13);
         //由于读卡器和扫描器原理一样,都是模拟USB键盘,所以这里可能收到的是读卡器的键盘消息
         //读卡器的卡号规律比较明显,所以很容易刨除
         if (!CardReader.IsCardCode(_scanCode))
         {
             _timer.Stop();
             OnScannerRead(_scanCode);
         }
     }
     _scanCode = "";
     _timer.Start();
 }
        /// <summary>
        /// 读卡构造函数
        /// </summary>
        /// <param name="type"></param>
        public DeviceReaderDialog(DeviceType type = DeviceType.Card)
        {
            InitializeComponent();
            //TODO: 硬件 接口没有做好之前先能手填
            this.Readonly = false;

            if (type == DeviceType.Card)
            {
                this._cardReader           = new CardReader(this);
                this._cardReader.CardRead += new CardReadEventHandler(_cardReader_CardRead);
            }
            else if (type == DeviceType.UsbScanner)
            {
                this._usbScanner              = new USBScanner(this);
                this._usbScanner.ScannerRead += new ScannerReadEventHandler(Scanner_ScannerRead);
            }
            else if (type == DeviceType.ComScanner)
            {
                this._comScanner              = new COMScanner("COM3");
                this._comScanner.ScannerRead += new ScannerReadEventHandler(Scanner_ScannerRead);
            }
        }