示例#1
0
 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);
     }
 }
示例#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);
            }
        }