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/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; } 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 37653f1..9eadfaf 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 .