コード例 #1
0
ファイル: CardManagerEvh.cs プロジェクト: makejack/TestTools
 private static void Host_RefreshOperation(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
 {
     //刷新操作
     CardManager.CardInfos.Clear();
     byte[] bys;
     try
     {
         bys = PortAgreement.ReadAllCard();
         bool ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, bys);
         if (ret)
         {
             ReceivedManager.SetReceivedFunction <CardRefresh>();
         }
         e.SetReturnValue(ret);
     }
     catch (Exception ex)
     {
         Log4Helper.ErrorInfo(ex.Message, ex);
         ViewCallFunction.ViewAlert(ex.Message);
     }
     finally
     {
         bys = null;
     }
 }
コード例 #2
0
ファイル: CardManagerEvh.cs プロジェクト: makejack/TestTools
        private static void Host_PostPersonnelIssue(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                int index = e.Arguments[0].IntValue;
                Chromium.Remote.CfrTime cTime = e.Arguments[1].DateValue;
                DateTime time       = new DateTime(cTime.Year, cTime.Month, cTime.DayOfMonth);
                int      partition  = e.Arguments[2].IntValue;
                int      dataType   = e.Arguments[3].IntValue;
                string   customData = e.Arguments[4].StringValue;

                CardInfo info = CardManager.CardInfos[index];
                info.CardTime      = time;
                info.CardPartition = partition;

                byte[] by = PersonnelIssue.Issue(info, dataType, customData);

                bool ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                if (ret)
                {
                    ReceivedManager.SetReceivedFunction <CardIssuePersonnel>();
                    ReceivedManager.GetReceivedFun <CardIssuePersonnel>().IssueInfo = info;
                }
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
コード例 #3
0
 private static void Host_PostWirelessTest(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
 {
     try
     {
         ReceivedManager.SetReceivedFunction <WirelessTest>();
         byte[] by = PortAgreement.OpenTheDoorAndVoice(new OpenTheDoorParam2()
         {
             DeviceAddress      = 0,
             IcCardNumber       = "093D2446",
             LicensePlateNumber = "福A000000",
             LicensePlateColor  = LicensePlateColors.Blue,
             Time = DateTime.Now,
         });
         SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
     }
     catch (Exception ex)
     {
         Log4Helper.ErrorInfo(ex.Message, ex);
         ViewCallFunction.ViewAlert(ex.Message);
     }
     finally
     {
         OverTimeManager.Stop();
     }
 }
コード例 #4
0
ファイル: CardManagerEvh.cs プロジェクト: makejack/TestTools
        private static void Host_PostBatch(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            UpdateBatchParam(e);

            Task.Factory.StartNew(() =>
            {
                try
                {
                    int index = -1;
                    CardBatch batchReceived = null;
                    foreach (CardInfo item in CardManager.CardInfos)
                    {
                        if (item.Id == 0 && item.CardType < 3)
                        {
                            index += 1;

                            item.CardTime            = CardManager.BatchParam.CardTime;
                            item.CardDistance        = CardManager.BatchParam.CardDistance;
                            item.ParkingRestrictions = CardManager.BatchParam.ParkingRestrictions;
                            item.CardPartition       = CardManager.BatchParam.CardPartition;

                            byte[] by = DistanceIssue.Issue(item);
                            bool ret  = SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                            if (ret)
                            {
                                ReceivedManager.SetReceivedFunction <CardBatch>();
                                if (batchReceived == null)
                                {
                                    batchReceived = ReceivedManager.GetReceivedFun <CardBatch>();
                                }
                                batchReceived.IssueInfo = item;

                                for (int i = 0; i < 250; i++)
                                {
                                    Thread.Sleep(10);
                                    if (batchReceived.IssueInfo == null)
                                    {
                                        if (item.Id > 0)
                                        {
                                            ViewCallFunction.ViewDisplayBatchContent(item, index);
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log4Helper.ErrorInfo(ex.Message, ex);
                    ViewCallFunction.ViewAlert(ex.Message);
                }
                finally
                {
                    int count = CardManager.CardInfos.Where(w => w.Id == 0 && w.CardType < 3).Count();
                    ViewCallFunction.ViewBatchOver(count);
                }
            });
        }
コード例 #5
0
        private static void Host_PostTestPort(object sender, CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                if (SerialPortManager.Device2.SerialPortDevice.BaudRate != WinApi.B38400)
                {
                    SerialPortManager.Device2.SerialPortDevice.SetBaudRate(WinApi.B38400);
                    Thread.Sleep(10);
                }

                byte[] by  = PortAgreement.TestPort(SerialPortManager.Device2Address);
                bool   ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device2, by);
                if (ret)
                {
                    ReceivedManager.SetReceivedFunction <TestPort>();
                }
                e.SetReturnValue(ret);
            }
            catch (Exception ex)
            {
                SerialPortManager.Device2.SerialPortDevice.SetBaudRate(WinApi.B19200);

                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
コード例 #6
0
 private static void Host_PostStopReadIcCard(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
 {
     try
     {
         byte[] by = PortAgreement.CloseModular();
         SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
     }
     catch (Exception ex)
     {
         Log4Helper.ErrorInfo(ex.Message, ex);
         ViewCallFunction.ViewAlert(ex.Message);
     }
 }
コード例 #7
0
 private static void ReplaceSerialPort(IDevice device)
 {
     try
     {
         m_SerialPort.DataReceived -= SerialPortDataReceived;
     }
     catch (Exception ex)
     {
         Log4Helper.ErrorInfo(ex.Message, ex);
     }
     SerialPortManager.CompleteSerialPortConnection(m_SerialPort, device);
     m_SerialPort = null;
     m_Validation.Dispose();
 }
コード例 #8
0
ファイル: PwdManagerEvh.cs プロジェクト: makejack/TestTools
        private static void Host_PostIcDeviceEncrypt(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                string pwd = e.Arguments[0].StringValue;

                byte[] bys = PortAgreement.IcDeviceEncryption(pwd);
                SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, bys);

                ReceivedManager.SetReceivedFunction <IcDeviceEncrypt>();
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
コード例 #9
0
 private static void Host_PostDownloadTime(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
 {
     try
     {
         byte[] bys = PortAgreement.SetPersonnelHostTime();
         bool   ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device2, bys);
         if (ret)
         {
             ReceivedManager.SetReceivedFunction <TimeDownload>();
         }
         e.SetReturnValue(ret);
     }
     catch (Exception ex)
     {
         Log4Helper.ErrorInfo(ex.Message, ex);
         ViewCallFunction.ViewAlert(ex.Message);
     }
 }
コード例 #10
0
        private static void Host_PostReadIcCard(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                byte[] by = PortAgreement.ReadIc();
                SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);

                ReceivedManager.SetReceivedFunction <ReadIcCard>();
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
            finally
            {
                OverTimeManager.Stop();
            }
        }
コード例 #11
0
        private static void Host_PostDownloadPassword(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                string oldpwd = e.Arguments[0].StringValue;
                string newpwd = e.Arguments[1].StringValue;

                byte[] by  = PortAgreement.SetPersonnelHostPassword(oldpwd, newpwd);
                bool   ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device2, by);
                if (ret)
                {
                    ReceivedManager.SetReceivedFunction <PasswordDownload>();
                }
                e.SetReturnValue(ret);
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
コード例 #12
0
ファイル: CardManagerEvh.cs プロジェクト: makejack/TestTools
 private static void Host_PostPersonnelRecovery(object sender, CfrV8HandlerExecuteEventArgs e)
 {
     try
     {
         string          loseCardNumber = GetLoseNumber(e);
         List <CardInfo> list           = CardManager.GetCardInfos(loseCardNumber);
         CardManager.LossLists = list;
         byte[] by  = PortAgreement.ReadACard("797979", 1);
         bool   ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
         if (ret)
         {
             ReceivedManager.SetReceivedFunction <PersonnelCardLoss>();
         }
         e.SetReturnValue(ret);
     }
     catch (Exception ex)
     {
         Log4Helper.ErrorInfo(ex.Message, ex);
         ViewCallFunction.ViewAlert(ex.Message);
     }
 }
コード例 #13
0
        private static void Host_PostDownloadNumber(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                int      index = e.Arguments[0].IntValue;
                UserInfo info  = UserManager.UserInfos[index];

                byte[] bys = PortAgreement.SetPersonnelHostNumber(info.UserNumber);
                bool   ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device2, bys);
                if (ret)
                {
                    ReceivedManager.SetReceivedFunction <NumberDownload>();
                }
                e.SetReturnValue(ret);
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
コード例 #14
0
ファイル: Main.cs プロジェクト: makejack/TestTools
        private void OnLoadForm(object sender, EventArgs e)
        {
            try
            {
                DataBaseManager.LoadFile();

                string version = ConfigManager.GetString("General", "Version");
                if (string.IsNullOrEmpty(version) || Application.ProductVersion != version)
                {
                    DataBaseManager.UpdateDataBaseStr();
                    ConfigManager.Set("General", "Version", Application.ProductVersion);
                }

                ConnectionSerialDevice.AutoConnectioinDevice = true;
                SerialPortManager.InitSerialDevice();
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
            }
        }
コード例 #15
0
ファイル: PortMonitor.cs プロジェクト: makejack/TestTools
 private static void CurrentPortIsDisconnected(SerialPortEx serial, List <string> serialPortNames)
 {
     try
     {
         foreach (var item in serialPortNames)
         {
             if (serial.PortName == item)
             {
                 return;
             }
         }
         SerialPortManager.CloseSerialPort(serial);
     }
     catch (Exception ex)
     {
         Log4Helper.ErrorInfo(ex.Message, ex);
     }
     finally
     {
         ViewCallFunction.ViewSerialPortChanged(serial);
     }
 }
コード例 #16
0
ファイル: PwdManagerEvh.cs プロジェクト: makejack/TestTools
        private static void Host_PostDistanceCardEncrypt(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                string oldpwd       = e.Arguments[0].StringValue;
                string pwd          = e.Arguments[1].StringValue;
                string clientnumber = e.Arguments[2].StringValue;

                byte[] bys = PortAgreement.DistanceDeviceEncryption(clientnumber, oldpwd);
                bool   ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, bys);
                if (ret)
                {
                    ReceivedManager.SetReceivedFunction <DistanceCardEncrypt>();
                    DistanceCardEncrypt received = ReceivedManager.GetReceivedFun <DistanceCardEncrypt>();
                    received.ClientNumber = clientnumber;
                    received.NewPwd       = pwd;
                }
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
コード例 #17
0
ファイル: Main.cs プロジェクト: makejack/TestTools
        public Main()
            : base("http://res.app.local/main.html")
        {
            InitializeComponent();
            GetMain = this;

            this.Load += OnLoadForm;

            LoadHandler.OnLoadEnd += (sender, args) =>
            {
                PortMonitor.StartMonitor();
            };

            GlobalObject.AddFunction("ShowDevTools").Execute += (sender, args) =>
            {
                Chromium.ShowDevTools();
            };

            GlobalObject.AddFunction("HostOpenAndCloseSerialDevice").Execute += (sender, args) =>
            {
                try
                {
                    var          callback   = args.Arguments.FirstOrDefault(e => e.IsFunction);
                    string       deviceName = args.Arguments[0].StringValue;
                    SerialPortEx serial     = SelectSerialDevice(deviceName);
                    string       portName   = args.Arguments[1].StringValue;
                    if (!serial.IsOpen)
                    {
                        SerialPortManager.OpenSerialPort(serial, portName);
                    }
                    else
                    {
                        SerialPortManager.CloseSerialPort(serial);
                    }
                    string json = Utility.JsonSerializerBySingleData(serial);
                    callback.ExecuteFunction(null, new Chromium.Remote.CfrV8Value[] { json });
                }
                catch (Exception ex)
                {
                    Log4Helper.ErrorInfo(ex.Message, ex);
                    ViewCallFunction.ViewAlert(ex.Message);
                }
            };

            GlobalObject.AddFunction("HostAutoConnectionDeviced").Execute += (sender, args) =>
            {
                try
                {
                    bool autoConnection = args.Arguments[0].BoolValue;
                    if (autoConnection)
                    {
                        ConnectionSerialDevice.Start();
                    }
                    else
                    {
                        ConnectionSerialDevice.Stop();
                    }
                    ConnectionSerialDevice.AutoConnectioinDevice = autoConnection;
                }
                catch (Exception ex)
                {
                    Log4Helper.ErrorInfo(ex.Message, ex);
                    ViewCallFunction.ViewAlert(ex.Message);
                }
            };

            CardManagerEvh.InitEvent();
            PwdManagerEvh.InitEvent();
            ConfigureManagerEvh.InitEvent();
            WirelessManagerEvh.InitEvent();
            UserManagerEvh.InitEvent();
        }
コード例 #18
0
ファイル: CardManagerEvh.cs プロジェクト: makejack/TestTools
        private static void Host_PostIssue(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                int index = e.Arguments[0].IntValue;
                Chromium.Remote.CfrTime cTime = e.Arguments[1].DateValue;
                DateTime time      = new DateTime(cTime.Year, cTime.Month, cTime.DayOfMonth);
                int      distance  = e.Arguments[2].IntValue;
                int      limit     = e.Arguments[3].IntValue;
                int      type      = e.Arguments[4].IntValue;
                int      partition = e.Arguments[5].IntValue;

                CardInfo info = CardManager.CardInfos[index];
                info.CardType            = type;
                info.CardDistance        = distance;
                info.CardTime            = time;
                info.ParkingRestrictions = limit;
                info.CardPartition       = partition;
                info.CardCount           = DistanceIssue.SetCount(info.CardCount);

                byte[] by;
                if (info.CardType == (int)PortEnums.CardTypes.Card2 && (info.ViceCardInfos != null && info.ViceCardInfos.Count > 0))
                {
                    info.CardTime = info.ViceCardInfos.Max(w => w.CardTime);

                    ViceCardRemoveLock lockReceived = null;
                    foreach (CardInfo item in info.ViceCardInfos)
                    {
                        if (item.CardLock == 1)
                        {
                            by = DistanceIssue.Issue(item);
                            SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);

                            ReceivedManager.SetReceivedFunction <ViceCardRemoveLock>();
                            if (lockReceived == null)
                            {
                                lockReceived = ReceivedManager.GetReceivedFun <ViceCardRemoveLock>();
                            }
                            lockReceived.RemoveLockInfo = item;

                            for (int i = 0; i < 250; i++)
                            {
                                Thread.Sleep(10);
                                if (lockReceived.RemoveLockInfo == null)
                                {
                                    if (item.CardLock == 0)
                                    {
                                        ViewCallFunction.ViewRemoveLock(info.ViceCardInfos);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }

                by = DistanceIssue.Issue(info);
                bool ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                if (ret)
                {
                    ReceivedManager.SetReceivedFunction <CardIssue>();
                    ReceivedManager.GetReceivedFun <CardIssue>().IssueInfo = info;
                }
                e.SetReturnValue(ret);
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
コード例 #19
0
        private static void OnTimerEvent(object sender, ElapsedEventArgs e)
        {
            m_StartTimer = true;
            byte[] by = null;
            try
            {
                for (int i = 0; i < 3; i++)
                {
                    if (m_StopTimer)
                    {
                        return;
                    }
                    foreach (string portName in SearchSerialPort.SerialPortNames)
                    {
                        if (m_StopTimer)
                        {
                            return;
                        }

                        m_Over = false;
                        if (m_SerialPort == null)
                        {
                            m_SerialPort = SerialPortManager.CreateSerialPort();
                            m_SerialPort.DataReceived += SerialPortDataReceived;
                        }

                        m_SerialPort.PortName = portName;
                        try
                        {
                            m_SerialPort.BaudRate = WinApi.B19200;
                            m_SerialPort.Open();

                            if (!SerialPortManager.Device1.SerialPortDevice.IsOpen)
                            {
                                if (m_StopTimer)
                                {
                                    return;
                                }
                                try
                                {
                                    by = PortAgreement.DistanceDeviceEncryption(DefaultParams.DEVICEDEFAULTCLIENTNUMBER, DefaultParams.DEVICEDEFAULTPASSWORD);
                                    m_SerialPort.Write(by);

                                    bool ret = WaitResult(SerialPortManager.Device1);
                                    if (ret)
                                    {
                                        continue;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Log4Helper.ErrorInfo(ex.Message, ex);
#if DEBUG
                                    Console.WriteLine(ex.Message);
#endif
                                }
                            }

                            m_SerialPort.SetBaudRate(WinApi.B9600);
                            Thread.Sleep(50);

                            if (!SerialPortManager.Device2.SerialPortDevice.IsOpen)
                            {
                                int address = 1;
                                try
                                {
                                    for (int number = 1; number <= 50; number++)
                                    {
                                        address = number;
                                        if (m_StopTimer)
                                        {
                                            return;
                                        }
                                        by = PortAgreement.CorridorReadCardData(number);
                                        m_SerialPort.Write(by);
                                        Thread.Sleep(50);
                                        if (m_Over)
                                        {
                                            ReplaceSerialPort(SerialPortManager.Device2);
                                            break;
                                        }
                                    }

                                    if (m_Over)
                                    {
                                        continue;
                                    }
                                    bool ret = WaitResult(SerialPortManager.Device2);
                                    if (ret)
                                    {
                                        continue;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Log4Helper.ErrorInfo(ex.Message, ex);
#if DEBUG
                                    Console.WriteLine(ex.Message);
#endif
                                }
                                finally
                                {
                                    SerialPortManager.Device2Address = address;
                                }
                            }

                            m_SerialPort.Close();
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
#if DEBUG
                Console.WriteLine(ex.Message);
#endif
            }
            finally
            {
                by = null;
                m_Validation.Dispose();
                if (m_SerialPort != null && m_SerialPort.IsOpen)
                {
                    m_SerialPort.Close();
                }
                m_SerialPort = null;
                if (!m_StopTimer && (!SerialPortManager.Device1.SerialPortDevice.IsOpen && !SerialPortManager.Device2.SerialPortDevice.IsOpen))
                {
                    ViewCallFunction.ViewConnectionFailedMessage();
                }
                m_StartTimer = false;
            }
        }
コード例 #20
0
        private static void Host_PostWirelessSetting(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                int wirelessNumber = e.Arguments[0].IntValue;
                int frequency      = e.Arguments[1].IntValue;

                Task.Factory.StartNew(() =>
                {
                    SettingModule settingModule = SettingReceived();
                    try
                    {
                        ViewCallFunction.ViewWirelessMessage("打开模块设置功能。");
                        byte[] by = PortAgreement.OpenModular();
                        SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                        Thread.Sleep(20);

                        #region 设置模块发送ID

                        for (int i = 0; i < 3; i++)
                        {
                            settingModule.SettingOver = false;
                            ViewCallFunction.ViewWirelessMessage("设置模块发送ID(编号)。");
                            by = PortAgreement.SetModuleTid(wirelessNumber);
                            SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                            Thread.Sleep(250);
                            if (settingModule.SettingOver)
                            {
                                break;
                            }
                        }

                        for (int i = 0; i < 3; i++)
                        {
                            settingModule.SettingOver = false;
                            ViewCallFunction.ViewWirelessMessage("设置模块接收ID(编号)。");
                            by = PortAgreement.SetModuleRid(wirelessNumber);
                            SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                            Thread.Sleep(250);
                            if (settingModule.SettingOver)
                            {
                                break;
                            }
                        }

                        for (int i = 0; i < 3; i++)
                        {
                            settingModule.SettingOver = false;
                            ViewCallFunction.ViewWirelessMessage("设置模块频率。");
                            by = PortAgreement.SetModuleFrequency(frequency);
                            SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                            Thread.Sleep(250);
                            if (settingModule.SettingOver)
                            {
                                break;
                            }
                        }

                        for (int i = 0; i < 3; i++)
                        {
                            settingModule.SettingOver = false;
                            ViewCallFunction.ViewWirelessMessage("设置模块回传功能。");
                            by = PortAgreement.SetModuleComesBack(1);
                            SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                            Thread.Sleep(250);
                            if (settingModule.SettingOver)
                            {
                                break;
                            }
                        }

                        ViewCallFunction.ViewWirelessMessage("关闭模块设置功能。");
                        by = PortAgreement.CloseModular();
                        SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                        Thread.Sleep(20);

                        for (int i = 0; i < 3; i++)
                        {
                            settingModule.SettingOver = false;
                            ViewCallFunction.ViewWirelessMessage("发送数据测试。");
                            by = PortAgreement.SetModular("ABCDEF");
                            SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                            Thread.Sleep(250);
                            if (settingModule.SettingOver)
                            {
                                break;
                            }
                        }

                        #endregion 设置模块发送ID
                    }
                    catch (Exception ex)
                    {
                        Log4Helper.ErrorInfo(ex.Message, ex);
                        ViewCallFunction.ViewAlert(ex.Message);
                    }
                    finally
                    {
                        OverTimeManager.Stop();
                        ViewCallFunction.ViewWirelessOver();
                    }
                });
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
コード例 #21
0
        private static void Host_PostWirelessQuery(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                Task.Factory.StartNew(() =>
                {
                    ReceivedManager.SetReceivedFunction <WirelessQuery>();
                    WirelessQuery queryReceived = ReceivedManager.GetReceivedFun <WirelessQuery>();
                    try
                    {
                        ViewCallFunction.ViewWirelessMessage("打开模块设置功能。");
                        byte[] by = PortAgreement.OpenModular();
                        SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                        Thread.Sleep(20);

                        for (int i = 0; i < 3; i++)
                        {
                            queryReceived.SettingOver = false;
                            ViewCallFunction.ViewWirelessMessage("关闭模块回传功能。");
                            by = PortAgreement.SetModuleComesBack(0);
                            SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                            Thread.Sleep(250);
                            if (queryReceived.SettingOver)
                            {
                                break;
                            }
                        }

                        ViewCallFunction.ViewWirelessMessage("关闭模块设置功能。");
                        by = PortAgreement.CloseModular();
                        SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                        Thread.Sleep(20);

                        ViewCallFunction.ViewWirelessMessage("查询无线ID(编号)。");
                        string strQueryFrequency = "AT+FREQ?";
                        by = PortAgreement.SetModular(strQueryFrequency);
                        SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                        Thread.Sleep(250);

                        ViewCallFunction.ViewWirelessMessage("查询无线的频率。");
                        string strQueryRid = "AT+TID?";
                        by = PortAgreement.SetModular(strQueryRid);
                        SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                        Thread.Sleep(250);
                    }
                    catch (Exception ex)
                    {
                        Log4Helper.ErrorInfo(ex.Message, ex);
                        ViewCallFunction.ViewAlert(ex.Message);
                    }
                    finally
                    {
                        OverTimeManager.Stop();
                        ViewCallFunction.ViewWirelessOver();
                    }
                });
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
コード例 #22
0
        private static void Host_PostWirelessSearch(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                Task.Factory.StartNew(() =>
                {
                    SettingModule settingModule = SettingReceived();
                    OverTimeManager.Stop();

                    byte[] by;
                    try
                    {
                        for (int i = 1; i <= 64; i++)
                        {
                            if (m_StopWirelessSearch)
                            {
                                break;
                            }

                            ViewCallFunction.ViewWirelessMessage($"搜索目标频率{i}/64。");

                            //ViewCallFunction.ViewWirelessMessage("打开模块设置功能。");
                            by = PortAgreement.OpenModular();
                            SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                            Thread.Sleep(20);

                            for (int j = 0; j < 3; j++)
                            {
                                if (m_StopWirelessSearch)
                                {
                                    break;
                                }
                                settingModule.SettingOver = false;
                                ViewCallFunction.ViewWirelessMessage("设置模块频率。");
                                by = PortAgreement.SetModuleFrequency(i);
                                SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                                Thread.Sleep(250);
                                if (settingModule.SettingOver)
                                {
                                    break;
                                }
                            }

                            for (int j = 0; j < 3; j++)
                            {
                                if (m_StopWirelessSearch)
                                {
                                    break;
                                }
                                settingModule.SettingOver = false;
                                //ViewCallFunction.ViewWirelessMessage("设置模块回传功能。");
                                by = PortAgreement.SetModuleComesBack(1);
                                SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                                Thread.Sleep(250);
                                if (settingModule.SettingOver)
                                {
                                    break;
                                }
                            }

                            //ViewCallFunction.ViewWirelessMessage("关闭模块设置功能。");
                            by = PortAgreement.CloseModular();
                            SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                            Thread.Sleep(20);

                            for (int j = 0; j < 3; j++)
                            {
                                if (m_StopWirelessSearch)
                                {
                                    break;
                                }
                                settingModule.SettingOver = false;
                                ViewCallFunction.ViewWirelessMessage("发送数据测试。");
                                by = PortAgreement.SetModular("ABCDEF");
                                SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                                Thread.Sleep(250);
                                if (settingModule.SettingOver)
                                {
                                    ViewCallFunction.ViewWirelessMessage($"无线频率 {i} 发现设备。");
                                    break;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log4Helper.ErrorInfo(ex.Message, ex);
                        ViewCallFunction.ViewAlert(ex.Message);
                    }
                    finally
                    {
                        m_StopWirelessSearch = false;
                        ViewCallFunction.ViewWirelessOver();
                    }
                });
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }