static async Task TestFileManagerCommands() { var meadow = await MeadowDeviceManager.GetMeadowForSerialPort("COM3"); // request rejected; unknown command //Console.WriteLine("CreateFileSystem"); //await MeadowFileManager.CreateFileSystem(meadow); Console.WriteLine("WriteFileToFlash"); File.WriteAllText(".\\hello_meadow.txt", "test"); await MeadowFileManager.WriteFileToFlash(meadow, @".\\hello_meadow.txt"); // MonoUpdateRt, PartitionFileSystem, MountFileSystem, InitializeFileSystem, CreateFileSystem, FormatFileSystem - do we still need these? Console.WriteLine("ListFiles"); await MeadowFileManager.ListFiles(meadow); Console.WriteLine("ListFilesAndCrcs"); await MeadowFileManager.ListFilesAndCrcs(meadow); Console.WriteLine("DeleteFile"); await MeadowFileManager.DeleteFile(meadow, @"hello_meadow.txt"); Console.WriteLine("ListFiles"); await MeadowFileManager.ListFiles(meadow); //await MeadowFileManager.EraseFlash(meadow); //await MeadowFileManager.VerifyErasedFlash(meadow); }
async Task <bool> InitializeMeadowDevice(MeadowDeviceExecutionTarget target, CancellationTokenSource cts) { if (cts.IsCancellationRequested) { return(true); } target.Write($"Initializing Meadow {target.meadowSerialDevice.connection.ToString()}\n"); if (target.meadowSerialDevice == null) { target.WriteError("Can't read Meadow device\n"); return(false); } Console.WriteLine("MonoDisable"); MeadowDeviceManager.MonoDisable(target.meadowSerialDevice); if (!(await target.meadowSerialDevice.AwaitStatus(5000, MeadowCLI.DeviceManagement.MeadowSerialDevice.DeviceStatus.PortOpen)).HasValue) { target.Write("The Meadow has failed to restart.\n"); return(false); } return(true); }
async Task DeployAppAsync(string target, string folder, IOutputPaneWriter outputPaneWriter, CancellationToken cts) { Stopwatch sw = Stopwatch.StartNew(); await outputPaneWriter.WriteAsync($"Deploying to Meadow on {target}..."); try { var meadow = _currentDevice = await MeadowDeviceManager.GetMeadowForSerialPort(target); EventHandler <MeadowMessageEventArgs> handler = (s, e) => { if (!string.IsNullOrEmpty(e.Message)) { outputPaneWriter.WriteAsync(e.Message).Wait(); } }; await MeadowDeviceManager.MonoDisable(meadow).ConfigureAwait(false); meadow.OnMeadowMessage += handler; await MeadowDeviceManager.DeployApp(meadow, Path.Combine(folder, "App.exe")); meadow.OnMeadowMessage -= handler; await MeadowDeviceManager.MonoEnable(meadow).ConfigureAwait(false); } catch (Exception ex) { throw ex; } sw.Stop(); await outputPaneWriter.WriteAsync($"Deployment Duration: {sw.Elapsed}"); }
async Task DeployAppAsync(string target, string folder, TextWriter outputPaneWriter, CancellationToken cts) { await outputPaneWriter.WriteAsync($"Deploying to Meadow on {target}..."); try { var meadow = MeadowDeviceManager.CurrentDevice; if (meadow == null) { meadow = await MeadowDeviceManager.GetMeadowForSerialPort(target); } if (await InitializeMeadowDeviceAsync(meadow, outputPaneWriter, cts) == false) { throw new Exception("Failed to initialize Meadow. Try resetting or reconnecting the device."); } var meadowFiles = await GetFilesOnDevice(meadow, outputPaneWriter, cts); var localFiles = await GetLocalFiles(outputPaneWriter, cts, folder); await DeleteUnusedFiles(meadow, outputPaneWriter, cts, meadowFiles, localFiles); await DeployApp(meadow, outputPaneWriter, cts, folder, meadowFiles, localFiles); await ResetMeadowAndStartMonoAsync(meadow, outputPaneWriter, cts); } catch (Exception ex) { throw ex; } }
protected void OnRadioMonoDisabledPressed(object sender, EventArgs e) { if (!((Gtk.RadioButton)sender).Active) { MeadowDeviceManager.MonoDisable(meadowSerialDevice); } }
public async Task ReInitializeMeadowAsync(CancellationToken cancellationToken = default) { var serialNumber = DeviceInfo.SerialNumber; string? serialPort = null; IMeadowDevice?meadow = null; if (_meadowDevice is MeadowSerialDevice device) { serialPort = device.SerialPort?.PortName; } _meadowDevice?.Dispose(); await Task.Delay(1000, cancellationToken) .ConfigureAwait(false); //try the old port first, if we still have it if (string.IsNullOrWhiteSpace(serialPort) == false) { meadow = await MeadowDeviceManager.GetMeadowForSerialPort(serialPort !, false, Logger); } meadow ??= await MeadowDeviceManager.FindMeadowBySerialNumber( serialNumber, Logger, cancellationToken : cancellationToken) .ConfigureAwait(false); await Task.Delay(1000, cancellationToken) .ConfigureAwait(false); _meadowDevice = meadow ?? throw new Exception($"Meadow not found. Serial Number {serialNumber}"); }
public void RefreshDeviceList() { MeadowSettings settings = new MeadowSettings(Globals.SettingsFilePath); Devices.Items.Clear(); Devices.Items.Add(new SerialDevice { Caption = "Select Target Device Port" }); Devices.SelectedIndex = 0; var index = 1; var captions = MeadowDeviceManager.GetSerialDeviceCaptions(); foreach (var c in captions.Distinct()) { var port = Regex.Match(c, @"(?<=\().+?(?=\))").Value; Devices.Items.Add(new SerialDevice() { Caption = c, Port = port }); if (port == settings.DeviceTarget) { Devices.SelectedIndex = index; } index++; } }
public async Task DeployApp(int debugPort, CancellationToken cancellationToken) { DeploymentTargetsManager.StopPollingForDevices(); cleanedup = false; meadow?.Dispose(); var target = this.Target as MeadowDeviceExecutionTarget; var device = await MeadowDeviceManager.GetMeadowForSerialPort(target.Port, logger : logger); meadow = new MeadowDeviceHelper(device, device.Logger); var fileNameExe = System.IO.Path.Combine(OutputDirectory, "App.dll"); var debug = debugPort > 1000; await meadow.DeployAppAsync(fileNameExe, debug, cancellationToken); if (debug) { meadowDebugServer = await meadow.StartDebuggingSessionAsync(debugPort, cancellationToken); } else { // sleep until cancel since this is a normal deploy without debug while (!cancellationToken.IsCancellationRequested) { await Task.Delay(1000); } Cleanup(); } }
private protected MeadowSerialCommand(DownloadManager downloadManager, ILoggerFactory loggerFactory, MeadowDeviceManager meadowDeviceManager) : base(downloadManager, loggerFactory) { Logger = loggerFactory.CreateLogger <MeadowSerialCommand>(); MeadowDeviceManager = meadowDeviceManager; }
public override async ValueTask ExecuteAsync(IConsole console) { var cancellationToken = console.RegisterCancellationHandler(); using var device = await MeadowDeviceManager.GetMeadowForSerialPort(SerialPortName, true, cancellationToken).ConfigureAwait(false); await device.MonoDisable(cancellationToken).ConfigureAwait(false); }
public override async ValueTask ExecuteAsync(IConsole console) { var cancellationToken = console.RegisterCancellationHandler(); _logger.LogInformation("Verifying flash"); using var device = await MeadowDeviceManager.GetMeadowForSerialPort(SerialPortName, true, cancellationToken).ConfigureAwait(false); await device.VerifyErasedFlash(cancellationToken).ConfigureAwait(false); }
public override async ValueTask ExecuteAsync(IConsole console) { await base.ExecuteAsync(console); foreach (var port in MeadowDeviceManager.GetSerialPorts()) { _logger.LogInformation("Found Meadow: {port}", port); } }
public override async ValueTask ExecuteAsync(IConsole console) { var cancellationToken = console.RegisterCancellationHandler(); await console.Output.WriteLineAsync("Renewing file system on the Meadow."); using var device = await MeadowDeviceManager.GetMeadowForSerialPort(SerialPortName, true, cancellationToken) .ConfigureAwait(false); await device.RenewFileSystem(cancellationToken : cancellationToken).ConfigureAwait(false); }
static async Task GetFilesAndCrcs() { var meadow = await MeadowDeviceManager.GetMeadowForSerialPort("/dev/tty.usbmodem01"); // MeadowDeviceManager.MonoDisable(meadow); await meadow.SetDeviceInfo(); // var (files, crcs) = await meadow.GetFilesAndCrcs(); // var fileList = await meadow.GetFilesOnDevice(); // Console.WriteLine("File list received"); }
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); } }
private async void Check_Version(object sender, RoutedEventArgs e) { try { if (IsDfuMode()) { await OutputMessageAsync($"Device is in bootloader mode. Connect device in normal mode to check version.", true); return; } EnableControls(false); MeadowSettings settings = new MeadowSettings(Globals.SettingsFilePath); await OutputMessageAsync($"Initialize device (~30s)", true); if (string.IsNullOrEmpty(settings.DeviceTarget)) { await OutputMessageAsync($"Select Target Device Port and click '{Flash_Device_Text}' to resume."); _skipFlashToSelectDevice = true; EnableControls(true); return; } MeadowSerialDevice meadow = null; // initialize connection. need to jump through hoops after exiting dfu mode =( meadow = await MeadowDeviceManager.GetMeadowForSerialPort(settings.DeviceTarget).ConfigureAwait(false); await MeadowDeviceManager.ResetMeadow(meadow).ConfigureAwait(false); await Task.Delay(1000); meadow = await MeadowDeviceManager.GetMeadowForSerialPort(settings.DeviceTarget).ConfigureAwait(false); await MeadowDeviceManager.GetDeviceInfo(meadow); await OutputMessageAsync($"Device {meadow.DeviceInfo.MeadowOSVersion}", true); } catch (Exception ex) { await OutputMessageAsync($"Could not read device version."); } finally { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); EnableControls(true); } }
public async Task MonoEnableTest() { var cts = new CancellationTokenSource(); using var meadow = await MeadowDeviceManager.GetMeadowForSerialPort(port, logger : NullLogger.Instance).ConfigureAwait(false); Assert.IsNotNull(meadow, "Initial connection"); await meadow.MonoEnableAsync(cts.Token); var monoEnabled = await meadow.GetMonoRunStateAsync(cts.Token); Assert.True(monoEnabled, "monoEnabled"); }
internal async void ReceiveVSDebug(MeadowSerialDevice meadow) { // Console.WriteLine("ActiveClient:Start receiving from VS"); try { // Receive from Visual Studio and send to Meadow await Task.Run(async() => { while (tcpClient.Connected && okayToRun) { var recvdBuffer = new byte[490]; var bytesRead = await networkStream.ReadAsync(recvdBuffer, 0, recvdBuffer.Length); if (!okayToRun) { break; } if (bytesRead > 0) { // Console.WriteLine($"{DateTime.Now:HH:mm:ss.fff}-Received {bytesRead} bytes from VS will forward to HCOM"); // Need a buffer the exact size of received data to work with CLI var meadowBuffer = new byte[bytesRead]; Array.Copy(recvdBuffer, 0, meadowBuffer, 0, bytesRead); // Forward to Meadow MeadowDeviceManager.ForwardVisualStudioDataToMono(meadowBuffer, meadow, 0); //Console.WriteLine($"{DateTime.Now:HH:mm:ss.fff}-Forwarded {bytesRead} from VS to Meadow"); } } }); } catch (System.IO.IOException ioe) { // VS client probably died Console.WriteLine(ioe.ToString()); debuggingServer.CloseActiveClient(); } catch (Exception e) { Console.WriteLine(e.ToString()); debuggingServer.CloseActiveClient(); if (okayToRun) { throw; } } }
public override async ValueTask ExecuteAsync(IConsole console) { var cancellationToken = console.RegisterCancellationHandler(); using var device = await MeadowDeviceManager .GetMeadowForSerialPort( SerialPortName, true, cancellationToken) .ConfigureAwait(false); var runState = await device.GetMonoRunState(cancellationToken) .ConfigureAwait(false); _logger.LogInformation($"Mono Run State: {(runState ? "Enabled" : "Disabled")}"); }
public override async ValueTask ExecuteAsync(IConsole console) { var cancellationToken = console.RegisterCancellationHandler(); using var device = await MeadowDeviceManager .GetMeadowForSerialPort( SerialPortName, true, cancellationToken) .ConfigureAwait(false); var deviceName = await device.GetDeviceName(cancellationToken : cancellationToken) .ConfigureAwait(false); _logger.LogInformation($"Device Name: {deviceName}"); }
public override async ValueTask ExecuteAsync(IConsole console) { var cancellationToken = console.RegisterCancellationHandler(); using var device = await MeadowDeviceManager.GetMeadowForSerialPort(SerialPortName, true, cancellationToken).ConfigureAwait(false); var deviceInfoString = await device.GetDeviceInfo(cancellationToken : cancellationToken).ConfigureAwait(false); if (string.IsNullOrWhiteSpace(deviceInfoString)) { throw new Exception("Unable to retrieve device info"); } var deviceInfo = new MeadowDeviceInfo(deviceInfoString); _logger.LogInformation(deviceInfo.ToString()); }
static async Task TestFlashCommands() { Stopwatch sw = new Stopwatch(); string networkBootloaderFilename = "bootloader.bin"; string networkMeadowCommsFilename = "MeadowComms.bin"; string networkPartitionTableFilename = "partition-table.bin"; var meadow = await MeadowDeviceManager.GetMeadowForSerialPort("COM3"); //MeadowSerialDevice meadow = null; for (int i = 0; i < 20; i++) { //meadow = await MeadowDeviceManager.GetMeadowForSerialPort("COM3"); Console.WriteLine("disable"); await MeadowDeviceManager.MonoDisable(meadow); Thread.Sleep(11000); //meadow = await MeadowDeviceManager.GetMeadowForSerialPort("COM3"); Console.WriteLine("enable"); await MeadowDeviceManager.MonoEnable(meadow); Thread.Sleep(11000); } ////await MeadowFileManager.MonoUpdateRt(meadow, @"C:\Users\brikim\AppData\Local\WildernessLabs\Firmware\Meadow.OS.Runtime.bin"); //Console.WriteLine("write runtime"); //await MeadowFileManager.WriteFileToFlash(meadow, @"C:\Users\brikim\AppData\Local\WildernessLabs\Firmware\Meadow.OS.Runtime.bin"); //Console.WriteLine("mono flash"); //sw.Start(); //await MeadowDeviceManager.MonoFlash(meadow); // does not emit `Concluded` //Console.WriteLine($"elapsed: {sw.Elapsed.TotalSeconds}"); //Console.WriteLine($"flash esp: {networkBootloaderFilename}"); //await MeadowFileManager.WriteFileToEspFlash(MeadowDeviceManager.CurrentDevice, Path.Combine(@"C:\Users\brikim\AppData\Local\WildernessLabs\Firmware", networkBootloaderFilename), mcuDestAddr: "0x1000"); //Console.WriteLine($"flash esp: {networkPartitionTableFilename}"); //await MeadowFileManager.WriteFileToEspFlash(MeadowDeviceManager.CurrentDevice, Path.Combine(@"C:\Users\brikim\AppData\Local\WildernessLabs\Firmware", networkPartitionTableFilename), mcuDestAddr: "0x8000"); //Console.WriteLine($"flash esp: {networkMeadowCommsFilename}"); //await MeadowFileManager.WriteFileToEspFlash(MeadowDeviceManager.CurrentDevice, Path.Combine(@"C:\Users\brikim\AppData\Local\WildernessLabs\Firmware", networkMeadowCommsFilename), mcuDestAddr: "0x10000"); }
async Task DeployAppAsync(string target, string folder, IOutputPaneWriter outputPaneWriter, CancellationToken cts) { Stopwatch sw = Stopwatch.StartNew(); await outputPaneWriter.WriteAsync($"Deploying to Meadow on {target}..."); try { var meadow = await MeadowDeviceManager.GetMeadowForSerialPort(target).ConfigureAwait(false); if (meadow == null) { await outputPaneWriter.WriteAsync($"Device connection error, please disconnect device and try again."); return; } await MeadowDeviceManager.ResetMeadow(meadow).ConfigureAwait(false); await Task.Delay(1000); meadow = await MeadowDeviceManager.GetMeadowForSerialPort(target).ConfigureAwait(false); await Task.Delay(1000); await MeadowDeviceManager.MonoDisable(meadow).ConfigureAwait(false); var meadowFiles = await GetFilesOnDevice(meadow, outputPaneWriter, cts).ConfigureAwait(false); var localFiles = await GetLocalFiles(outputPaneWriter, cts, folder).ConfigureAwait(false); await DeleteUnusedFiles(meadow, outputPaneWriter, cts, meadowFiles, localFiles).ConfigureAwait(false); await DeployApp(meadow, outputPaneWriter, cts, folder, meadowFiles, localFiles).ConfigureAwait(false); await MeadowDeviceManager.MonoEnable(meadow).ConfigureAwait(false); } catch (Exception ex) { throw ex; } sw.Stop(); await outputPaneWriter.WriteAsync($"Deployment Duration: {sw.Elapsed}"); }
public async Task FlashOSTest() { //DfuUpload.FlashOS(Path.Combine(fixturesPath.FullName, osFilename)); using (var meadow = await MeadowDeviceManager.GetMeadowForSerialPort(port)) { Assert.IsNotNull(meadow, "Initial connection"); await MeadowDeviceManager.MonoDisable(meadow); var isEnabled = await MeadowDeviceManager.MonoRunState(meadow); // try to disable one more time if (isEnabled) { await MeadowDeviceManager.MonoDisable(meadow); isEnabled = await MeadowDeviceManager.MonoRunState(meadow); } Assert.IsFalse(isEnabled, "Disable mono"); } using (var meadow = await MeadowDeviceManager.GetMeadowForSerialPort(port)) { await MeadowFileManager.MonoUpdateRt(meadow, Path.Combine(fixturesPath.FullName, runtimeFilename)); } using (var meadow = await MeadowDeviceManager.GetMeadowForSerialPort(port)) { await MeadowFileManager.FlashEsp(meadow, fixturesPath.FullName); } using (var meadow = await MeadowDeviceManager.GetMeadowForSerialPort(port)) { Assert.IsNotNull(meadow); await MeadowDeviceManager.MonoEnable(meadow); var isEnabled = await MeadowDeviceManager.MonoRunState(meadow); Assert.IsTrue(isEnabled); } }
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; }
async Task <bool> InitializeMeadowDeviceAsync(MeadowSerialDevice meadow, TextWriter outputPaneWriter, CancellationToken cts) { if (cts.IsCancellationRequested) { return(true); } await outputPaneWriter.WriteAsync("Initializing Meadow"); if (meadow == null) { await outputPaneWriter.WriteAsync("Can't read Meadow device"); return(false); } meadow.Initialize(false); MeadowDeviceManager.MonoDisable(meadow); await Task.Delay(5000); //hack for testing if (meadow.Initialize() == false) { await outputPaneWriter.WriteAsync("Couldn't initialize serial port"); return(false); } else { MeadowDeviceManager.GetDeviceInfo(meadow); await Task.Delay(1000); // wait for device info to populate await outputPaneWriter.WriteAsync($"Device {meadow.DeviceInfo.MeadowOSVersion}"); } return(true); }
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); }
public TraceLevelCommand(DownloadManager downloadManager, ILoggerFactory loggerFactory, MeadowDeviceManager meadowDeviceManager) : base(downloadManager, loggerFactory, meadowDeviceManager) { _logger = LoggerFactory.CreateLogger <TraceLevelCommand>(); }
public VerifyFlashCommand(ILoggerFactory loggerFactory, MeadowDeviceManager meadowDeviceManager) : base(loggerFactory, meadowDeviceManager) { _logger = LoggerFactory.CreateLogger <VerifyFlashCommand>(); }
public RenewFileSystemCommand(DownloadManager downloadManager, ILoggerFactory loggerFactory, MeadowDeviceManager meadowDeviceManager) : base(downloadManager, loggerFactory, meadowDeviceManager) { }