public bool DoPay(CancellationToken token, POSDevicePayRequest request, out POSDevicePayResponse response, out string msg)
 {
     msg      = "";
     response = null;
     try
     {
         // return CallDevice(token, request, out response, out msg);
         SerialPort connection = NewLandPOSDeviceConnectTool.OpenSerialPort(token,
                                                                            new SerialPortRequest()
         {
             ComPort  = Global.MachineSettings.DevicesSettingsConfiguration.POSCOM,
             BaudRate = Global.MachineSettings.DevicesSettingsConfiguration.POSCOMRate
         });
         var cmd = NewLandPOSDeviceConnectTool.FormatDeviceCommand(request);
         NewLandPOSDeviceConnectTool.SendCommandToSerialPortConnection(token, connection, cmd);
         response = NewLandPOSDeviceConnectTool.ListenToSerialPortConnection(token, connection);
         msg      = string.Format("成功支付{0}元!", request.Amount);
         return(true);
     }
     catch (DeviceException ex)
     {
         msg = ex.Message;
         return(false);
     }
     catch (Exception ex)
     {
         msg = "连接设备失败!" + ex.Message;
         return(false);
     }
 }
Example #2
0
        public bool ReadCard(CancellationToken token, decimal amount, out Models.PosModels.StoreValueCardInfomactions info, out string msg)
        {
            info = null;
            msg  = "";
            var request = new POSDevicePayRequest()
            {
                MachineSn          = Global.MachineSettings.MachineInformations.MachineSn,
                Amount             = amount,
                CashierId          = PosViewModel.Current.UserCode,
                OldTransactionCode = "",
                OrderSn            = PosViewModel.Current.OrderSn,
                Type = TransactionType.ReadCard
            };
            POSDevicePayResponse response = null;

            try
            {
                // return CallDevice(token, request, out response, out msg);
                SerialPort connection = NewLandPOSDeviceConnectTool.OpenSerialPort(token,
                                                                                   new SerialPortRequest()
                {
                    ComPort  = Global.MachineSettings.DevicesSettingsConfiguration.POSCOM,
                    BaudRate = Global.MachineSettings.DevicesSettingsConfiguration.POSCOMRate
                });
                var cmd = NewLandPOSDeviceConnectTool.FormatDeviceCommand(request);
                NewLandPOSDeviceConnectTool.SendCommandToSerialPortConnection(token, connection, cmd);
                response = NewLandPOSDeviceConnectTool.ListenToSerialPortConnection(token, connection);
                info     = new StoreValueCardInfomactions()
                {
                    CardNo = response.CardNo.Trim(), Password = response.CardPin.Trim()
                };
                return(true);
            }
            catch (DeviceException ex)
            {
                msg = ex.Message;
                return(false);
            }
            catch (Exception ex)
            {
                msg = "连接设备是失败!失败信息:" + ex.Message;
                return(false);
            }
        }
Example #3
0
 /// <summary>
 /// 解析接收到的结果
 /// </summary>
 /// <param name="info">接收到的字符串数据</param>
 /// <returns>解析结果</returns>
 internal static POSDevicePayResponse FormatResponse(string info)
 {
     try
     {
         var returnStr     = info.ToString();
         var isSuccessCode = returnStr.Substring(2, 2);
         if (isSuccessCode == "00")
         {
             var response = new POSDevicePayResponse();
             var cardKind = returnStr.Substring(4, 1);
             if (cardKind == "0" || (cardKind == " "))
             {
                 var cardno = returnStr.Substring(252, 20).Trim();
                 response.CardNo = cardno;
             }
             else if (cardKind == "1")
             {
                 var cardno = returnStr.Substring(8, 244);
                 response.CardNo = cardno.Replace(" ", "").Replace("~", "");
             }
             response.CardPin             = returnStr.Substring(272, 12).Trim();
             response.CardName            = returnStr.Substring(284, 10).Trim();
             response.DeviceTranDate      = returnStr.Substring(294, 10).Trim();
             response.BankTransactionCode = returnStr.Substring(304, 12).Trim();
             response.TransactionCode     = returnStr.Substring(328, 6).Trim();
             response.AuthCode            = returnStr.Substring(334, 6).Trim();
             return(response);
         }
         else
         {
             throw new DeviceException("在设备上操作失败,或者设备取消了操作!");
         }
     }
     catch (DeviceException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw new DeviceException("解析失败,无效的设备回传数据!解析错误信息:" + ex.Message);
     }
 }