예제 #1
0
 public CorDebugProcess(DebugPort port, PortDefinition portDefinition)
 {
     m_port = port;
     m_portDefinition = portDefinition;
     m_guidProcessId = Guid.NewGuid();
     m_syncTerminatingObject = new object();
 }
 private void SetButtonText()
 {
     if (bwConnecter.IsBusy || m_state == ProfilingState.Connecting)
     {
         buttonConnect.Text  = c_Cancel;
         checkReboot.Enabled = false;
     }
     else if (m_state == ProfilingState.Connected)
     {
         buttonConnect.Text = c_Disconnect;
     }
     else
     {
         _DBG.PortDefinition          port    = comboBoxDevice.PortDefinition;
         _DBG.PortDefinition_Emulator emuPort = port as _DBG.PortDefinition_Emulator;
         if (emuPort != null && emuPort.Pid == 0)
         {
             buttonConnect.Text  = c_Launch;
             checkReboot.Enabled = false;
         }
         else
         {
             buttonConnect.Text  = c_Connect;
             checkReboot.Enabled = true;
         }
     }
 }
예제 #3
0
        public static PortDefinition[] EnumeratePorts()
        {
            SortedList lst = new SortedList();

            // enumerate each guid under the discovery key
            OperatingSystem thisMachine = Environment.OSVersion;

            // Win7 is 6.1, Win8 is 6.2 and up
            System.Version win8_version = new System.Version(6, 2);
            if (thisMachine.Version <= win8_version)
            {
                EnumeratePorts(NETMF_WinUsb_Guid_Win7, lst);
            }
            else
            {
                EnumeratePorts(NETMF_WinUsb_Guid_Win8, lst);
            }

            ICollection col = lst.Values;

            PortDefinition[] res = new PortDefinition[col.Count];

            col.CopyTo(res, 0);

            return(res);
        }
예제 #4
0
        public static PortDefinition[] EnumeratePorts()
        {
            SortedList lst = new SortedList();

            // enumerate each guid under the discovery key
            RegistryKey driverParametersKey = Registry.LocalMachine.OpenSubKey(SpotGuidKeyPath);

            // if no parameters key is found, it means that no USB device has ever been plugged into the host
            // or no driver was installed
            if (driverParametersKey != null)
            {
                string inquiriesInterfaceGuid = (string)driverParametersKey.GetValue(InquiriesInterface);
                string driverVersion          = (string)driverParametersKey.GetValue(DriverVersion);

                if ((inquiriesInterfaceGuid != null) && (driverVersion != null))
                {
                    EnumeratePorts(new Guid(inquiriesInterfaceGuid), driverVersion, lst);
                }
            }

            ICollection col = lst.Values;

            PortDefinition[] res = new PortDefinition[col.Count];

            col.CopyTo(res, 0);

            return(res);
        }
