Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions docs/DEVICE_INTERFACES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
```
Expand Down
4 changes: 2 additions & 2 deletions docs/simulator/GITHUB_ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ Implement TCP server for data connections and SCPI command processing, enabling
- `SYSTem:ECHO <-1|1>`
- `SYSTem:StartStreamData <freq>`
- `SYSTem:StopStreamData`
- `ENAble:VOLTage:DC <binary_string>`
- `ENAble:VOLTage:DC <decimal_bitmask>`
- [ ] Integrate TCP server with `DeviceSimulator.StartAsync()`
- [ ] Write integration tests with `DaqifiDevice` and `TcpStreamTransport`

Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions docs/simulator/SIMULATOR_DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ SYSTem:STReam:FORmat <0|1|2>
SYSTem:STReam:FORmat?

# Configuration
ENAble:VOLTage:DC <binary_string>
ENAble:VOLTage:DC <decimal_bitmask>

# Digital I/O
DIO:PORt:DIRection <ch>,<dir>
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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<DaqifiOutMessage>();
Expand Down
4 changes: 2 additions & 2 deletions docs/simulator/SIMULATOR_IMPLEMENTATION_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
27 changes: 13 additions & 14 deletions src/Daqifi.Core/Communication/Producers/ScpiMessageProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,24 +316,23 @@ public static IOutboundMessage<string> StartStreaming(int frequency)
public static IOutboundMessage<string> GetStreamFormat => new ScpiMessage("SYSTem:STReam:FORmat?");

/// <summary>
/// Creates a command message to enable ADC channels using a binary string.
/// Creates a command message to enable ADC channels using a decimal bitmask.
/// </summary>
/// <param name="channelSetString">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.</param>
/// <param name="channelSetString">A decimal integer string representing a bitmask where each bit enables a channel. For example, "84" (0b1010100) enables channels 2, 4, and 6.</param>
/// <remarks>
/// 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
/// <code>
/// // 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"));
/// </code>
/// </remarks>
public static IOutboundMessage<string> EnableAdcChannels(string channelSetString)
Expand Down
3 changes: 2 additions & 1 deletion src/Daqifi.Core/Device/DaqifiStreamingDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ public async Task<IReadOnlyList<SdCardFileInfo>> GetSdCardFilesAsync(Cancellatio
/// (.bin for Protobuf, .json for JSON, .dat for TestData).
/// </param>
/// <param name="channelMask">
/// 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.
/// </param>
/// <param name="format">The logging format to use. Defaults to <see cref="SdCardLogFormat.Protobuf"/>.</param>
Expand Down
3 changes: 2 additions & 1 deletion src/Daqifi.Core/Device/SdCard/ISdCardOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public interface ISdCardOperations
/// (.bin for Protobuf, .json for JSON, .dat for TestData).
/// </param>
/// <param name="channelMask">
/// 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.
/// </param>
/// <param name="format">The logging format to use. Defaults to <see cref="SdCardLogFormat.Protobuf"/>.</param>
Expand Down
Loading