From cd64e711f5501a1d9ffa4dbe8b77ece59cef660d Mon Sep 17 00:00:00 2001 From: Tyler Kron Date: Sun, 29 Mar 2026 09:54:31 -0600 Subject: [PATCH 1/2] fix: correct EnableAdcChannels docs from binary to decimal bitmask The firmware's SCPI_ADCChanEnableSet parses the ENAble:VOLTage:DC parameter as a decimal integer via SCPI_ParamInt32, but the docs and examples showed binary strings like "0000000011". This mismatch meant any caller following the documented examples would send the wrong channel configuration (e.g. "11" instead of "3" for channels 0+1). Updated XML docs, README, and DEVICE_INTERFACES.md to show decimal bitmask values. Updated the test to use a decimal example. Co-Authored-By: Claude Opus 4.6 Entire-Checkpoint: a0fb8798807b --- README.md | 2 +- docs/DEVICE_INTERFACES.md | 8 +++--- .../Producers/ScpiMessageProducerTests.cs | 4 +-- .../Producers/ScpiMessageProducer.cs | 27 +++++++++---------- .../Device/DaqifiStreamingDevice.cs | 3 ++- .../Device/SdCard/ISdCardOperations.cs | 3 ++- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 2aba1b8..ddf73ca 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ device.MessageReceived += (sender, e) => }; // Configure channels and start streaming -device.Send(ScpiMessageProducer.EnableAdcChannels("0000000011")); // Enable first 2 channels +device.Send(ScpiMessageProducer.EnableAdcChannels("3")); // Enable first 2 channels (bitmask 0b11 = 3) device.Send(ScpiMessageProducer.StartStreaming(100)); // 100 Hz sample rate await Task.Delay(TimeSpan.FromSeconds(10)); // Stream for 10 seconds diff --git a/docs/DEVICE_INTERFACES.md b/docs/DEVICE_INTERFACES.md index 563ae94..e658e21 100644 --- a/docs/DEVICE_INTERFACES.md +++ b/docs/DEVICE_INTERFACES.md @@ -28,7 +28,7 @@ device.MessageReceived += (sender, e) => }; // Configure channels and start streaming -device.Send(ScpiMessageProducer.EnableAdcChannels("0000000011")); // Enable first 2 channels +device.Send(ScpiMessageProducer.EnableAdcChannels("3")); // Enable first 2 channels (bitmask 0b11 = 3) device.Send(ScpiMessageProducer.StartStreaming(100)); // 100 Hz sample rate await Task.Delay(TimeSpan.FromSeconds(10)); // Stream for 10 seconds @@ -226,8 +226,8 @@ device.MessageReceived += (sender, e) => } }; -// Enable channels (binary mask: 1 = enabled) -device.Send(ScpiMessageProducer.EnableAdcChannels("0000000011")); // Channels 0 and 1 +// Enable channels (decimal bitmask: each bit enables a channel) +device.Send(ScpiMessageProducer.EnableAdcChannels("3")); // Channels 0 and 1 (bitmask 0b11 = 3) // Start streaming at 100 Hz device.Send(ScpiMessageProducer.StartStreaming(100)); @@ -255,7 +255,7 @@ device.Send(ScpiMessageProducer.StartStreaming(1000)); // Start at 1000 Hz device.Send(ScpiMessageProducer.StopStreaming); // Channel configuration -device.Send(ScpiMessageProducer.EnableAdcChannels("11111111")); // Enable 8 channels +device.Send(ScpiMessageProducer.EnableAdcChannels("255")); // Enable 8 channels (bitmask 0xFF = 255) device.Send(ScpiMessageProducer.DisableDeviceEcho); device.Send(ScpiMessageProducer.SetProtobufStreamFormat); ``` diff --git a/src/Daqifi.Core.Tests/Communication/Producers/ScpiMessageProducerTests.cs b/src/Daqifi.Core.Tests/Communication/Producers/ScpiMessageProducerTests.cs index 5e2df84..cad79ab 100644 --- a/src/Daqifi.Core.Tests/Communication/Producers/ScpiMessageProducerTests.cs +++ b/src/Daqifi.Core.Tests/Communication/Producers/ScpiMessageProducerTests.cs @@ -151,8 +151,8 @@ public void GetStreamFormat_ReturnsCorrectCommand() [Fact] public void EnableAdcChannels_ReturnsCorrectCommand() { - var message = ScpiMessageProducer.EnableAdcChannels("0001010100"); - Assert.Equal("ENAble:VOLTage:DC 0001010100", message.Data); + var message = ScpiMessageProducer.EnableAdcChannels("84"); + Assert.Equal("ENAble:VOLTage:DC 84", message.Data); AssertMessageFormat(message); } diff --git a/src/Daqifi.Core/Communication/Producers/ScpiMessageProducer.cs b/src/Daqifi.Core/Communication/Producers/ScpiMessageProducer.cs index de0baa5..cc8e07e 100644 --- a/src/Daqifi.Core/Communication/Producers/ScpiMessageProducer.cs +++ b/src/Daqifi.Core/Communication/Producers/ScpiMessageProducer.cs @@ -316,24 +316,23 @@ public static IOutboundMessage StartStreaming(int frequency) public static IOutboundMessage GetStreamFormat => new ScpiMessage("SYSTem:STReam:FORmat?"); /// - /// Creates a command message to enable ADC channels using a binary string. + /// Creates a command message to enable ADC channels using a decimal bitmask. /// - /// A binary string where each character represents a channel (0 = disabled, 1 = enabled), right-to-left. For example, "0001010100" enables channels 2, 4, and 6. + /// A decimal integer string representing a bitmask where each bit enables a channel. For example, "84" (0b1010100) enables channels 2, 4, and 6. /// - /// The binary string is read from right to left, where position 0 is the rightmost bit: - /// - Position 0: Channel 0 - /// - Position 1: Channel 1 - /// - Position 2: Channel 2 + /// The firmware parses this value as a decimal integer and interprets it as a bitmask: + /// - Bit 0 (value 1): Channel 0 + /// - Bit 1 (value 2): Channel 1 + /// - Bit 2 (value 4): Channel 2 /// etc. - /// - /// Command: ENAble:VOLTage:DC binaryString - /// Example: + /// + /// Command: ENAble:VOLTage:DC decimalMask /// - /// // Enable channels 2, 4, and 6 - /// messageProducer.Send(ScpiMessageProducer.EnableAdcChannels("0001010100")); - /// - /// // Enable channels 0 and 1 - /// messageProducer.Send(ScpiMessageProducer.EnableAdcChannels("0000000011")); + /// // Enable channels 2, 4, and 6 (bitmask = 4 + 16 + 64 = 84) + /// device.Send(ScpiMessageProducer.EnableAdcChannels("84")); + /// + /// // Enable channels 0 and 1 (bitmask = 1 + 2 = 3) + /// device.Send(ScpiMessageProducer.EnableAdcChannels("3")); /// /// public static IOutboundMessage EnableAdcChannels(string channelSetString) diff --git a/src/Daqifi.Core/Device/DaqifiStreamingDevice.cs b/src/Daqifi.Core/Device/DaqifiStreamingDevice.cs index a4cd405..8d2e8bf 100644 --- a/src/Daqifi.Core/Device/DaqifiStreamingDevice.cs +++ b/src/Daqifi.Core/Device/DaqifiStreamingDevice.cs @@ -366,7 +366,8 @@ public async Task> GetSdCardFilesAsync(Cancellatio /// (.bin for Protobuf, .json for JSON, .dat for TestData). /// /// - /// Optional binary string mask to enable specific ADC channels (e.g. "0000000011" enables channels 0 and 1). + /// Optional decimal bitmask string to enable specific ADC channels (e.g. "3" enables channels 0 and 1). + /// The firmware parses this as a decimal integer where each bit enables a channel. /// If null or empty, the current device channel configuration is used. /// /// The logging format to use. Defaults to . diff --git a/src/Daqifi.Core/Device/SdCard/ISdCardOperations.cs b/src/Daqifi.Core/Device/SdCard/ISdCardOperations.cs index d2abd7d..4f9dded 100644 --- a/src/Daqifi.Core/Device/SdCard/ISdCardOperations.cs +++ b/src/Daqifi.Core/Device/SdCard/ISdCardOperations.cs @@ -40,7 +40,8 @@ public interface ISdCardOperations /// (.bin for Protobuf, .json for JSON, .dat for TestData). /// /// - /// Optional binary string mask to enable specific ADC channels (e.g. "0000000011" enables channels 0 and 1). + /// Optional decimal bitmask string to enable specific ADC channels (e.g. "3" enables channels 0 and 1). + /// The firmware parses this as a decimal integer where each bit enables a channel. /// If null or empty, the current device channel configuration is used. /// /// The logging format to use. Defaults to . From e741afe227eb420614c489fc496ff3975ed5d70b Mon Sep 17 00:00:00 2001 From: Tyler Kron Date: Fri, 3 Apr 2026 22:10:09 -0600 Subject: [PATCH 2/2] fix: update simulator docs from binary string to decimal bitmask format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses Qodo review feedback — simulator docs still referenced binary string format for ENAble:VOLTage:DC while core docs were updated to decimal. Co-Authored-By: Claude Opus 4.6 --- docs/simulator/GITHUB_ISSUES.md | 4 ++-- docs/simulator/SIMULATOR_DESIGN.md | 6 +++--- docs/simulator/SIMULATOR_IMPLEMENTATION_PLAN.md | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/simulator/GITHUB_ISSUES.md b/docs/simulator/GITHUB_ISSUES.md index 4fbe2d2..91b2e43 100644 --- a/docs/simulator/GITHUB_ISSUES.md +++ b/docs/simulator/GITHUB_ISSUES.md @@ -261,7 +261,7 @@ Implement TCP server for data connections and SCPI command processing, enabling - `SYSTem:ECHO <-1|1>` - `SYSTem:StartStreamData ` - `SYSTem:StopStreamData` - - `ENAble:VOLTage:DC ` + - `ENAble:VOLTage:DC ` - [ ] Integrate TCP server with `DeviceSimulator.StartAsync()` - [ ] Write integration tests with `DaqifiDevice` and `TcpStreamTransport` @@ -279,7 +279,7 @@ Implement TCP server for data connections and SCPI command processing, enabling **Example**: ``` -Client: "ENAble:VOLTage:DC 0000000011\r\n" +Client: "ENAble:VOLTage:DC 3\r\n" Server: (no response) Client: "SYSTem:SYSInfoPB?\r\n" diff --git a/docs/simulator/SIMULATOR_DESIGN.md b/docs/simulator/SIMULATOR_DESIGN.md index 2a37627..abcde2e 100644 --- a/docs/simulator/SIMULATOR_DESIGN.md +++ b/docs/simulator/SIMULATOR_DESIGN.md @@ -151,7 +151,7 @@ SYSTem:STReam:FORmat <0|1|2> SYSTem:STReam:FORmat? # Configuration -ENAble:VOLTage:DC +ENAble:VOLTage:DC # Digital I/O DIO:PORt:DIRection , @@ -282,7 +282,7 @@ Length-delimited DaqifiOutMessage containing: **Example Exchange**: ``` -Client -> Server: "ENAble:VOLTage:DC 0000000011\r\n" +Client -> Server: "ENAble:VOLTage:DC 3\r\n" Server -> Client: (no response) Client -> Server: "SYSTem:StartStreamData 100\r\n" @@ -412,7 +412,7 @@ public async Task CanConnectAndStreamData() device.Connect(); // Configure channels - device.Send(ScpiMessageProducer.EnableAnalogChannels("0000000011")); + device.Send(ScpiMessageProducer.EnableAdcChannels("3")); // 0b11 = channels 0,1 // Start streaming var messagesReceived = new List(); diff --git a/docs/simulator/SIMULATOR_IMPLEMENTATION_PLAN.md b/docs/simulator/SIMULATOR_IMPLEMENTATION_PLAN.md index 8c03fd2..081356e 100644 --- a/docs/simulator/SIMULATOR_IMPLEMENTATION_PLAN.md +++ b/docs/simulator/SIMULATOR_IMPLEMENTATION_PLAN.md @@ -583,8 +583,8 @@ internal class ScpiCommandProcessor // Channel configuration else if (command.StartsWith("enable:voltage:dc ")) { - var binaryString = command.Split(' ')[1]; - var mask = Convert.ToUInt32(binaryString, 2); + var maskString = command.Split(' ')[1]; + var mask = Convert.ToUInt32(maskString); _device.SetChannelMask(mask); return null; }