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."); } }