Пример #1
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            if (param.DistanceCardParam == null)
            {
                return;
            }
            if (param.DistanceCardParam.Command == PortEnums.DistanceCommands.WriteACard)
            {
                OverTimeManager.Stop();
                if (IssueInfo == null)
                {
                    return;
                }
                try
                {
                    if (param.DistanceCardParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
                    {
                        IssueInfo.Id = CardManager.Insert(IssueInfo);
                    }
                }
                catch (Exception ex)
                {
                    Log4Helper.ErrorInfo(ex.Message, ex);
                }
                finally
                {
                    IssueInfo = null;
                }
            }
        }
Пример #2
0
        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);
            }
        }
Пример #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);
     }
 }
Пример #4
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            if (param.FunctionAddress == PortEnums.DealFunctions.ModularAndVoice)
            {
                //if (param.Command.MCommand == PortEnums.MCommands.SetModule || param.Command.MCommand == PortEnums.MCommands.TestCommunication)
                //{
                SettingOver = param.ModuleParam.Result;
                //}
            }
        }
Пример #5
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            OverTimeManager.Stop();
            try
            {
                if (param.FunctionAddress == PortEnums.DealFunctions.Ic)
                {
                    if (param.Command.ICommand == PortEnums.ICommands.EntryptIcDevice)
                    {
                        if (param.IcParam.Result)
                        {
                            EncryptNewPwd();
                        }
                        else
                        {
                            ViewCallFunction.ViewEncryptMessage("加密失败,请重新操作。");
                            ViewCallFunction.ViewEncryptOver();
                        }
                    }
                    else if (param.Command.ICommand == PortEnums.ICommands.EntryptIcCard)
                    {
                        if (param.IcParam != null)
                        {
                            string msg = $"IC 卡加密{(param.IcParam.Result ? "成功" : "失败")}";
                            ViewCallFunction.ViewEncryptMessage(msg);

                            Task.Factory.StartNew(() =>
                            {
                                for (int i = 0; i < 150; i++)
                                {
                                    Thread.Sleep(10);
                                    if (StopEncrypt)
                                    {
                                        StopEncrypt = false;
                                        OverEncrypt();
                                        return;
                                    }
                                }
                                EncryptNewPwd();
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
Пример #6
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            OverTimeManager.Stop();
            if (param.Command.HCommand == PortEnums.HCommands.NumberModify)
            {
                if (param.HostParam != null)
                {
                    ViewCallFunction.ViewDownloadOver(param.HostParam.Result);
                }
            }
        }
Пример #7
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            OverTimeManager.Stop();
            if (param.FunctionAddress == PortEnums.DealFunctions.ProsennelHost)
            {
                if (param.HostParam != null)
                {
                    ViewCallFunction.ViewDownloadOver(param.HostParam.Result);
                }
            }
        }
Пример #8
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            if (param.FunctionAddress == PortEnums.DealFunctions.Ic)
            {
                if (param.Command.ICommand == PortEnums.ICommands.Read)
                {
                    IcParameter icInfo = param.IcParam;
                    string      msg    = $"IC卡号:{icInfo.IcNumber} 车牌号码:{icInfo.LicensePlate} 时间:{icInfo.Time} ";
                    ViewCallFunction.ViewWirelessMessage(msg);
                }
            }
        }
Пример #9
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            if (param.FunctionAddress == PortEnums.DealFunctions.ModularAndVoice)
            {
                if (param.Command.MCommand == PortEnums.MCommands.SetModule)
                {
                    SettingOver = param.ModuleParam.Result;
                }
                if (by.Length > 12)
                {
                    string str = Encoding.ASCII.GetString(by);
                    ViewCallFunction.ViewWirelessMessage(str);
                }
            }
        }
Пример #10
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            if (param.FunctionAddress == PortEnums.DealFunctions.ModularAndVoice)
            {
                if (param.Command.MCommand == PortEnums.MCommands.TestCommunication)
                {
                    if (param.ModuleParam.Result)
                    {
                        ViewCallFunction.ViewWirelessMessage("测试数据发送成功。");
                    }
                    else
                    {
                        ViewCallFunction.ViewWirelessMessage("测试数据发送失败,请检测无线ID(编号)或频率是否正确。");
                    }
                }
            }
        }
Пример #11
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            OverTimeManager.Stop();
            if (param.DistanceDeviceParam.Command == PortEnums.DistanceCommands.InitializeDevice)
            {
                string msg = null;
                if (param.DistanceDeviceParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
                {
                    msg = "定距发行器加密成功";
                }
                else
                {
                    msg = "定距发行器加密失败";
                }
                ViewCallFunction.ViewEncryptMessage(msg);
                ViewCallFunction.ViewEncryptOver();
            }
        }
Пример #12
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            OverTimeManager.Stop();
            try
            {
                if (param.FunctionAddress == PortEnums.DealFunctions.Ic && param.Command.ICommand == PortEnums.ICommands.EntryptIcDevice)
                {
                    if (param.IcParam != null)
                    {
                        string msg = $"IC 设备加密{(param.IcParam.Result ? "成功" : "失败")}";
                        ViewCallFunction.ViewEncryptMessage(msg);
                        ViewCallFunction.ViewEncryptOver();
                    }
                }
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
Пример #13
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();
                }
            }
        }
