Esempio n. 1
0
        private void FormExample_Load(object sender, EventArgs e)
        {
            // set path
            tbPath.Text = Properties.Settings.Default.Path;
            // binding list
            lbRegisteredTools.DataSource = RegisterTools;
            lbScannedTools.DataSource    = ScanTools;
            // check port list
            foreach (var item in HComm.Device.HcSerial.GetPortNames())
            {
                // add port name
                cbPorts.Items.Add(item);
            }
            // check interfcae list
            foreach (var item in HcManager.GetAllInterfaces())
            {
                // add interface item
                cbInterface.Items.Add($@"{item.Name}:{item.Id}");
            }
            // check list
            if (cbInterface.Items.Count > 0)
            {
                cbInterface.SelectedIndex = 0;
            }

            // set event
            HCommAir.ChangedConnect += OnChangedConnect;
            HCommAir.ReceivedMsg    += OnReceivedMsg;
            // load register tools
            HCommAir.LoadRegisterTools(tbPath.Text);
            // start timer
            timer.Start();
            // start scanner
            HCommAir.Start();
        }
Esempio n. 2
0
 private void btOpen_Click(object sender, EventArgs e)
 {
     // check text
     if (btOpen.Text == @"Open")
     {
         // get port name
         var port = $@"{cbPorts.SelectedItem}";
         // check port name
         if (port == string.Empty)
         {
             return;
         }
         // Connect manual tool
         HCommAir.ConnectManualTool(port);
     }
     else
     {
         // get port name
         var port = $@"{cbPorts.SelectedItem}";
         // check port name
         if (port == string.Empty)
         {
             return;
         }
         // Disconnect manual tool
         HCommAir.DisConnectManualTool(port);
         // set text
         btOpen.Text = @"Open";
     }
 }
Esempio n. 3
0
        private void lbRegisteredTools_SelectedIndexChanged(object sender, EventArgs e)
        {
            // get item
            var item = (HcToolInfo)lbRegisteredTools.SelectedItem;

            // check item
            if (item == null)
            {
                return;
            }
            // stop all sessions event monitoring
            HCommAir.StopAllSessionsEventMonitor();
            // select session
            SelectedSession = HCommAir.GetSession(item);
            // check selected session
            if (SelectedSession == null)
            {
                return;
            }
            // update information
            lbIp.Text     = $@"IP: {SelectedSession.ToolInfo.Ip}";
            lbMac.Text    = $@"MAC: {SelectedSession.ToolInfo.Mac}";
            lbSerial.Text = $@"S/N: {SelectedSession.ToolInfo.Serial}";
            lbState.Text  = $@"STATE: {SelectedSession.State}";
        }
Esempio n. 4
0
        private void btRegister_Click(object sender, EventArgs e)
        {
            var scanned    = HCommAir.GetScannedTools();
            var registered = HCommAir.GetRegisteredTools();

            // check sender
            if (sender == btRegister)
            {
                // check index
                if (lbScannedTools.SelectedIndex < 0 || lbScannedTools.SelectedIndex > scanned.Count)
                {
                    return;
                }
                // get item
                var info = scanned.Find(x => x.Mac == scanned[lbScannedTools.SelectedIndex].Mac);
                // add item
                HCommAir.RegisterTool(info);
                // save tool list
                HCommAir.SaveRegisterTools(tbPath.Text);
            }
            else
            {
                // check index
                if (lbRegisteredTools.SelectedIndex < 0 || lbRegisteredTools.SelectedIndex > registered.Count)
                {
                    return;
                }
                // get item
                var info = registered.Find(x => x.Mac == registered[lbRegisteredTools.SelectedIndex].Mac);
                // remove item
                HCommAir.UnRegisterTool(info);
                // save tool list
                HCommAir.SaveRegisterTools(tbPath.Text);
            }
        }
Esempio n. 5
0
        private void cbInterface_SelectedIndexChanged(object sender, EventArgs e)
        {
            // get selected item
            var item = $@"{cbInterface.SelectedItem}".Split(':')[1];
            // find interface
            var inf = HcManager.GetAllInterfaces().Find(x => x.Id == item);

            // check interface
            if (inf == null)
            {
                return;
            }
            // change interface
            HCommAir.ChangeInterfaceProp(inf.GetIPProperties().GetIPv4Properties());
        }
Esempio n. 6
0
        private void timer_Tick(object sender, EventArgs e)
        {
            var scanned    = HCommAir.GetScannedTools();
            var registered = HCommAir.GetRegisteredTools();

            // check scanned tools count
            if (scanned.Count != ScanTools.Count)
            {
                // clear scanned tools item
                ScanTools.Clear();
                // add item list
                foreach (var info in scanned)
                {
                    // add
                    ScanTools.Add(info);
                }
                // refresh
                lbScannedTools.Refresh();
            }
            // check registered tools count
            if (registered.Count != RegisterTools.Count)
            {
                // clear register tools item
                RegisterTools.Clear();
                // add item list
                foreach (var info in registered)
                {
                    // add
                    RegisterTools.Add(info);
                }
                // refresh
                lbRegisteredTools.Refresh();
            }
            // check graph state
            if (!GraphState || SelectedSession == null || SelectedSession.State != ConnectionState.Connected ||
                !((DateTime.Now - GraphTime).TotalSeconds > 5))
            {
                return;
            }
            // set
            SelectedSession.SetGraph();
            // reset time
            GraphTime = DateTime.Now;
        }
Esempio n. 7
0
        private void OnChangedConnect(HcToolInfo info, ConnectionState state)
        {
            // check tool serial
            if (info.Serial != string.Empty)
            {
                // check mac address
                if (SelectedSession == null || SelectedSession.ToolInfo.Mac != info.Mac)
                {
                    return;
                }
            }
            else
            {
                // set selected tool
                SelectedSession = HCommAir.GetSession(info);
            }


            Invoke(new EventHandler(delegate
            {
                // set state
                lbState.Text = $@"STATE: {state}";
            }));
        }