SSPC-Tester/SSPCTester.Devices/Drivers/Mock/MockSafetyDio.cs

35 lines
992 B
C#
Raw Permalink Normal View History

using Microsoft.Extensions.Logging;
using SSPCTester.Devices.Interfaces;
namespace SSPCTester.Devices.Drivers.Mock;
public sealed class MockSafetyDio : MockDeviceBase, ISafetyDio
{
private readonly bool[] _inputs = new bool[16];
private readonly bool[] _outputs = new bool[16];
public MockSafetyDio(ILogger<MockSafetyDio> logger)
: base(logger, "PCI2312 (Mock)")
{
}
public Task<bool> ReadInputAsync(int channel, CancellationToken ct = default)
{
ValidateChannel(channel);
return Task.FromResult(_inputs[channel]);
}
public Task WriteOutputAsync(int channel, bool on, CancellationToken ct = default)
{
ValidateChannel(channel);
_outputs[channel] = on;
return Task.CompletedTask;
}
private static void ValidateChannel(int channel)
{
if (channel is < 0 or > 15)
throw new ArgumentOutOfRangeException(nameof(channel), channel, "PCI2312 channel must be 0-15.");
}
}