Пример #14
0
        public static PortDataParameter Parsing(byte[] by)
        {
            PortDataParameter param = new PortDataParameter()
            {
                Header = by[0],
                End    = by[by.Length - 1],
            };

            if (param.Header == 2)
            {
                param.FunctionAddress = (PortEnums.DealFunctions)by[1];
                param.DeviceAddress   = Utility.HexToInt(by[2], by[3]);
                int command = Utility.HexToInt(by[4], by[5]);
                switch (param.FunctionAddress)
                {
                case PortEnums.DealFunctions.Distance:
                    PortEnums.DistanceCommands dCommand = (PortEnums.DistanceCommands)Utility.HexToInt(by[6], by[7]);
                    param.Command.DCommand = (PortEnums.DCommands)command;
                    switch (dCommand)
                    {
                    case PortEnums.DistanceCommands.WriteAllCard:
                    case PortEnums.DistanceCommands.WriteACard:
                    case PortEnums.DistanceCommands.ReadAllCard:
                    case PortEnums.DistanceCommands.ReadACard:
                    case PortEnums.DistanceCommands.ModifyAllCardPwd:
                        DistanceCardParameter distanceParam = new DistanceCardParameter
                        {
                            Command          = dCommand,
                            AuxiliaryCommand = (PortEnums.AuxiliaryCommands)Utility.HexToInt(by[8], by[9])
                        };
                        if (distanceParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
                        {
                            distanceParam.CardNumber        = Encoding.ASCII.GetString(by, 10, 6);
                            distanceParam.CardTypeValue     = Utility.HexToInt(by[16], by[17]);
                            distanceParam.CardTypeParameter = ParsingDistanceCardType(distanceParam.CardTypeValue);
                            distanceParam.Area  = Utility.HexToInt(by[18], by[19]);
                            distanceParam.Start = Utility.HexToInt(by[20], by[21]);
                            distanceParam.Len   = Utility.HexToInt(by[22], by[23]);
                            if (((int)distanceParam.CardTypeParameter.CardType) < 2)
                            {
                                if (dCommand == PortEnums.DistanceCommands.ReadACard || dCommand == PortEnums.DistanceCommands.ReadAllCard)
                                {
                                    if (distanceParam.Len >= 1)
                                    {
                                        distanceParam.FunctionByteValue = Utility.HexToInt(by[24], by[25]);
                                        distanceParam.FunctionByteParam = ParsingDistanceFunctionByte(distanceParam.FunctionByteValue);
                                    }
                                    if (distanceParam.Len >= 3)
                                    {
                                        distanceParam.Count = Utility.HexToInt(by[26], by[27], by[28], by[29]);
                                    }
                                }
                            }
                        }
                        param.DistanceCardParam = distanceParam;
                        break;

                    case PortEnums.DistanceCommands.InitializeDevice:
                        DistanceDeviceParameter deviceParam = new DistanceDeviceParameter()
                        {
                            Command          = dCommand,
                            AuxiliaryCommand = (PortEnums.AuxiliaryCommands)Utility.HexToInt(by[8], by[9]),
                        };
                        param.DistanceDeviceParam = deviceParam;
                        break;
                    }

                    break;

                case PortEnums.DealFunctions.Ic:
                    param.Command.ICommand = (PortEnums.ICommands)command;
                    IcParameter icParam = new IcParameter();
                    switch (param.Command.ICommand)
                    {
                    case PortEnums.ICommands.Read:
                        string icNumber = Encoding.ASCII.GetString(by, 6, 8);
                        icParam.IcNumber = icNumber;
                        string licensePlate = Encoding.Default.GetString(by, 14, 10);
                        icParam.LicensePlate = licensePlate;
                        string   strTime = Encoding.Default.GetString(by, 24, 12);
                        DateTime time    = DateTime.Now;
                        if (CRegex.IsTime(strTime))
                        {
                            time = DateTime.ParseExact(strTime, "yyMMddHHmmss", System.Globalization.CultureInfo.InstalledUICulture);
                        }
                        icParam.Time = time;
                        break;

                    case PortEnums.ICommands.EntryptIcCard:
                    case PortEnums.ICommands.EntryptIcDevice:
                        icParam.Result = Utility.HexToInt(by[6], by[7]) == 0;
                        break;
                    }
                    param.IcParam = icParam;
                    break;

                case PortEnums.DealFunctions.ModularAndVoice:
                    param.Command.MCommand = (PortEnums.MCommands)command;
                    param.ModuleParam      = new ModuleParameter();
                    switch (param.Command.MCommand)
                    {
                    case PortEnums.MCommands.SetModule:
                        param.ModuleParam.Result = by[6] == 89;
                        break;

                    case PortEnums.MCommands.TestCommunication:
                        param.ModuleParam.Result = by[6] == 83;
                        break;
                    }
                    break;

                case PortEnums.DealFunctions.HostResult:
                    param.Command.HCommand = (PortEnums.HCommands)command;
                    param.HostParam        = new HostParameter();
                    switch (param.Command.HCommand)
                    {
                    case PortEnums.HCommands.Search:
                        break;

                    case PortEnums.HCommands.ReadData:
                        break;
                    }
                    break;

                case PortEnums.DealFunctions.HostNoResult:
                case PortEnums.DealFunctions.ProsennelHost:
                    param.Command.HCommand = (PortEnums.HCommands)command;
                    param.HostParam        = new HostParameter();
                    switch (param.Command.HCommand)
                    {
                    case PortEnums.HCommands.Password:
                    case PortEnums.HCommands.Time:
                        param.HostParam.Result = by[12] == 49;
                        break;

                    case PortEnums.HCommands.NumberModify:
                        param.HostParam.Result = by[6] == 49;
                        break;
                    }
                    break;
                }
            }
            else if (param.Header == 10)
            {
                param.DeviceAddress    = Utility.HexToInt(by[1], by[2]);
                param.Command.PCommand = (PortEnums.PCommands)Utility.HexToInt(by[3], by[4]);
                switch (param.Command.PCommand)
                {
                case PortEnums.PCommands.Default:
                    string   strTime  = Encoding.Default.GetString(by, 15, 6);
                    DateTime cardTime = DateTime.MinValue;
                    if (CRegex.IsTime(strTime))
                    {
                        cardTime = DateTime.ParseExact(strTime, "yyMMdd", System.Globalization.CultureInfo.InstalledUICulture);
                    }
                    strTime = Encoding.Default.GetString(by, 21, 6);
                    DateTime systemTime = DateTime.MinValue;
                    if (CRegex.IsTime(strTime))
                    {
                        systemTime = DateTime.ParseExact(strTime, "yyMMdd", System.Globalization.CultureInfo.InstalledUICulture);
                    }
                    param.PersonnelParam = new PersonnelParameter()
                    {
                        CorridorNumber   = Utility.HexToInt(by[5], by[6]),
                        HostNumber       = Utility.HexToInt(by[7], by[8]),
                        CardNumber       = Encoding.ASCII.GetString(by, 9, 6),
                        CardTime         = cardTime,
                        SystemTime       = systemTime,
                        OpenTheDoorState = Utility.HexToInt(by[27], by[28])
                    };
                    break;
                }
            }
            return(param);
        }