From 060d05ebce1e6f31f351b767c626e326d0493c3c Mon Sep 17 00:00:00 2001 From: Tyler Kron Date: Sun, 29 Mar 2026 09:42:59 -0600 Subject: [PATCH 1/2] fix: re-enable LAN after stopping SD card logging StartSdCardLoggingAsync disables LAN (SD card and WiFi share the SPI bus), but StopSdCardLoggingAsync never re-enabled it. This left WiFi/LAN silently disabled after SD logging was stopped. Every other SD operation (GetSdCardFilesAsync, DeleteSdCardFileAsync, DownloadSdCardFileAsync) correctly restored LAN in their finally blocks via PrepareLanInterface(). Co-Authored-By: Claude Opus 4.6 Entire-Checkpoint: a0fb8798807b --- src/Daqifi.Core.Tests/Device/SdCard/SdCardOperationsTests.cs | 3 ++- src/Daqifi.Core/Device/DaqifiStreamingDevice.cs | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Daqifi.Core.Tests/Device/SdCard/SdCardOperationsTests.cs b/src/Daqifi.Core.Tests/Device/SdCard/SdCardOperationsTests.cs index 14f42f0..ed93566 100644 --- a/src/Daqifi.Core.Tests/Device/SdCard/SdCardOperationsTests.cs +++ b/src/Daqifi.Core.Tests/Device/SdCard/SdCardOperationsTests.cs @@ -197,10 +197,11 @@ public async Task StopSdCardLoggingAsync_SendsCorrectCommands() // Assert var sentCommands = device.SentMessages.Select(m => m.Data).ToList(); - Assert.Equal(3, sentCommands.Count); + Assert.Equal(4, sentCommands.Count); Assert.Equal("SYSTem:StopStreamData", sentCommands[0]); Assert.Equal("SYSTem:STORage:SD:ENAble 0", sentCommands[1]); Assert.Equal("SYSTem:STReam:INTerface 0", sentCommands[2]); // Restore USB + Assert.Equal("SYSTem:COMMunicate:LAN:ENAbled 1", sentCommands[3]); // Re-enable LAN } [Fact] diff --git a/src/Daqifi.Core/Device/DaqifiStreamingDevice.cs b/src/Daqifi.Core/Device/DaqifiStreamingDevice.cs index a4cd405..e562afb 100644 --- a/src/Daqifi.Core/Device/DaqifiStreamingDevice.cs +++ b/src/Daqifi.Core/Device/DaqifiStreamingDevice.cs @@ -461,6 +461,10 @@ public Task StopSdCardLoggingAsync(CancellationToken cancellationToken = default Send(ScpiMessageProducer.SetStreamInterface(StreamInterface.Usb)); } + // Re-enable LAN interface. StartSdCardLoggingAsync disables LAN because + // the SD card and WiFi/LAN share the SPI bus on the hardware. + Send(ScpiMessageProducer.EnableNetworkLan); + _isLoggingToSdCard = false; return Task.CompletedTask; From 97d83af45ecc401f693cf6c786961354fe375b85 Mon Sep 17 00:00:00 2001 From: Tyler Kron Date: Fri, 3 Apr 2026 22:05:04 -0600 Subject: [PATCH 2/2] fix: defensively send stop-stream command in StopSdCardLoggingAsync StopStreaming() is a no-op when IsStreaming is false, but IsStreaming can be stale (issue #118). Other SD operations already use the defensive pattern of unconditionally sending the stop command. Apply the same pattern here and add a test verifying the command is sent even when IsStreaming is false. Co-Authored-By: Claude Opus 4.6 --- .../Device/SdCard/SdCardOperationsTests.cs | 18 ++++++++++++++++++ .../Device/DaqifiStreamingDevice.cs | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Daqifi.Core.Tests/Device/SdCard/SdCardOperationsTests.cs b/src/Daqifi.Core.Tests/Device/SdCard/SdCardOperationsTests.cs index ed93566..75f5ba0 100644 --- a/src/Daqifi.Core.Tests/Device/SdCard/SdCardOperationsTests.cs +++ b/src/Daqifi.Core.Tests/Device/SdCard/SdCardOperationsTests.cs @@ -204,6 +204,24 @@ public async Task StopSdCardLoggingAsync_SendsCorrectCommands() Assert.Equal("SYSTem:COMMunicate:LAN:ENAbled 1", sentCommands[3]); // Re-enable LAN } + [Fact] + public async Task StopSdCardLoggingAsync_SendsStopCommandEvenWhenIsStreamingIsFalse() + { + // Arrange - simulate stale IsStreaming state (see issue #118) + var device = new TestableSdCardStreamingDevice("TestDevice"); + device.Connect(); + await device.StartSdCardLoggingAsync("test.bin"); + device.StopStreaming(); // Sets IsStreaming = false + device.SentMessages.Clear(); + + // Act + await device.StopSdCardLoggingAsync(); + + // Assert - stop command should still be sent defensively + var sentCommands = device.SentMessages.Select(m => m.Data).ToList(); + Assert.Contains("SYSTem:StopStreamData", sentCommands); + } + [Fact] public async Task StopSdCardLoggingAsync_SetsIsLoggingToFalse() { diff --git a/src/Daqifi.Core/Device/DaqifiStreamingDevice.cs b/src/Daqifi.Core/Device/DaqifiStreamingDevice.cs index e562afb..37653f1 100644 --- a/src/Daqifi.Core/Device/DaqifiStreamingDevice.cs +++ b/src/Daqifi.Core/Device/DaqifiStreamingDevice.cs @@ -452,7 +452,10 @@ public Task StopSdCardLoggingAsync(CancellationToken cancellationToken = default cancellationToken.ThrowIfCancellationRequested(); - StopStreaming(); + // Defensive: always send stop command even if IsStreaming is stale (see issue #118) + Send(ScpiMessageProducer.StopStreaming); + IsStreaming = false; + Send(ScpiMessageProducer.DisableStorageSd); // Restore stream interface to USB so subsequent non-SD operations work.