예제 #5
0
        static public PortDefinition[] EnumeratePorts()
        {
            SortedList lst = new SortedList();

            try
            {
                RegistryKey key = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DEVICEMAP\SERIALCOMM");

                foreach (string name in key.GetValueNames())
                {
                    string         val = (string)key.GetValue(name);
                    PortDefinition pd  = PortDefinition.CreateInstanceForSerial(val, @"\\.\" + val, 115200);

                    lst.Add(val, pd);
                }
            }
            catch
            {
            }

            ICollection col = lst.Values;

            PortDefinition[] res = new PortDefinition[col.Count];

            col.CopyTo(res, 0);

            return(res);
        }
예제 #6
0
        public CorDebugProcess EnsureProcess(PortDefinition portDefinition)
        {
            CorDebugProcess process = ProcessFromPortDefinition(portDefinition);

            if (process == null)
            {
                process = new CorDebugProcess(this, portDefinition);

                uint pid;
                if (portDefinition is PortDefinition_Emulator)
                {
                    Debug.Assert(this.IsLocalPort);
                    pid = (uint)((PortDefinition_Emulator)portDefinition).Pid;
                }
                else
                {
                    pid = m_pidNext++;
                }

                process.SetPid(pid);

                AddProcess(process);
            }

            return(process);
        }
예제 #7
0
        internal CorDebugProcess TryAddProcess(string name)
        {
            CorDebugProcess process        = null;
            PortDefinition  portDefinition = null;

            //this is kind of bogus.  How should the attach dialog be organized????

            switch (m_portFilter)
            {
            case PortFilter.TcpIp:
                for (int retry = 0; retry < 5; retry++)
                {
                    try
                    {
                        portDefinition = PortDefinition.CreateInstanceForTcp(name);
                        break;
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        System.Threading.Thread.Sleep(1000);
                    }
                }
                break;
            }

            if (portDefinition != null)
            {
                process = this.EnsureProcess(portDefinition);
            }

            return(process);
        }
예제 #8
0
        public void RemoveProcess(PortDefinition portDefinition)
        {
            CorDebugProcess process = ProcessFromPortDefinition(portDefinition);

            if (process != null)
            {
                RemoveProcess(process);
            }
        }
예제 #9
0
        //--//

        public Gateway(ManagerRemote mgrRemote, _DBG.PortDefinition pd)
        {
            m_mgrRemote      = mgrRemote;
            m_portDefinition = pd;
            m_ctrl           = new _WP.Controller(_WP.Packet.MARKER_PACKET_V1, this);

            m_stubs     = ArrayList.Synchronized(new ArrayList());
            m_endpoints = Hashtable.Synchronized(new Hashtable());
        }
예제 #10
0
        //--//

        public Gateway( ManagerRemote mgrRemote, _DBG.PortDefinition pd )
        {
            m_mgrRemote      = mgrRemote;
            m_portDefinition = pd;
            m_ctrl           = new _WP.Controller( _WP.Packet.MARKER_PACKET_V1, this );

            m_stubs          = ArrayList.Synchronized( new ArrayList() );
            m_endpoints      = Hashtable.Synchronized( new Hashtable() );
        }
예제 #11
0
        public PortDefinition[] GetPersistablePortDefinitions()
        {
            PortDefinition[] ports = null;

            switch (m_portFilter)
            {
            case PortFilter.Emulator:
                Debug.Assert(false);
                break;

            case PortFilter.Serial:
                ports = AsyncSerialStream.EnumeratePorts();
                break;

            case PortFilter.Usb:
            {
                if (MonoDevelop.Core.Platform.IsWindows)
                {
                    PortDefinition[] portUSB;
                    PortDefinition[] portWinUSB;

                    portUSB    = AsyncUsbStream.EnumeratePorts();
                    portWinUSB = WinUsb_AsyncUsbStream.EnumeratePorts();

                    int lenUSB    = portUSB != null ? portUSB.Length : 0;
                    int lenWinUSB = portWinUSB != null ? portWinUSB.Length : 0;

                    ports = new PortDefinition[lenUSB + lenWinUSB];

                    if (lenUSB > 0)
                    {
                        Array.Copy(portUSB, ports, lenUSB);
                    }
                    if (lenWinUSB > 0)
                    {
                        Array.Copy(portWinUSB, 0, ports, lenUSB, lenWinUSB);
                    }
                }
                else
                {
                    ports = LibUsb_AsyncUsbStream.EnumeratePorts();
                }
            }
            break;

            case PortFilter.TcpIp:
                ports = PortDefinition_Tcp.EnumeratePorts(false);
                break;

            default:
                Debug.Assert(false);
                throw new ApplicationException();
            }

            return(ports);
        }
예제 #12
0
        public override bool Equals(object obj)
        {
            PortDefinition pd = obj as PortDefinition; if (pd == null)

            {
                return(false);
            }

            return(pd.UniqueId.Equals(UniqueId));
        }
예제 #13
0
        private CorDebugProcess ProcessFromPortDefinition(PortDefinition portDefinition)
        {
            foreach (CorDebugProcess process in m_alProcesses)
            {
                if (ArePortEntriesEqual(portDefinition, process.PortDefinition))
                {
                    return(process);
                }
            }

            return(null);
        }
        /// <include file='doc\ConnectionManager.uex' path='docs/doc[@for="Manager.Connect"]/*' />
        public _DBG.Engine Connect(_DBG.PortDefinition pd)
        {
            _DBG.Engine eng = new _DBG.Engine();

            GatewayProxy gwp = new GatewayProxy();
            GatewayStub  gws = m_mgr.Connect(pd, gwp);

            gwp.SetOwner(eng);

            eng.SetController(gwp);

            return(eng);
        }
예제 #15
0
        static public PortDefinition CreateInstanceForTcp(string name)
        {
            PortDefinition portDefinition = null;

            //From CorDebug\DebugPort.cs
            string    hostName  = name;
            int       port      = PortDefinition_Tcp.WellKnownPort;
            int       portIndex = hostName.IndexOf(':');
            IPAddress address   = null;

            if (portIndex > 0)
            {
                hostName = name.Substring(0, portIndex);

                if (portIndex < name.Length - 1)
                {
                    string portString = name.Substring(portIndex + 1);

                    int portT;

                    if (int.TryParse(portString, out portT))
                    {
                        port = portT;
                    }
                }
            }

            if (!IPAddress.TryParse(hostName, out address))
            {
                //Does DNS resolution make sense here?

                IPHostEntry iPHostEntry = Dns.GetHostEntry(hostName);

                if (iPHostEntry.AddressList.Length > 0)
                {
                    //choose the first one?
                    address = iPHostEntry.AddressList[0];
                }
            }

            if (address != null)
            {
                IPEndPoint ipEndPoint = new IPEndPoint(address, port);

                portDefinition = new PortDefinition_Tcp(ipEndPoint);

                //ping to see if it is alive?
            }

            return(portDefinition);
        }
        private ArrayList GeneratePortList()
        {
            ArrayList ports = _DBG.PortDefinition.Enumerate(_DBG.PortFilter.Serial, _DBG.PortFilter.Usb);

            foreach (string ip in Settings.Default.TcpIpAddresses.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                _DBG.PortDefinition pd = _DBG.PortDefinition.CreateInstanceForTcp(ip);
                if (pd != null)
                {
                    ports.Add(pd);
                }
            }

            return(ports);
        }
예제 #17
0
 private void groupBoxDevice_Validating(System.Object sender, CancelEventArgs e)
 {
     _DBG.PortDefinition port = comboBoxDevice.PortDefinition;
     if (port == null)
     {
         e.Cancel = true;
         errorProvider.SetError(groupBoxDevice, "Invalid device");
         comboBoxDevice.SelectAll();
         comboBoxDevice.Focus();
     }
     else
     {
         errorProvider.SetError(groupBoxDevice, "");
     }
 }
예제 #18
0
        public void RefreshProcesses()
        {
            PortDefinition[] ports = null;

            switch (m_portFilter)
            {
            case PortFilter.Emulator:
#if USE_CONNECTION_MANAGER
                ports = this.DebugPortSupplier.Manager.EnumeratePorts(m_portFilter);
#else
                ports = Emulator.EnumeratePipes();
#endif
                break;

            case PortFilter.Serial:
            case PortFilter.Usb:
            case PortFilter.TcpIp:
                ports = GetPersistablePortDefinitions();
                break;

            default:
                Debug.Assert(false);
                throw new ApplicationException();
            }

            ArrayList processes = new ArrayList(m_alProcesses.Count + ports.Length);

            for (int i = ports.Length - 1; i >= 0; i--)
            {
                PortDefinition  portDefinition = (PortDefinition)ports[i];
                CorDebugProcess process        = EnsureProcess(portDefinition);

                processes.Add(process);
            }

            for (int i = m_alProcesses.Count - 1; i >= 0; i--)
            {
                CorDebugProcess process = (CorDebugProcess)m_alProcesses[i];

                if (!processes.Contains(process))
                {
                    RemoveProcess(process);
                }
            }
        }
예제 #19
0
        protected static void RetrieveProperties(string hash, ref PortDefinition pd, UsbStream s)
        {
            IDictionaryEnumerator dict;

            dict = s_textProperties.GetEnumerator();

            while (dict.MoveNext())
            {
                pd.Properties.Add(dict.Key, s.RetrieveStringFromDevice((int)dict.Value));
            }

            dict = s_digitProperties.GetEnumerator();

            while (dict.MoveNext())
            {
                pd.Properties.Add(dict.Key, s.RetrieveIntegerFromDevice((int)dict.Value));
            }
        }
예제 #20
0
        private static void RetrieveProperties(string hash, ref PortDefinition pd, AsyncUsbStream s)
        {
            IDictionaryEnumerator dict;

            dict = s_textProperties.GetEnumerator();

            while (dict.MoveNext())
            {
                pd.Properties.Add(dict.Key, s.RetrieveStringFromDevice((int)dict.Value));
            }

            dict = s_digitProperties.GetEnumerator();

            while (dict.MoveNext())
            {
                pd.Properties.Add(dict.Key, s.RetrieveIntegerFromDevice((int)dict.Value));
            }
        }
예제 #21
0
        public DataCollector(string port, string fileName)
        {
            _DBG.PortDefinition pd = null;
            this.port = port;
            uint baudrate = 115200;

            pd = _DBG.PortDefinition.CreateInstanceForSerial(this.port, this.port, baudrate);

            if (pd.TryToOpen())
            {
                UsartStream = pd.Open();

                Console.WriteLine("Opening Port : " + pd.DisplayName.ToString());
            }
            else
            {
                Console.WriteLine("The Port can not be openend");
            }

            inpFile = new BinaryWriter(File.Open(fileName, FileMode.Create));
        }
예제 #22
0
        private bool ArePortEntriesEqual(PortDefinition pd1, PortDefinition pd2)
        {
            if (pd1.Port != pd2.Port)
            {
                return(false);
            }

            if (pd1.GetType() != pd2.GetType())
            {
                return(false);
            }

            if (pd1 is PortDefinition_Emulator && pd2 is PortDefinition_Emulator)
            {
                if (((PortDefinition_Emulator)pd1).Pid != ((PortDefinition_Emulator)pd2).Pid)
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #23
0
        public static PortDefinition[] EnumeratePipes()
        {
            SortedList lst = new SortedList();
            Regex      re  = new Regex("^TinyCLR_([0-9]+)_Port1$");

            try
            {
                String[] pipeNames = Directory.GetFiles(@"\\.\pipe");

                foreach (string pipe in pipeNames)
                {
                    try
                    {
                        if (re.IsMatch(Path.GetFileName(pipe)))
                        {
                            int            pid = Int32.Parse(re.Match(Path.GetFileName(pipe)).Groups[1].Value);
                            PortDefinition pd  = PortDefinition.CreateInstanceForEmulator("Emulator - pid " + pid, pipe, pid);

                            lst.Add(pd.DisplayName, pd);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }

            ICollection col = lst.Values;

            PortDefinition[] res = new PortDefinition[col.Count];

            col.CopyTo(res, 0);

            return(res);
        }
        public GatewayStub Connect(_DBG.PortDefinition pd, GatewayProxy gwp)
        {
            lock (m_gateways)
            {
                object  key = pd.UniqueId;
                Gateway gw  = null;

                if (m_gateways.ContainsKey(key))
                {
                    gw = m_gateways[key];
                }
                else
                {
                    gw = new Gateway(this, pd);

                    ((_WP.IController)gw).Start();

                    m_gateways[key] = gw;
                }

                return(new GatewayStub(gw, gwp));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns>Returns the previous conneciton state of the debugger engine</returns>
        private bool EnsureDebuggerConnection()
        {
            if (m_eng == null)
            {
                _DBG.PortDefinition pd = GetSelectedPortDefinition();

                m_eng = new _DBG.Engine(pd);

                m_eng.OnNoise   += new _DBG.NoiseEventHandler(OnNoise);
                m_eng.OnMessage += new _DBG.MessageEventHandler(OnMessage);

                m_eng.Start();

                m_eng.TryToConnect(5, 100);

                return(false);
            }

            // TryToConnect calls GetCLRCapabilities which prevents a bunch of asserts
            m_eng.TryToConnect(5, 100);

            return(true);
        }
예제 #26
0
        public static PortDefinition[] EnumeratePipes()
        {
            SortedList lst = new SortedList();
            Regex re = new Regex("^TinyCLR_([0-9]+)_Port1$");

            try
            {
                String[] pipeNames = Directory.GetFiles(@"\\.\pipe");

                foreach (string pipe in pipeNames)
                {
                    try
                    {
                        if (re.IsMatch(Path.GetFileName(pipe)))
                        {
                            int pid = Int32.Parse(re.Match(Path.GetFileName(pipe)).Groups[1].Value);
                            PortDefinition pd = PortDefinition.CreateInstanceForEmulator("Emulator - pid " + pid, pipe, pid);

                            lst.Add(pd.DisplayName, pd);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }

            ICollection col = lst.Values;
            PortDefinition[] res = new PortDefinition[col.Count];

            col.CopyTo(res, 0);

            return res;
        }
        private _DBG.PortDefinition GetSelectedPortDefinition()
        {
            _DBG.PortDefinition pd = comboBoxPort.SelectedItem as _DBG.PortDefinition;

            if (pd == null)
            {
                string hostname = (comboBoxPort.SelectedItem != null? comboBoxPort.SelectedItem as string: comboBoxPort.Text);

                pd = _DBG.PortDefinition.CreateInstanceForTcp(hostname);

                if (pd != null)
                {
                    ArrayList ips = new ArrayList(Settings.Default.TcpIpAddresses.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));

                    if (!ips.Contains(hostname))
                    {
                        IList ports = GeneratePortList();

                        Settings.Default.TcpIpAddresses += hostname + ";";
                        Settings.Default.Save();

                        int idx = ports.Add(pd);
                        comboBoxPort.DataSource    = ports;
                        comboBoxPort.SelectedIndex = idx;
                    }
                }
            }

            if (pd is _DBG.PortDefinition_Serial)
            {
                _DBG.PortDefinition_Serial pds = (_DBG.PortDefinition_Serial)pd;

                pds.BaudRate = uint.Parse((string)comboBoxBaud.SelectedItem);
            }

            return(pd);
        }
예제 #28
0
        private CorDebugProcess InternalGetDeviceProcess(string deviceName)
        {
            CorDebugProcess process = null;

            RefreshProcesses();

            for (int i = 0; i < m_alProcesses.Count; i++)
            {
                CorDebugProcess processT = (CorDebugProcess)m_alProcesses[i];
                PortDefinition  pd       = processT.PortDefinition;
                if (String.Compare(GetDeviceName(pd), deviceName, true) == 0)
                {
                    process = processT;
                    break;
                }
            }

            if (m_portFilter == PortFilter.TcpIp && process == null)
            {
                process = EnsureProcess(PortDefinition.CreateInstanceForTcp(deviceName));
            }

            return(process);
        }
예제 #29
0
        private void InitializeDeployDevice(PortDefinition selected)
        {
            //What about EmulatorExe????

            int       iSelected = -1;
            DebugPort port      = this.SelectedDeployPort;

            if (port == null)
            {
                return;
            }

            PortDefinition[] portDefinitions;

            if (port.IsLocalPort)
            {
                PlatformInfo platformInfo = this.VsProjectFlavorCfg.PlatformInfo;

                PlatformInfo.Emulator[] emulators = platformInfo.Emulators;

                portDefinitions = new PortDefinition[emulators.Length];

                for (int i = 0; i < emulators.Length; i++)
                {
                    portDefinitions[i] = new PlatformInfo.PortDefinition_PeristableEmulator(emulators[i]);
                }
            }
            else
            {
                portDefinitions = port.GetPersistablePortDefinitions();
            }

            m_cbDeployDevice.Items.Clear();

            for (int iPortDefinition = 0; iPortDefinition < portDefinitions.Length; iPortDefinition++)
            {
                PortDefinition pd = portDefinitions[iPortDefinition];

                ComboBoxItemDevice cbi = new ComboBoxItemDevice(pd);
                m_cbDeployDevice.Items.Add(cbi);

                if (Object.Equals(selected, pd))
                {
                    iSelected = m_cbDeployDevice.Items.Count - 1;
                }
            }

            if (m_cbDeployDevice.Items.Count == 0)
            {
                if (selected != null && port.PortFilter == PortFilter.TcpIp && selected is PortDefinition_Tcp)
                {
                    m_cbDeployDevice.Items.Add(new ComboBoxItemDevice(selected));
                }
                else
                {
                    ComboBoxItemDevice cbi = new ComboBoxItemDevice("<none>");
                    m_cbDeployDevice.Items.Insert(0, cbi);
                }
                iSelected = 0;
            }

            if (port.PortFilter != PortFilter.TcpIp)
            {
                iSelected = 0;
            }

            if (iSelected != -1)
            {
                m_cbDeployDevice.SelectedIndex = iSelected;
            }
        }
예제 #30
0
        /// <summary>
        /// Attempt to establish a connection with TinyBooter (with reboot if necessary)
        /// </summary>
        /// <returns>true connection was made, false otherwise</returns>
        public bool ConnectToTinyBooter()
        {
            bool ret = false;

            if (m_eng == null)
            {
                _DBG.PortDefinition pd = m_portTinyBooter;

                try
                {
                    if (m_eng == null)
                    {
                        m_eng = new _DBG.Engine(pd);

                        m_eng.OnNoise   += new _DBG.NoiseEventHandler(OnNoiseHandler);
                        m_eng.OnMessage += new _DBG.MessageEventHandler(OnMessage);

                        m_eng.Start();
                        m_eng.TryToConnect(5, 100, true, _DBG.ConnectionSource.Unknown);
                    }
                }
                catch
                {
                }
            }


            if (m_eng != null)
            {
                if (m_eng.ConnectionSource == _DBG.ConnectionSource.TinyBooter)
                {
                    return(true);
                }

                m_eng.RebootDevice(_DBG.Engine.RebootOption.EnterBootloader);

                // tinyBooter is only com port so
                if (m_port is _DBG.PortDefinition_Tcp)
                {
                    Disconnect();

                    m_port = m_portTinyBooter;

                    // digi takes forever to reset
                    if (!Connect(60000, true))
                    {
                        Console.WriteLine(Properties.Resources.ErrorUnableToConnectToTinyBooterSerial);
                        return(false);
                    }
                }
                bool fConnected = false;
                for (int i = 0; i < 40; i++)
                {
                    if (EventCancel.WaitOne(0, false))
                    {
                        throw new MFUserExitException();
                    }

                    if (fConnected = m_eng.TryToConnect(0, 500, true, _DBG.ConnectionSource.Unknown))
                    {
                        _WP.Commands.Monitor_Ping.Reply reply = m_eng.GetConnectionSource();
                        ret = (reply.m_source == _WP.Commands.Monitor_Ping.c_Ping_Source_TinyBooter);

                        break;
                    }
                }
                if (!fConnected)
                {
                    Console.WriteLine(Properties.Resources.ErrorUnableToConnectToTinyBooter);
                }
            }
            return(ret);
        }
예제 #31
0
        internal bool Connect(int timeout_ms, bool tryConnect)
        {
            // to use user cancel event, so that cancel button is more responsive
            int retries = timeout_ms / 100;
            int loops   = 1;

            if (retries == 0)
            {
                retries = 1;
            }

            if (m_portTinyBooter != null && m_port.UniqueId != m_portTinyBooter.UniqueId)
            {
                retries /= 2;
                loops    = 2;
            }
            for (int i = 0; i < loops; i++)
            {
                _DBG.PortDefinition pd = i == 0 ? m_port : m_portTinyBooter;

                if (EventCancel.WaitOne(0, false))
                {
                    throw new MFUserExitException();
                }

                try
                {
                    if (m_eng == null)
                    {
                        m_eng = new _DBG.Engine(pd);

                        m_eng.OnNoise   += new _DBG.NoiseEventHandler(OnNoiseHandler);
                        m_eng.OnMessage += new _DBG.MessageEventHandler(OnMessage);
                    }

                    if (!m_eng.IsConnected)
                    {
                        m_eng.Start();
                        if (tryConnect)
                        {
                            for (int j = retries; j > 0; j -= 5)
                            {
                                if (m_eng.TryToConnect(5, 100, true, _DBG.ConnectionSource.Unknown))
                                {
                                    //UNLOCK DEVICE in secure way?
                                    m_eng.UnlockDevice(m_data);
                                    break;
                                }

                                if (EventCancel.WaitOne(0, false))
                                {
                                    throw new MFUserExitException();
                                }
                            }
                            if (m_eng.IsConnected)
                            {
                                break;
                            }
                            else
                            {
                                Disconnect();
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                catch (MFUserExitException)
                {
                    Disconnect();
                    throw;
                }
                catch
                {
                    Disconnect();
                }
            }
            return(m_eng != null && (!tryConnect || m_eng.IsConnected));
        }
예제 #32
0
 internal MFDevice(_DBG.PortDefinition port, _DBG.PortDefinition tinyBooterPort)
 {
     m_port           = port;
     m_portTinyBooter = tinyBooterPort;
 }
예제 #33
0
파일: Streams.cs 프로젝트: prabby/miniclr
        public static PortDefinition[] EnumeratePorts()
        {
            SortedList lst = new SortedList();

            // enumerate each guid under the discovery key
            RegistryKey driverParametersKey = Registry.LocalMachine.OpenSubKey( SpotGuidKeyPath );

            // if no parameters key is found, it means that no USB device has ever been plugged into the host 
            // or no driver was installed
            if(driverParametersKey != null)
            {
                string inquiriesInterfaceGuid   = (string)driverParametersKey.GetValue( InquiriesInterface   );
                string driverVersion            = (string)driverParametersKey.GetValue( DriverVersion        );
            
                if((inquiriesInterfaceGuid != null) && (driverVersion != null))
                {
                    EnumeratePorts( new Guid( inquiriesInterfaceGuid ), driverVersion, lst ); 
                }
            }

            ICollection      col = lst.Values;
            PortDefinition[] res = new PortDefinition[col.Count];

            col.CopyTo( res, 0 );

            return res;
        }
예제 #34
0
 public string GetDeviceName(PortDefinition pd)
 {
     return pd.PersistName;
 }
예제 #35
0
        public void RemoveProcess(PortDefinition portDefinition)
        {
            CorDebugProcess process = ProcessFromPortDefinition(portDefinition);

            if (process != null)
            {
                RemoveProcess(process);
            }
        }
예제 #36
0
        private CorDebugProcess ProcessFromPortDefinition(PortDefinition portDefinition)
        {
            foreach (CorDebugProcess process in m_alProcesses)
            {
                if (ArePortEntriesEqual(portDefinition, process.PortDefinition))
                    return process;
            }

            return null;
        }
예제 #37
0
        static public PortDefinition[] EnumeratePorts()
        {
            SortedList lst = new SortedList();

			string[] portNames = System.IO.Ports.SerialPort.GetPortNames();
			for (int iPortName = 0; iPortName < portNames.Length; iPortName++)
			{
				lst.Add(portNames[iPortName], PortDefinition.CreateInstanceForSerial(portNames[iPortName], portNames[iPortName], 115200));
			}
			
            /* NOTE: on Mac OS X, the SerialPort.GetPortNames() function does not return any values.
			 *       For now (on Mac OS X), it is necessary to manually add serial port entries. 
			 *       Here are some sample serial port definition entries. */
            //lst.Add("/dev/tty.KeySerial1", PortDefinition.CreateInstanceForSerial("/dev/tty.KeySerial1", "/dev/tty.KeySerial1", 115200));
			//lst.Add("/dev/ttyUSB0", PortDefinition.CreateInstanceForSerial("/dev/ttyUSB0", "/dev/ttyUSB0", 115200));
			//lst.Add("COM2", PortDefinition.CreateInstanceForSerial("COM2", "COM2", 115200));

            ICollection      col = lst.Values;
            PortDefinition[] res = new PortDefinition[col.Count];

            col.CopyTo( res, 0 );

            return res;
        }
예제 #38
0
 private void comboBoxPort_SelectionChangeCommitted(object sender, System.EventArgs e)
 {
     m_lastValid = GetSelectedPortDefinition() as _DBG.PortDefinition;
     comboBoxBaud.Enabled = (m_lastValid is _DBG.PortDefinition_Serial);
 }
예제 #39
0
            //emulator stuff

            public ComboBoxItemDevice(PortDefinition pd)
                : base(pd.DisplayName, pd.PersistName, pd is PortDefinition_Tcp)
            {
                m_pd = pd;
            }
        private void InitializeLocal(PortDefinition pd)
        {
            m_portDefinition = pd;
            m_ctrl = new WireProtocol.Controller(WireProtocol.Packet.MARKER_PACKET_V1, this);

            Initialize();
        }
예제 #41
0
        public CorDebugProcess EnsureProcess(PortDefinition portDefinition)
        {
            CorDebugProcess process = ProcessFromPortDefinition(portDefinition);            

            if (process == null)
            {
                process = new CorDebugProcess(this, portDefinition);

                uint pid;
                if (portDefinition is PortDefinition_Emulator)
                {
                    Debug.Assert(this.IsLocalPort);
                    pid = (uint)((PortDefinition_Emulator)portDefinition).Pid;
                }
                else
                {
                    pid = m_pidNext++;
                }

                process.SetPid(pid);

                AddProcess(process);
            }

            return process;
        }
예제 #42
0
        private MFDevice InitializePorts(MFPortDefinition portDefinitionMain, MFPortDefinition portDefinitionTinyBooter)
        {
            MFDevice device = null;

            MFPortDefinition[] portDefs = new MFPortDefinition[2] {
                portDefinitionMain, portDefinitionTinyBooter
            };
            _DBG.PortDefinition[] pds = new Microsoft.SPOT.Debugger.PortDefinition[2];

            for (int i = 0; i < portDefs.Length; i++)
            {
                MFPortDefinition portDefinition = portDefs[i];
                if (portDefinition == null)
                {
                    continue;
                }

                if (portDefinition.Transport == TransportType.TCPIP)
                {
                    System.Net.IPAddress[] addr = System.Net.Dns.GetHostAddresses(portDefinition.Port);

                    pds[i] = new Microsoft.SPOT.Debugger.PortDefinition_Tcp(addr[0]);
                }
                else
                {
                    ArrayList list = _DBG.PortDefinition.Enumerate(_DBG.PortFilter.Usb, _DBG.PortFilter.Serial);
                    foreach (_DBG.PortDefinition pd in list)
                    {
                        if (portDefinition.Port.Length > 0)
                        {
                            if (string.Equals(portDefinition.Port, pd.UniqueId.ToString()))
                            {
                                pds[i] = pd;
                                break;
                            }
                        }
                        if (string.Equals(portDefinition.Name, pd.DisplayName))
                        {
                            pds[i] = pd;
                            break;
                        }
                    }
                }
            }

            if (pds[0] == null && pds[1] != null)
            {
                pds[0] = pds[1];
                pds[1] = null;
            }

            if (pds[0] != null || pds[1] != null)
            {
                device = new MFDevice(pds[0], pds[1]);

                if (!device.Connect(2000, m_tryConnect))
                {
                    throw new MFDeviceNoResponseException();
                }
            }
            else
            {
                throw new MFDeviceUnknownDeviceException();
            }

            return(device);
        }
예제 #43
0
        public PortDefinition[] GetPersistablePortDefinitions()
        {
            PortDefinition[] ports = null;

            switch (m_portFilter)
            {
                case PortFilter.Emulator:
                    Debug.Assert(false);
                    break;
                case PortFilter.Serial:
                    ports = AsyncSerialStream.EnumeratePorts();
                    break;
                case PortFilter.Usb:
                    {
                        PortDefinition []portUSB;
                        PortDefinition []portWinUSB;
                        
                        portUSB    = AsyncUsbStream.EnumeratePorts();
                        portWinUSB = WinUsb_AsyncUsbStream.EnumeratePorts(EnablePermiscuousWinUSB);

                        int lenUSB    = portUSB    != null ? portUSB.Length    : 0;
                        int lenWinUSB = portWinUSB != null ? portWinUSB.Length : 0;

                        ports = new PortDefinition[lenUSB + lenWinUSB];

                        if(lenUSB > 0)
                        {
                            Array.Copy(portUSB, ports, lenUSB);
                        }
                        if(lenWinUSB > 0)
                        {
                            Array.Copy(portWinUSB, 0, ports, lenUSB, lenWinUSB);
                        }
                    }
                    break;
                case PortFilter.TcpIp:
                    ports = PortDefinition_Tcp.EnumeratePorts(false);
                    break;         
                default:
                    Debug.Assert(false);
                    throw new ApplicationException();
            }

            return ports;
        }
        private void InitializeDeployDevice( Debugger.PortDefinition selected)
        {
            //What about EmulatorExe????

            int iSelected = -1;
            DebugPort port = this.SelectedDeployPort;

            if (port == null)
                return;

            PortDefinition[] portDefinitions;

            if (port.IsLocalPort)
            {
                PlatformInfo platformInfo = this.VsProjectFlavorCfg.PlatformInfo;

                PlatformInfo.Emulator[] emulators = platformInfo.Emulators;

                portDefinitions = new PortDefinition[emulators.Length];

                for (int i = 0; i < emulators.Length; i++)
                {
                    portDefinitions[i] = new PlatformInfo.PortDefinition_PeristableEmulator(emulators[i]);
                }
            }
            else
            {
                portDefinitions = port.GetPersistablePortDefinitions();
            }

            m_cbDeployDevice.Items.Clear();

            for (int iPortDefinition = 0; iPortDefinition < portDefinitions.Length; iPortDefinition++)
            {
                PortDefinition pd = portDefinitions[iPortDefinition];

                ComboBoxItemDevice cbi = new ComboBoxItemDevice(pd);
                m_cbDeployDevice.Items.Add(cbi);

                if (Object.Equals(selected, pd))
                {
                    iSelected = m_cbDeployDevice.Items.Count - 1;
                }
            }

            if (m_cbDeployDevice.Items.Count == 0)
            {
                if(selected != null && port.PortFilter == PortFilter.TcpIp && selected is PortDefinition_Tcp)
                {
                    m_cbDeployDevice.Items.Add(new ComboBoxItemDevice(selected));
                }
                else
                {
                    ComboBoxItemDevice cbi = new ComboBoxItemDevice("<none>");
                    m_cbDeployDevice.Items.Insert(0, cbi);
                }
                iSelected = 0;
            }

            if(port.PortFilter != PortFilter.TcpIp)
            {
                iSelected = 0;
            }

            if(iSelected != -1)
            {
                m_cbDeployDevice.SelectedIndex = iSelected;
            }
                
        }
예제 #45
0
 private bool ArePortEntriesEqual(PortDefinition pd1, PortDefinition pd2)
 {
     if (pd1.Port != pd2.Port) 
         return false;
     
     if (pd1.GetType() != pd2.GetType()) 
         return false;
     
     if (pd1 is PortDefinition_Emulator && pd2 is PortDefinition_Emulator)
     {
         if (((PortDefinition_Emulator) pd1).Pid != ((PortDefinition_Emulator) pd2).Pid) 
             return false;
     }
     
     return true;
 }
예제 #46
0
        public static PortDefinition[] EnumeratePorts()
        {
            SortedList lst = new SortedList();
            ICollection col = lst.Values;
            PortDefinition[] res = new PortDefinition[col.Count];

            col.CopyTo(res, 0);

            return res;
        }
 public Engine(PortDefinition pd)
 {
     InitializeLocal(pd);
 }
예제 #48
0
파일: MFDevice.cs 프로젝트: prabby/miniclr
 internal MFDevice(_DBG.PortDefinition port, _DBG.PortDefinition tinyBooterPort)
 {
     m_port = port;
     m_portTinyBooter = tinyBooterPort;
 }
        public static PortDefinition[] EnumeratePipes()
        {
            SortedList lst = new SortedList();
            Regex re = new Regex("^TinyCLR_([0-9]+)_Port1$");

            try
            {
                DirectoryInfo di = new DirectoryInfo(@"\\.\pipe");

                foreach (FileInfo fi in di.GetFiles())
                {
                    try
                    {
                        if (re.IsMatch(fi.Name))
                        {
                            int pid = Int32.Parse(re.Match(fi.Name).Groups[1].Value);
                            PortDefinition pd = PortDefinition.CreateInstanceForEmulator("Emulator - pid " + pid, fi.FullName, pid);

                            lst.Add(pd.DisplayName, pd);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }

            ICollection col = lst.Values;
            PortDefinition[] res = new PortDefinition[col.Count];

            col.CopyTo(res, 0);

            return res;
        }
예제 #50
0
파일: MFDevice.cs 프로젝트: prabby/miniclr
        /// <summary>
        /// Attempt to establish a connection with TinyBooter (with reboot if necessary)
        /// </summary>
        /// <returns>true connection was made, false otherwise</returns>
        public bool ConnectToTinyBooter()
        {
            bool ret = false;

            if (m_eng == null)
            {
                _DBG.PortDefinition pd = m_portTinyBooter;

                try
                {
                    if (m_eng == null)
                    {
                        m_eng = new _DBG.Engine(pd);

                        m_eng.OnNoise += new _DBG.NoiseEventHandler(OnNoiseHandler);
                        m_eng.OnMessage += new _DBG.MessageEventHandler(OnMessage);

                        m_eng.Start();
                        m_eng.TryToConnect(5, 100, true, _DBG.ConnectionSource.Unknown);
                    }
                }
                catch
                {
                }
            }


            if (m_eng != null)
            {
                if (m_eng.ConnectionSource == _DBG.ConnectionSource.TinyBooter) return true;

                m_eng.RebootDevice(_DBG.Engine.RebootOption.EnterBootloader);

                // tinyBooter is only com port so
                if (m_port is _DBG.PortDefinition_Tcp)
                {
                    Disconnect();

                    m_port = m_portTinyBooter;

                    // digi takes forever to reset
                    if (!Connect(60000, true))
                    {
                        Console.WriteLine(Properties.Resources.ErrorUnableToConnectToTinyBooterSerial);
                        return false;
                    }
                }
                bool fConnected = false;
                for(int i = 0; i<40; i++)
                {
                    if (EventCancel.WaitOne(0, false)) throw new MFUserExitException();

                    if (fConnected = m_eng.TryToConnect(0, 500, true, _DBG.ConnectionSource.Unknown))
                    {
                        _WP.Commands.Monitor_Ping.Reply reply = m_eng.GetConnectionSource();
                        ret = (reply.m_source == _WP.Commands.Monitor_Ping.c_Ping_Source_TinyBooter);

                        break;
                    }
                }
                if(!fConnected)
                {
                    Console.WriteLine(Properties.Resources.ErrorUnableToConnectToTinyBooter);
                }
            }
            return ret;
        }
예제 #51
0
파일: Streams.cs 프로젝트: prabby/miniclr
        static public PortDefinition[] EnumeratePorts()
        {
            SortedList lst = new SortedList();

            try
            {
                RegistryKey key = Registry.LocalMachine.OpenSubKey( @"HARDWARE\DEVICEMAP\SERIALCOMM" );

                foreach(string name in key.GetValueNames())
                {
                    string         val = (string)key.GetValue( name );
                    PortDefinition pd  = PortDefinition.CreateInstanceForSerial( val, @"\\.\" + val, 115200 );

                    lst.Add( val, pd );
                }
            }
            catch
            {
            }

            ICollection      col = lst.Values;
            PortDefinition[] res = new PortDefinition[col.Count];

            col.CopyTo( res, 0 );

            return res;
        }
            //emulator stuff

            public ComboBoxItemDevice( Debugger.PortDefinition pd)
                : base(pd.DisplayName, pd.PersistName, pd is PortDefinition_Tcp)
            {
                m_pd = pd;
            }
예제 #53
0
 private void Form1_Load( object sender, EventArgs e )
 {
     comboBoxPort.DisplayMember = "DisplayName";
     comboBoxPort.DataSource = GeneratePortList();
     m_lastValid = comboBoxPort.SelectedItem as _DBG.PortDefinition;
 }
예제 #54
0
파일: MFDeploy.cs 프로젝트: prabby/miniclr
        private MFDevice InitializePorts(MFPortDefinition portDefinitionMain, MFPortDefinition portDefinitionTinyBooter)
        {
            MFDevice device = null;
            MFPortDefinition[] portDefs = new MFPortDefinition[2] { portDefinitionMain, portDefinitionTinyBooter };
            _DBG.PortDefinition[] pds = new Microsoft.SPOT.Debugger.PortDefinition[2];

            for (int i = 0;i < portDefs.Length;i++)
            {
                MFPortDefinition portDefinition = portDefs[i];
                if (portDefinition == null) continue;

                if (portDefinition.Transport == TransportType.TCPIP)
                {
                    System.Net.IPAddress[] addr = System.Net.Dns.GetHostAddresses(portDefinition.Port);

                    pds[i] = new Microsoft.SPOT.Debugger.PortDefinition_Tcp(addr[0]);
                }
                else
                {
                    ArrayList list = _DBG.PortDefinition.Enumerate(_DBG.PortFilter.Usb, _DBG.PortFilter.Serial);
                    foreach (_DBG.PortDefinition pd in list)
                    {
                        if (portDefinition.Port.Length > 0)
                        {
                            if (string.Equals(portDefinition.Port, pd.UniqueId.ToString()))
                            {
                                pds[i] = pd;
                                break;
                            }
                        }
                        if (string.Equals(portDefinition.Name, pd.DisplayName))
                        {
                            pds[i] = pd;
                            break;
                        }
                    }
                }
            }

            if (pds[0] == null && pds[1] != null)
            {
                pds[0] = pds[1];
                pds[1] = null;
            }

            if (pds[0] != null || pds[1] != null)
            {
                device = new MFDevice(pds[0], pds[1]);

                if (!device.Connect(2000, m_tryConnect))
                {
                    throw new MFDeviceNoResponseException();
                }
            }
            else
            {
                throw new MFDeviceUnknownDeviceException();
            }

            return device;
        }
예제 #55
0
		public static PortDefinition[] EnumeratePorts()
		{
			SortedList lst = new SortedList();

			// enumerate each guid under the discovery key
			OperatingSystem thisMachine = Environment.OSVersion;

			// Win7 is 6.1, Win8 is 6.2 and up
			System.Version win8_version = new System.Version(6, 2);
			if(thisMachine.Version <= win8_version)
			{
				EnumeratePorts(NETMF_WinUsb_Guid_Win7, lst);
			}
			else
			{
				EnumeratePorts(NETMF_WinUsb_Guid_Win8, lst);
			}

			ICollection col = lst.Values;
			PortDefinition[] res = new PortDefinition[col.Count];

			col.CopyTo(res, 0);

			return res;
		}
		public MicroFrameworkExecutionTarget(PortDefinition portDefinition)
		{
			this.PortDefinition = portDefinition;
		}