From 21de831ccf5e5c1e5e9b41dbccbd1b41a7a6f974 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Gimenez?= Date: Wed, 1 Mar 2023 08:44:29 +0100 Subject: [PATCH] Updated driver and CLCapture to avoid port blockage under Linux --- Software/LogicAnalyzer/AppConfig.json | 46 +++++++++++++++++++ Software/LogicAnalyzer/CLCapture/Program.cs | 29 ++++++++++-- .../CLCapture/Properties/launchSettings.json | 2 +- .../LogicAnalyzer/LogicAnalyzer.csproj.user | 2 +- .../LogicAnalyzer/MainWindow.axaml.cs | 3 ++ .../SharedDriver/LogicAnalyzerDriver.cs | 12 +++-- 6 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 Software/LogicAnalyzer/AppConfig.json diff --git a/Software/LogicAnalyzer/AppConfig.json b/Software/LogicAnalyzer/AppConfig.json new file mode 100644 index 0000000..8703ba3 --- /dev/null +++ b/Software/LogicAnalyzer/AppConfig.json @@ -0,0 +1,46 @@ +{ + "AppName": "Avalonia.Designer.HostApp, Version=0.10.16.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b", + "WindowSettings": { + "LogicAnalyzer.Dialogs.CreateSamplesDialog": { + "Width": 800.0, + "Height": 600.0, + "Position": { + "$type": "Avalonia.PixelPoint, Avalonia.Visuals", + "X": 0, + "Y": 0 + }, + "WindowState": 0 + }, + "LogicAnalyzer.MainWindow": { + "Width": 1024.0, + "Height": 800.0, + "Position": { + "$type": "Avalonia.PixelPoint, Avalonia.Visuals", + "X": 0, + "Y": 0 + }, + "WindowState": 0 + }, + "LogicAnalyzer.Dialogs.SignalComposerDialog": { + "EditorFontSize": 14.0, + "Width": 640.0, + "Height": 480.0, + "Position": { + "$type": "Avalonia.PixelPoint, Avalonia.Visuals", + "X": 0, + "Y": 0 + }, + "WindowState": 0 + }, + "LogicAnalyzer.Dialogs.MeasureDialog": { + "Width": 400.0, + "Height": 450.0, + "Position": { + "$type": "Avalonia.PixelPoint, Avalonia.Visuals", + "X": 0, + "Y": 0 + }, + "WindowState": 0 + } + } +} \ No newline at end of file diff --git a/Software/LogicAnalyzer/CLCapture/Program.cs b/Software/LogicAnalyzer/CLCapture/Program.cs index a686c1e..4407c27 100644 --- a/Software/LogicAnalyzer/CLCapture/Program.cs +++ b/Software/LogicAnalyzer/CLCapture/Program.cs @@ -9,9 +9,12 @@ using System.Text.RegularExpressions; Regex regAddressPort = new Regex("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\:[0-9]+"); Regex regAddress = new Regex("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+"); +LogicAnalyzerDriver? driver = null; TaskCompletionSource captureCompletedTask; +Console.CancelKeyPress += Console_CancelKeyPress; + return await Parser.Default.ParseArguments(args) .MapResult( async (CLCaptureOptions opts) => await Capture(opts), @@ -144,8 +147,6 @@ async Task Capture(CLCaptureOptions opts) break; } - LogicAnalyzerDriver driver; - Console.WriteLine($"Opening logic analyzer in {opts.AddressPort}..."); try @@ -234,6 +235,12 @@ async Task Capture(CLCaptureOptions opts) var result = await captureCompletedTask.Task; + if (result.Samples == null) + { + Console.WriteLine("Capture aborted."); + return -1; + } + Console.WriteLine("Capture complete, writting output file..."); var file = File.Create(opts.OutputFile); @@ -302,7 +309,7 @@ int Configure(CLNetworkOptions opts) return -1; } - LogicAnalyzerDriver driver; + Console.WriteLine($"Opening logic analyzer in port {opts.SerialPort}..."); @@ -343,4 +350,18 @@ int Configure(CLNetworkOptions opts) void CaptureFinished(CaptureEventArgs e) { captureCompletedTask.SetResult(e); -} \ No newline at end of file +} + +void Console_CancelKeyPress(object? sender, ConsoleCancelEventArgs e) +{ + if (driver != null) + { + try + { + driver.StopCapture(); + driver.Dispose(); + } + catch { } + driver = null; + } +} diff --git a/Software/LogicAnalyzer/CLCapture/Properties/launchSettings.json b/Software/LogicAnalyzer/CLCapture/Properties/launchSettings.json index d61449c..f066825 100644 --- a/Software/LogicAnalyzer/CLCapture/Properties/launchSettings.json +++ b/Software/LogicAnalyzer/CLCapture/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "CLCapture": { "commandName": "Project", - "commandLineArgs": "netconfig" + "commandLineArgs": "capture COM3 1000000 1,2,3,4,5,6,7,8 20 20000 TriggerType:Edge,Channel:1,Value:1 ../test.csv" } } } \ No newline at end of file diff --git a/Software/LogicAnalyzer/LogicAnalyzer/LogicAnalyzer.csproj.user b/Software/LogicAnalyzer/LogicAnalyzer/LogicAnalyzer.csproj.user index 60bd275..58adfad 100644 --- a/Software/LogicAnalyzer/LogicAnalyzer/LogicAnalyzer.csproj.user +++ b/Software/LogicAnalyzer/LogicAnalyzer/LogicAnalyzer.csproj.user @@ -1,6 +1,6 @@  - <_LastSelectedProfileId>C:\Users\geniw\source\repos\LogicAnalyzer\LogicAnalyzer\Properties\PublishProfiles\Linux-Arm64.pubxml + <_LastSelectedProfileId>C:\Users\geniw\source\repos\LogicAnalyzer\LogicAnalyzer\Properties\PublishProfiles\Windows-Arm64.pubxml \ No newline at end of file diff --git a/Software/LogicAnalyzer/LogicAnalyzer/MainWindow.axaml.cs b/Software/LogicAnalyzer/LogicAnalyzer/MainWindow.axaml.cs index 7ea7bd6..2abce6e 100644 --- a/Software/LogicAnalyzer/LogicAnalyzer/MainWindow.axaml.cs +++ b/Software/LogicAnalyzer/LogicAnalyzer/MainWindow.axaml.cs @@ -549,6 +549,9 @@ namespace LogicAnalyzer private void Driver_CaptureCompleted(object? sender, CaptureEventArgs e) { + if (e.Samples == null) + return; + Dispatcher.UIThread.InvokeAsync(() => { sampleViewer.BeginUpdate(); diff --git a/Software/LogicAnalyzer/SharedDriver/LogicAnalyzerDriver.cs b/Software/LogicAnalyzer/SharedDriver/LogicAnalyzerDriver.cs index 6f31cc6..698d39f 100644 --- a/Software/LogicAnalyzer/SharedDriver/LogicAnalyzerDriver.cs +++ b/Software/LogicAnalyzer/SharedDriver/LogicAnalyzerDriver.cs @@ -375,7 +375,13 @@ namespace SharedDriver } catch (Exception ex) { - Console.WriteLine(ex.Message + " - " + ex.StackTrace); + //if(ex.GetType() != typeof(OperationCanceledException)) + // Console.WriteLine(ex.Message + " - " + ex.StackTrace); + + if (currentCaptureHandler != null) + currentCaptureHandler(new CaptureEventArgs { SourceType = isNetwork ? AnalyzerDriverType.Network : AnalyzerDriverType.Serial, Samples = null, ChannelCount = channelCount, TriggerChannel = triggerChannel, PreSamples = preSamples }); + else if (CaptureCompleted != null) + CaptureCompleted(this, new CaptureEventArgs { SourceType = isNetwork ? AnalyzerDriverType.Network : AnalyzerDriverType.Serial, Samples = null, ChannelCount = channelCount, TriggerChannel = triggerChannel, PreSamples = preSamples }); } } public bool StopCapture() @@ -389,7 +395,7 @@ namespace SharedDriver { baseStream.WriteByte(0xff); baseStream.Flush(); - Thread.Sleep(1); + Thread.Sleep(2000); tcpClient.Close(); Thread.Sleep(1); tcpClient = new TcpClient(); @@ -403,7 +409,7 @@ namespace SharedDriver sp.Write(new byte[] { 0xFF }, 0, 1); sp.BaseStream.Flush(); - Thread.Sleep(1); + Thread.Sleep(2000); sp.Close(); Thread.Sleep(1); sp.Open();