private async Task UpdateTargetsList(CancellationToken ct) { var serialPorts = MeadowDeviceManager.FindSerialDevices(); foreach (var port in serialPorts) { if (ct.IsCancellationRequested) { break; } if (Targets.Any(t => t.meadowSerialDevice.connection?.USB?.DevicePort == port)) { continue; } var timeout = Task <MeadowDevice> .Delay(1000); var meadowTask = MeadowDeviceManager.GetMeadowForSerialPort(port); await Task.WhenAny(timeout, meadowTask); var meadow = meadowTask.Result; if (meadow != null) { //we should really just have the execution target own an instance of MeadowDevice Targets.Add(new MeadowDeviceExecutionTarget(meadow)); //meadow.CloseConnection(); DeviceListChanged?.Invoke(null); meadow.StatusChange += StatusDisplay; } } var removeList = new List <MeadowDeviceExecutionTarget>(); foreach (var t in Targets) { if (serialPorts.Any(p => p == t.meadowSerialDevice.connection?.USB?.DevicePort) == false) { removeList.Add(t); } } foreach (var r in removeList) { r.meadowSerialDevice.StatusChange -= StatusDisplay; Targets.Remove(r); DeviceListChanged?.Invoke(null); } }
public void RefreshDeviceList() { MeadowSettings settings = new MeadowSettings(Globals.SettingsFilePath); Devices.Items.Clear(); Devices.Items.Add("Select Target Device Port"); var devices = MeadowDeviceManager.FindSerialDevices(); var selectedIndex = 0; for (int i = 0; i < devices.Count; i++) { if (devices[i] == settings.DeviceTarget) { selectedIndex = i + 1; } Devices.Items.Add(devices[i]); } Devices.SelectedIndex = selectedIndex; }
public async Task DeployAsync(CancellationToken cts, TextWriter outputPaneWriter) { var generalProperties = await this.Properties.GetConfigurationGeneralPropertiesAsync(); var projectDir = await generalProperties.Rule.GetPropertyValueAsync("ProjectDir"); var outputPath = Path.Combine(projectDir, await generalProperties.Rule.GetPropertyValueAsync("OutputPath")); MeadowSettings settings = new MeadowSettings(Globals.SettingsFilePath); if (string.IsNullOrEmpty(settings.DeviceTarget)) { throw new Exception("Device has not been selected. Hit Ctrl+Shift+M to access the Device list."); } var attachedDevices = MeadowDeviceManager.FindSerialDevices(); if (!attachedDevices.Contains(settings.DeviceTarget)) { throw new Exception($"Device on '{settings.DeviceTarget}' is not connected or busy."); } await DeployAppAsync(settings.DeviceTarget, Path.Combine(projectDir, outputPath), outputPaneWriter, cts); }