Ejemplo n.º 1
0
        /// <summary>
        /// 读标签响应函数
        /// </summary>
        /// <param name="buffer">标签数据?</param>
        /// <param name="type"></param>
        private void RfidOutPutHandler(byte[] buffer, AutoOutputType type)
        {
            try
            {
                //取得标签条码
                string readCode = Encoding.ASCII.GetString(buffer, 0, 12)
                                  .Replace("\r", "")//去除特殊字符
                                  .Replace("\n", "")
                                  .Replace("\0", "")
                                  .Replace("\t", "");

                if (string.IsNullOrEmpty(readCode))
                {
                    _log.Warn($"RFID读取到空标签!");
                    return;
                }
                if (!regex.IsMatch(readCode))
                {
                    _log.Warn($"条码格式不符:{readCode}");
                    return;
                }
                if (lastEngineCode != null && lastEngineCode == readCode)
                {
                    _log.Warn($"条码重复读取:{readCode}");
                    return;
                }
                _log.Info($"RFID读取到发动机条码:{readCode}");
                OnRfidReaded?.Invoke(readCode);
            }
            catch (Exception ex)
            {
                _log.Error("RFID读取标签出现异常", ex);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 读标签响应函数
 /// </summary>
 /// <param name="buffer">标签数据?</param>
 /// <param name="type"></param>
 private void RfidOutPutHandler(byte[] buffer, AutoOutputType type)
 {
     try
     {
         //取得标签条码
         string readCode = Encoding.ASCII.GetString(buffer, 0, buffer.Length)
                           .Replace("\r", "")//去除特殊字符
                           .Replace("\n", "")
                           .Replace("\0", "")
                           .Replace("\t", "");
         if (string.IsNullOrEmpty(readCode))
         {
             Log.Warning("RFID读取到空标签!");
         }
         else
         {
             lastEngineCode = readCode;
         }
         //Log.Information("{Name} RFID读取到发动机条码:{readCode}", rfid.Name,readCode);
         OnRfidReaded?.Invoke(readCode);
         var tag = new TagData(readCode);
         OnTagDataReaded?.Invoke(tag);
     }
     catch (Exception ex)
     {
         Log.Error(ex, "RFID读取标签出现异常");
     }
 }