Example #1
0
 public static void SetReceivedFunction <T>()
 {
     if (ReceivedFunction == null ||
         (ReceivedFunction != null && ReceivedFunction.GetType().Name != typeof(T).Name))
     {
         ReceivedFunction = (ISerialPortDataReceived)Activator.CreateInstance <T>();
     }
     OverTimeManager.Start();
 }
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            OverTimeManager.Stop();
            try
            {
                if (param.Command.DCommand == PortEnums.DCommands.Default)
                {
                    if (param.DistanceDeviceParam != null && param.DistanceDeviceParam.Command == PortEnums.DistanceCommands.InitializeDevice)
                    {
                        if (param.DistanceDeviceParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
                        {
                            if (!EncryptNewDevice)
                            {
                                byte[] bys = PortAgreement.DistanceCardEncryption(NewPwd);
                                SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, bys);
                                EncryptNewDevice = true;
                                OverTimeManager.Start();
                                return;
                            }
                            else
                            {
                                ViewCallFunction.ViewEncryptMessage("定距卡加密结束。");
                                ViewCallFunction.ViewEncryptOver();
                            }
                        }
                        else
                        {
                            ViewCallFunction.ViewEncryptMessage("定距卡加密失败,请重新操作。");
                            ViewCallFunction.ViewEncryptOver();
                        }
                        EncryptNewDevice = false;
                    }
                    else if (param.DistanceCardParam != null && param.DistanceCardParam.Command == PortEnums.DistanceCommands.ModifyAllCardPwd)
                    {
                        if (param.DistanceCardParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
                        {
                            DistanceCardParameter distanceParam = param.DistanceCardParam;
                            string msg = $"定距卡:{distanceParam.CardNumber} 密码(口令)加密{(distanceParam.CardTypeParameter.CardType != PortEnums.CardTypes.PwdError ? "成功" : "失败")}";
                            ViewCallFunction.ViewEncryptMessage(msg);
                        }
                        else
                        {
                            DeviceNewPwd();
                        }
                        OverTimeManager.Start();
                    }
                }
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewEncryptOver();
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
Example #3
0
 public void DataReceived(byte[] by)
 {
     try
     {
         PortDataParameter param = DataParsing.Parsing(by);
         if (param.DistanceCardParam == null)
         {
             return;
         }
         OverTimeManager.Stop();
         if (param.DistanceCardParam.Command == PortEnums.DistanceCommands.ReadACard)
         {
             if (param.DistanceCardParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
             {
                 int state = CardManager.LossLists[0].CardReportLoss;
                 by = DistanceLoss.PersonnelLoseOrRecovery(CardManager.LossLists, state == 1 ? 1 : 2);
                 bool ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                 if (!ret)
                 {
                     ViewCallFunction.ViewCloseLoading();
                 }
                 else
                 {
                     OverTimeManager.Start();
                 }
             }
             else
             {
                 ViewCallFunction.ViewCloseLoading();
                 ViewCallFunction.ViewMessage("未能获取到挂失卡,请重新操作。", "2");
             }
         }
         else if (param.DistanceCardParam.Command == PortEnums.DistanceCommands.WriteACard)
         {
             if (param.DistanceCardParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
             {
                 foreach (CardInfo item in CardManager.LossLists)
                 {
                     item.CardReportLoss = item.CardReportLoss == 1 ? 0 : 1;
                 }
                 CardManager.Update(CardManager.LossLists.ToArray());
                 CardManager.LossLists = null;
                 ViewCallFunction.ViewLoseOver();
             }
             else
             {
                 ViewCallFunction.ViewCloseLoading();
             }
         }
     }
     catch (Exception ex)
     {
         Log4Helper.ErrorInfo(ex.Message, ex);
         ViewCallFunction.ViewCloseLoading();
         ViewCallFunction.ViewAlert(ex.Message);
     }
 }
Example #4
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            if (param.DistanceCardParam == null)
            {
                return;
            }
            if (param.DistanceCardParam.Command == PortEnums.DistanceCommands.ReadAllCard)
            {
                OverTimeManager.Stop();
                if (param.DistanceCardParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.End)
                {
                    ViewCallFunction.ViewCloseLoading();
                    return;
                }
                try
                {
                    bool exists = CardManager.CardInfos.Exists(e => e.CardNumber == param.DistanceCardParam.CardNumber);
                    if (exists)
                    {
                        return;
                    }
                    CardInfo info = CardManager.GetCardInfo(param.DistanceCardParam.CardNumber);
                    if (info == null)
                    {
                        info          = new CardInfo();
                        info.CardTime = DateTime.Now;
                    }
                    info.CardNumber   = param.DistanceCardParam.CardNumber;
                    info.CardType     = (int)param.DistanceCardParam.CardTypeParameter.CardType;
                    info.CardLock     = param.DistanceCardParam.CardTypeParameter.CardLock;
                    info.CardDistance = param.DistanceCardParam.CardTypeParameter.Distance;
                    info.Electricity  = param.DistanceCardParam.CardTypeParameter.Electricity;
                    if (info.CardType <= 3)
                    {
                        if (param.DistanceCardParam.FunctionByteParam != null)
                        {
                            if (info.Id > 0 && info.CardType < 3)
                            {
                                info.CardType = (int)param.DistanceCardParam.FunctionByteParam.RegistrationType;
                                if (info.CardType == 1)//人卡或组合卡
                                {
                                    info.ParkingRestrictions = param.DistanceCardParam.FunctionByteParam.ParkingRestrictions;
                                }
                            }
                            info.CardReportLoss = param.DistanceCardParam.FunctionByteParam.Loss;
                            info.ViceCardCount  = param.DistanceCardParam.FunctionByteParam.ViceCardCount;
                            info.Synchronous    = param.DistanceCardParam.FunctionByteParam.Synchronous;
                            info.InOutState     = param.DistanceCardParam.FunctionByteParam.InOutState;
                            info.CardCount      = param.DistanceCardParam.Count;
                        }
                    }
                    CardManager.CardInfos.Add(info);
                    ViewCallFunction.ViewDisplayReadCardInfo(info);
                }
                catch (Exception ex)
                {
                    Log4Helper.ErrorInfo(ex.Message, ex);
                }
                finally
                {
                    OverTimeManager.Start();
                }
            }
        }
Example #5
0
 private void EncryptNewPwd()
 {
     byte[] bys = PortAgreement.IcCardEncryption(Pwd);
     SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, bys);
     OverTimeManager.Start();
 }