/// <summary> /// This function will add the device to the listOfDevices /// </summary> private void OnDeviceAdded(object sender, NetworkDeviceInformation networkDevice) { OnLogMessageAvailable(NanoDevicesEventSource.Log.DeviceArrival(networkDevice.DeviceId)); _newDevicesCount++; Task.Run(() => { AddDeviceToListAsync(networkDevice); }); }
private void RemoveDeviceFromList(NetworkDeviceInformation networkDevice) { // Removes the device entry from the internal list; therefore the UI var deviceEntry = FindDevice(networkDevice.DeviceId); OnLogMessageAvailable(NanoDevicesEventSource.Log.DeviceDeparture(networkDevice.DeviceId)); _networkDevices.Remove(deviceEntry); // get device... var device = FindNanoFrameworkDevice(networkDevice.DeviceId); // ... and remove it from collection NanoFrameworkDevices.Remove(device); device?.DebugEngine?.StopProcessing(); device?.DebugEngine?.Dispose(); }
/// <summary> /// Remove the device from the device list /// </summary> private void OnDeviceRemoved(object sender, NetworkDeviceInformation networkDevice) { RemoveDeviceFromList(networkDevice); }
/// <summary> /// Creates a DeviceListEntry for a device and adds it to the list of devices /// </summary> private void AddDeviceToListAsync(NetworkDeviceInformation networkDevice) { // search the device list for a device with a matching interface ID var networkMatch = FindDevice(networkDevice.DeviceId); // Add the device if it's new if (networkMatch != null) { return; } OnLogMessageAvailable(NanoDevicesEventSource.Log.CandidateDevice(networkDevice.DeviceId)); // search the nanoFramework device list for a device with a matching interface ID var nanoFrameworkDeviceMatch = FindNanoFrameworkDevice(networkDevice.DeviceId); if (nanoFrameworkDeviceMatch != null) { return; } // Create a new element for this device and... var newNanoFrameworkDevice = new NanoDevice <NanoNetworkDevice>(); newNanoFrameworkDevice.DeviceId = networkDevice.DeviceId; newNanoFrameworkDevice.ConnectionPort = new PortTcpIp(this, newNanoFrameworkDevice, networkDevice); newNanoFrameworkDevice.Transport = TransportType.TcpIp; var connectResult = newNanoFrameworkDevice.ConnectionPort.ConnectDevice(); if (connectResult == ConnectPortResult.Unauthorized) { OnLogMessageAvailable( NanoDevicesEventSource.Log.UnauthorizedAccessToDevice(networkDevice.DeviceId)); } else if (connectResult == ConnectPortResult.Connected) { if (CheckValidNanoFrameworkNetworkDevice(newNanoFrameworkDevice)) { //add device to the collection NanoFrameworkDevices.Add(newNanoFrameworkDevice); _networkDevices.Add(networkDevice); OnLogMessageAvailable( NanoDevicesEventSource.Log.ValidDevice($"{newNanoFrameworkDevice.Description}")); } else { // disconnect newNanoFrameworkDevice.Disconnect(); } } else { OnLogMessageAvailable(NanoDevicesEventSource.Log.QuitDevice(networkDevice.DeviceId)); } // subtract devices count _newDevicesCount--; // check if we are done processing arriving devices if (_newDevicesCount == 0) { ProcessDeviceEnumerationComplete(); } }
public PortTcpIp(PortTcpIpManager portManager, NanoDevice <NanoNetworkDevice> networkDevice, NetworkDeviceInformation deviceInformation) { _portManager = portManager ?? throw new ArgumentNullException(nameof(portManager)); NanoDevice = networkDevice ?? throw new ArgumentNullException(nameof(networkDevice)); NanoDevice.Device.NetworkDeviceInformation = deviceInformation; }