コード例 #1
0
        public bool SelectDevice(string deviceId = null)
        {
            NanoDeviceBase device = null;

            if (deviceId != null)
            {
                // check if this device is available
                device = DebugClient.NanoFrameworkDevices.FirstOrDefault(d => d.Description == deviceId);
            }

            Device = device;

            // has we'll be needing the debugger engine anyway, create it if needed
            if (device != null)
            {
                if (device.DebugEngine == null)
                {
                    device.CreateDebugEngine();
                }
            }

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Connects the debugger to the device
        /// </summary>
        /// <param name="comPort">COM-Port name</param>
        /// <returns>true if connected successfully</returns>
        public bool Connect(string comPort)
        {
            if (_portBase == null)
            {
                _portBase = PortBase.CreateInstanceForSerial("");
            }

            // wait until all devices are found
            while (!_portBase.IsDevicesEnumerationComplete)
            {
                Thread.Sleep(100);
            }

            // get the NanoFramework device list
            IList nanoFrameworkDevices = _portBase.NanoFrameworkDevices;

            if (nanoFrameworkDevices.Count == 0)
            {
                return(false);
            }
            // iterate through the NanoFramework device list
            NanoDeviceBase nanoFrameworkDeviceForConnection = null;

            foreach (NanoDeviceBase nanoFrameworkDevice in nanoFrameworkDevices)
            {
                // does the description contains the delivered port name?
                if (nanoFrameworkDevice.Description.ToUpperInvariant().Contains(comPort.ToUpperInvariant()))
                {
                    // device found
                    nanoFrameworkDeviceForConnection = nanoFrameworkDevice;
                    break;
                }
            }
            // device not found?
            if (nanoFrameworkDeviceForConnection == null)
            {
                return(false);
            }

            // get the DebugEngine
            _engine = nanoFrameworkDeviceForConnection.DebugEngine;
            // if null create the DebugEngine get the DebugEngine again
            if (_engine == null)
            {
                nanoFrameworkDeviceForConnection.CreateDebugEngine();
                _engine = nanoFrameworkDeviceForConnection.DebugEngine;
            }
            if (_engine == null)
            {
                return(false);
            }
            // connect the nanoFramework debugger to the device
            bool result = _engine.ConnectAsync(5000).Result;

            // connected?
            if (result)
            {
                // add the OnMessage event handler and store the device instance for later use
                _engine.OnMessage += OnMessage;
                _connectedDevice   = nanoFrameworkDeviceForConnection;
            }
            return(result);
        }