From 5838d0360e562c24d280b225cddb70bc50c2541e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Gimenez?= Date: Sun, 5 May 2024 13:26:11 +0200 Subject: [PATCH] Update to V5.1 --- .../SharedDriver/LogicAnalyzerDriver.cs | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/Software/LogicAnalyzer/SharedDriver/LogicAnalyzerDriver.cs b/Software/LogicAnalyzer/SharedDriver/LogicAnalyzerDriver.cs index 3de4df7..5c051a6 100644 --- a/Software/LogicAnalyzer/SharedDriver/LogicAnalyzerDriver.cs +++ b/Software/LogicAnalyzer/SharedDriver/LogicAnalyzerDriver.cs @@ -84,27 +84,10 @@ namespace SharedDriver baseStream.ReadTimeout = 10000; DeviceVersion = readResponse.ReadLine(); - var verMatch = regVersion.Match(DeviceVersion ?? ""); - - if (verMatch == null || !verMatch.Success || !verMatch.Groups[2].Success) + if (!ValidateVersion()) { Dispose(); - throw new DeviceConnectionException($"Invalid device version V{ (string.IsNullOrWhiteSpace(verMatch?.Value) ? "(unknown)" : verMatch?.Value) }, minimum supported version: V{MAJOR_VERSION}_{MINOR_VERSION}"); - } - - int majorVer = int.Parse(verMatch.Groups[2].Value); - int minorVer = int.Parse(verMatch.Groups[3].Value); - - if (majorVer < MAJOR_VERSION) - { - Dispose(); - throw new DeviceConnectionException($"Invalid device version V{verMatch.Value}, minimum supported version: V{MAJOR_VERSION}_{MINOR_VERSION}"); - } - - if (majorVer == MAJOR_VERSION && minorVer < MINOR_VERSION) - { - Dispose(); - throw new DeviceConnectionException($"Invalid device version V{verMatch.Value}, minimum supported version: V{MAJOR_VERSION}_{MINOR_VERSION}"); + throw new DeviceConnectionException($"Invalid device version {DeviceVersion}, minimum supported version: V{MAJOR_VERSION}_{MINOR_VERSION}"); } baseStream.ReadTimeout = Timeout.Infinite; @@ -139,10 +122,38 @@ namespace SharedDriver baseStream.ReadTimeout = 10000; DeviceVersion = readResponse.ReadLine(); + + if (!ValidateVersion()) + { + Dispose(); + throw new DeviceConnectionException($"Invalid device version {DeviceVersion}, minimum supported version: V{MAJOR_VERSION}_{MINOR_VERSION}"); + } + baseStream.ReadTimeout = Timeout.Infinite; - + isNetwork = true; } + + private bool ValidateVersion() + { + var verMatch = regVersion.Match(DeviceVersion ?? ""); + + if (verMatch == null || !verMatch.Success || !verMatch.Groups[2].Success) + return false; + + int majorVer = int.Parse(verMatch.Groups[2].Value); + int minorVer = int.Parse(verMatch.Groups[3].Value); + + if (majorVer < MAJOR_VERSION) + return false; + + if (majorVer == MAJOR_VERSION && minorVer < MINOR_VERSION) + return false; + + return true; + + } + public unsafe bool SendNetworkConfig(string AccesPointName, string Password, string IPAddress, ushort Port) { if(isNetwork) @@ -525,7 +536,6 @@ namespace SharedDriver readData = null; readData = null; - DeviceVersion = null; CaptureCompleted = null; }