private static void updateTargetsList(object state)
 {
     lock (locker)
     {
         var  devices       = PortDefinition.Enumerate(PortFilter.Usb);
         var  targetsToKeep = new List <MicroFrameworkExecutionTarget>();
         bool changed       = false;
         foreach (var device in devices)
         {
             bool targetExist = false;
             foreach (var target in targets)
             {
                 if (target.PortDefinition.Port == (device as PortDefinition).Port)
                 {
                     targetsToKeep.Add(target);
                     targetExist = true;
                     break;
                 }
             }
             if (!targetExist)
             {
                 changed = true;
                 var newTarget = new MicroFrameworkExecutionTarget(device as PortDefinition);
                 targets.Add(newTarget);
                 targetsToKeep.Add(newTarget);
             }
         }
         changed |= targets.RemoveAll((target) => !targetsToKeep.Contains(target)) > 0;
         if (changed && deviceListChanged != null)
         {
             deviceListChanged(null);
         }
     }
 }
Ejemplo n.º 2
0
 private void Form1_Load(object sender, EventArgs e)
 {
     comboBox1.DataSource  = PortDefinition.Enumerate(PortFilter.Serial);
     comboBox1.ValueMember = "DisplayName";
 }
        public void UpdateList()
        {
            ArrayList list = PortDefinition.Enumerate(m_pf);

            #region Code that should probably be in PortDefinition.Enumerate
            {
                bool enumTcpIpPorts = false;
                foreach (PortFilter pf in m_pf)
                {
                    if (pf == PortFilter.TcpIp)
                    {
                        enumTcpIpPorts = true;
                        break;
                    }
                }
                if (enumTcpIpPorts)
                {
                    list.AddRange(EnumerateTcpIpPorts());
                }
            }
            #endregion

            #region Code that could go in PortDefinition.Enumerate if we add a LauncableEmulator port definition. (Or move PersistableEmulator into a non-VS class?
            {
                bool listLaunchableEmulators = false;
                foreach (PortFilter pf in m_pf)
                {
                    if (pf == PortFilter.Emulator)
                    {
                        listLaunchableEmulators = true;
                        break;
                    }
                }

                if (listLaunchableEmulators == true)
                {
                    PlatformInfo            pi   = new PlatformInfo(null);
                    PlatformInfo.Emulator[] emus = pi.Emulators;

                    foreach (PlatformInfo.Emulator emu in emus)
                    {
                        list.Add(new PortDefinition_Emulator("Launch '" + emu.name + "'", emu.persistableName, 0));
                    }
                }
            }
            #endregion

            object si = SelectedItem;
            base.DataSource = null;
            if (list.Count > 0)
            {
                base.DataSource = list;
                if (list[0] is PortDefinition)
                {
                    base.DisplayMember = "DisplayName";
                }
                if (si != null)
                {
                    SelectedItem = si;
                }
                else
                {
                    base.SelectedIndex = 0;
                }
            }
            else
            {
                base.Text = "<None>";
            }
            base.Update();
        }
Ejemplo n.º 4
0
        internal static PortDefinition GetPort(string device, string transport, string exePath)
        {
            PortFilter[] args = { };
            switch (transport.ToLower())
            {
            case "emulator":
                args   = new PortFilter[] { PortFilter.Emulator };
                device = "emulator";
                PortDefinition pd =
                    PortDefinition.CreateInstanceForEmulator("Launch 'Microsoft Emulator'", "Microsoft", 0);

                PlatformInfo          pi  = new PlatformInfo(null);
                PlatformInfo.Emulator emu = pi.FindEmulator(pd.Port);

                if (emu != null)
                {
                    string onboardFlash = Path.Combine(Path.GetDirectoryName(emu.application), "OnBoardFlash.dat");

                    if (File.Exists(onboardFlash))
                    {
                        try
                        {
                            File.Delete(onboardFlash);
                        }
                        catch
                        {
                        }
                    }
                }


                PortDefinition_Emulator emuport = pd as PortDefinition_Emulator;
                Console.WriteLine("\tLaunching Emulator..");
                Process emuProc = EmulatorLauncher.LaunchEmulator(
                    emuport,
                    true, exePath);
                break;

            case "serial":
                args = new PortFilter[] { PortFilter.Serial };
                break;

            case "tcpip":
                args = new PortFilter[] { PortFilter.TcpIp };
                break;

            case "usb":
                args = new PortFilter[] { PortFilter.Usb };
                break;
            }

            ArrayList list     = new ArrayList();
            int       nRetries = 20;

            while (list.Count == 0 && nRetries-- > 0)
            {
                list = PortDefinition.Enumerate(args);

                if (list.Count > 0)
                {
                    break;
                }

                System.Threading.Thread.Sleep(500);
            }

            PortDefinition port = null;

            foreach (object prt in list)
            {
                port = (PortDefinition)prt;
                if (port.DisplayName.ToLower().Contains(device.ToLower()))
                {
                    break;
                }
                else
                {
                    port = null;
                }
            }

            if (null != port)
            {
                return(port);
            }
            else
            {
                throw new ApplicationException(
                          "Could not find the specified device for the harness to connect to.");
            }
        }