Beispiel #1
0
 /// <summary>
 /// 向读卡器请求命令,并取得返回包
 /// </summary>
 /// <param name="cmd">请求的命令</param>
 /// <param name="data">请求中包含的数据</param>
 /// <returns></returns>
 public YCTPacket Request(YCTCommandType cmd, byte[] data)
 {
     lock (_PortLocker)
     {
         byte[] request = CreateRequest(cmd, data);
         if (Log)
         {
             Ralid.GeneralLibrary.LOG.FileLog.Log("羊城通读卡器", "发送数据: " + HexStringConverter.HexToString(request, " "));
         }
         _Port.OnDataArrivedEvent -= _Port_OnDataArrivedEvent;
         _buffer.Clear();
         _Responsed.Reset();
         _Response = null;
         _Port.OnDataArrivedEvent += _Port_OnDataArrivedEvent;
         _Port.SendData(request);
         if (_Responsed.WaitOne(5000))
         {
             if (_Response != null && _Response.CheckCRC() && _Response.Command == (byte)cmd)
             {
                 _LastError = _Response.Status;
                 return(_Response);
             }
         }
     }
     _LastError = -1;
     return(null);
 }
Beispiel #2
0
        private void _Port_OnDataArrivedEvent(object sender, byte[] data)
        {
            _buffer.Write(data);
            YCTPacket p = _buffer.Read();

            if (p != null)
            {
                _Response = p;
                _Responsed.Set();
                if (Log)
                {
                    Ralid.GeneralLibrary.LOG.FileLog.Log("羊城通读卡器", "接收数据: " + HexStringConverter.HexToString(p.AllBytes, " "));
                }
            }
        }
Beispiel #3
0
 private YCTPaymentInfo GetPaymentInfoFromCPU(YCTPacket packet)
 {
     byte[] data = packet.Data; //86字节
     if (data == null || data.Length == 0)
     {
         return(null);
     }
     try
     {
         YCTPaymentInfo payment = new YCTPaymentInfo();
         payment.本次交易设备编号   = HexStringConverter.HexToString(Slice(data, 0, 6), string.Empty);
         payment.终端交易流水号    = BEBinaryConverter.BytesToInt(Slice(data, 6, 4));
         payment.本次交易日期时间   = DateTime.ParseExact(HexStringConverter.HexToString(Slice(data, 10, 7), string.Empty), "yyyyMMddHHmmss", null);
         payment.逻辑卡号       = HexStringConverter.HexToString(Slice(data, 17, 8), string.Empty);
         payment.物理卡号       = HexStringConverter.HexToString(Slice(data, 25, 8), string.Empty);
         payment.交易金额       = BEBinaryConverter.BytesToInt(Slice(data, 33, 4));
         payment.票价         = BEBinaryConverter.BytesToInt(Slice(data, 37, 4));
         payment.本次余额       = BEBinaryConverter.BytesToInt(Slice(data, 41, 4));
         payment.交易类型       = Slice(data, 45, 1)[0];
         payment.附加交易类型     = Slice(data, 46, 1)[0];
         payment.票卡充值交易计数   = BEBinaryConverter.BytesToInt(Slice(data, 47, 2));
         payment.票卡消费交易计数   = BEBinaryConverter.BytesToInt(Slice(data, 49, 2));
         payment.累计门槛月份     = HexStringConverter.HexToString(Slice(data, 51, 2), string.Empty);
         payment.公交门槛计数     = Slice(data, 53, 1)[0];
         payment.地铁门槛计数     = Slice(data, 54, 1)[0];
         payment.联乘门槛计数     = Slice(data, 55, 1)[0];
         payment.本次交易入口设备编号 = HexStringConverter.HexToString(Slice(data, 56, 6), string.Empty);
         payment.本次交易入口日期时间 = HexStringConverter.HexToString(Slice(data, 62, 7), string.Empty);
         payment.次交易设备编号    = HexStringConverter.HexToString(Slice(data, 69, 6), string.Empty);
         payment.次交易日期时间    = HexStringConverter.HexToString(Slice(data, 75, 4), string.Empty);
         payment.区域代码       = HexStringConverter.HexToString(Slice(data, 79, 1), string.Empty);
         payment.区域卡类型      = HexStringConverter.HexToString(Slice(data, 80, 2), string.Empty);
         payment.区域子码       = HexStringConverter.HexToString(Slice(data, 82, 1), string.Empty);
         payment.交易认证码      = HexStringConverter.HexToString(Slice(data, 83, 4), string.Empty);
         return(payment);
     }
     catch (Exception ex)
     {
         Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
     }
     return(null);
 }
Beispiel #4
0
 private YCTPaymentInfo GetPaymentInfoFromM1(YCTPacket packet)
 {
     byte[] data = packet.Data; //73个字节
     if (data == null || data.Length == 0)
     {
         return(null);
     }
     try
     {
         YCTPaymentInfo payment = new YCTPaymentInfo();
         payment.终端交易流水号    = BEBinaryConverter.BytesToInt(Slice(data, 0, 4));
         payment.逻辑卡号       = HexStringConverter.HexToString(Slice(data, 4, 8), string.Empty);
         payment.物理卡号       = HexStringConverter.HexToString(Slice(data, 12, 4), string.Empty);
         payment.次交易设备编号    = HexStringConverter.HexToString(Slice(data, 16, 4), string.Empty);
         payment.次交易日期时间    = HexStringConverter.HexToString(Slice(data, 20, 7), string.Empty);
         payment.本次交易设备编号   = HexStringConverter.HexToString(Slice(data, 27, 4), string.Empty);
         payment.本次交易日期时间   = DateTime.ParseExact(HexStringConverter.HexToString(Slice(data, 31, 7), string.Empty), "yyyyMMddHHmmss", null);
         payment.交易金额       = BEBinaryConverter.BytesToInt(Slice(data, 38, 4));
         payment.本次余额       = BEBinaryConverter.BytesToInt(Slice(data, 42, 4));
         payment.票价         = BEBinaryConverter.BytesToInt(Slice(data, 46, 4));
         payment.交易类型       = Slice(data, 50, 1)[0];
         payment.票卡消费交易计数   = BEBinaryConverter.BytesToInt(Slice(data, 51, 2));
         payment.累计门槛月份     = HexStringConverter.HexToString(Slice(data, 53, 2), string.Empty);
         payment.公交门槛计数     = Slice(data, 55, 1)[0];
         payment.地铁门槛计数     = Slice(data, 56, 1)[0];
         payment.联乘门槛计数     = Slice(data, 57, 1)[0];
         payment.本次交易入口设备编号 = HexStringConverter.HexToString(Slice(data, 58, 4), string.Empty);
         payment.本次交易入口日期时间 = HexStringConverter.HexToString(Slice(data, 62, 7), string.Empty);
         payment.交易认证码      = HexStringConverter.HexToString(Slice(data, 69, 4), string.Empty);
         return(payment);
     }
     catch (Exception ex)
     {
         Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
     }
     return(null);
 }