public void setupConnection(Action <String> startMethod, System.Windows.Forms.ComboBox cbo, configHandler cfg)
        {
            Object[] arrayPorts = null;
            int      startPort  = -1;
            String   setting    = cfg.readSetting("Port", "*");

            using (var searcher = new ManagementObjectSearcher("SELECT * FROM WIN32_SerialPort"))
            {
                string[] portnames = SerialPort.GetPortNames();
                var      ports     = searcher.Get().Cast <ManagementBaseObject>().ToList();
                arrayPorts = (from n in portnames join p in ports on n equals p["DeviceID"].ToString() select p["Caption"]).ToArray();
            }
            cbo.Items.AddRange(arrayPorts);

            if (setting != "*")
            {
                for (int j = 0; j < SerialPort.GetPortNames().Length; j++)
                {
                    if (SerialPort.GetPortNames()[j].Equals(setting))
                    {
                        try
                        {
                            startMethod(setting);
                            startPort = j;
                        }
                        catch {
                            cfg.writeSetting("Port", "*");
                        }
                    }
                }
                if (startPort == -1)
                {
                    cfg.writeSetting("Port", "*");
                }
            }
            else
            {
                for (int i = 0; i < cbo.Items.Count; i++)
                {
                    if (cbo.Items[i].ToString().Contains("Arduino"))
                    {
                        String port = Regex.Match(cbo.Items[i].ToString(), @"\(([^)]*)\)").Groups[1].Value;
                        console("Found Arduino On Port: " + port);
                        startMethod(port);

                        for (int j = 0; j < SerialPort.GetPortNames().Length; j++)
                        {
                            if (SerialPort.GetPortNames()[j].Equals(port))
                            {
                                startPort = j;
                            }
                        }

                        break;
                    }
                }
            }
            cbo.SelectedIndex = startPort;
        }
 private void estimateFuel(TelemetryInfo telem)
 {
     if (prevFuel != 0)
     {
         double usg = prevFuel - telem.FuelLevel.Value;
         double tmp = (fuelEst * fuelLaps) + usg;
         fuelLaps += 1;
         fuelEst   = tmp / fuelLaps;
         cfg.writeSetting(track + "-" + car, Convert.ToString(fuelEst));
         cfg.writeSetting(track + "-" + car + "-l", Convert.ToString(fuelLaps));
         //console("Recalculate Fuel Usage per Lap to: " + fuelEst);
     }
     prevFuel = telem.FuelLevel.Value;
 }
        public void setupConnection(Action<String> startMethod, System.Windows.Forms.ComboBox cbo, configHandler cfg)
        {
            Object[] arrayPorts = null;
            int startPort = -1;
            String setting = cfg.readSetting("Port", "*");
            using (var searcher = new ManagementObjectSearcher("SELECT * FROM WIN32_SerialPort"))
            {
                string[] portnames = SerialPort.GetPortNames();
                var ports = searcher.Get().Cast<ManagementBaseObject>().ToList();
                arrayPorts = (from n in portnames join p in ports on n equals p["DeviceID"].ToString() select p["Caption"]).ToArray();
            }
            cbo.Items.Add("Local");
            cbo.Items.AddRange(arrayPorts);

            if (setting != "*")
            {
                if (setting == "Local")
                {
                    startMethod(setting);
                }
                else
                {
                    for (int j = 0; j < SerialPort.GetPortNames().Length; j++)
                    {
                        if (SerialPort.GetPortNames()[j].Equals(setting))
                        {
                            try
                            {
                                startMethod(setting);
                                startPort = j;
                            }
                            catch
                            {
                                cfg.writeSetting("Port", "*");
                            }
                        }
                    }
                    if (startPort == -1)
                        cfg.writeSetting("Port", "*");
                }
            }
            else
            {
                for (int i = 0; i < cbo.Items.Count; i++)
                {
                    if (cbo.Items[i].ToString().Contains("Arduino"))
                    {
                        String port = Regex.Match(cbo.Items[i].ToString(), @"\(([^)]*)\)").Groups[1].Value;
                        console("Found Arduino On Port: " + port);
                        startMethod(port);

                        for (int j = 0; j < SerialPort.GetPortNames().Length; j++)
                        {
                            if (SerialPort.GetPortNames()[j].Equals(port))
                                startPort = j;
                        }

                        break;
                    }
                }
            }
            cbo.SelectedIndex = startPort + 1;
        }