Ejemplo n.º 1
0
 /// <summary>
 /// 条形码事件委托
 /// </summary>
 /// <param name="sender">事件发送者</param>
 /// <param name="e">事件内容</param>
 void BarCodeDelegate(object sender, BarCodeEventArgs e)
 {
     if (BarCodeHandle != null)
     {
         BarCodeHandle(sender, e);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 一维码事件回调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnBarCode(object sender, BarCodeEventArgs e)
        {
            // 1.非有效条码信息,回调图像数据
            // 2.条码数量大于1
            if (e.Result.Code == string.Empty)
            {
                if (BarCodeHandle != null)
                {
                    BarCodeHandle(this, e);
                }
                return;
            }

            if (Interlocked.Read(ref _bBarCodeNotifyFlag) == 1)
            {
                return;
            }

            // 判断是否为重复条码数据
            if (_BarcodeCache.IsIn(e.Result.Code))
            {
                BarcodeSustaining.Stop();
                long t = BarcodeSustaining.ElapsedMilliseconds;


                if (t <= MvBarCode.MvBarCodeGlobalVar.BarcodeValidTime)
                {
                    BarcodeSustaining.Start();
                    return;
                }
            }

            BarcodeSustaining.Reset();
            BarcodeSustaining.Start();

            // 条码事件,直接回调
            if (BarCodeHandle != null)
            {
                //MvBarCode.MvBarCodeGlobalVar.Log.InfoFormat("DeviceLayer读取到条码:{0}",e.Result.Code);
                //读条形码
                BarCodeHandle(this, e);
            }

            // 记录条码数据信息
            if (Interlocked.CompareExchange(ref _bBarCodeNotifyFlag, 1, 0) == 0)
            {
                // 添加条码到缓冲中
                _BarcodeCache.Push(e.Result.Code);

                // 记录绑定标识
                Interlocked.Exchange(ref _bBinding, 1);

                // 记录一维码信息
                _BarCodeInfo = e.Result;

                // 检测到一维码后开始获取称数据
                if (_Scale != null)
                {
                    _Scale.AsyncPost(e.Result.Code);

                    // 启动重量检测超时定时器
                }
                else
                {
                    Interlocked.CompareExchange(ref _bBarCodeNotifyFlag, 0, 1);
                }
            }
        }