2026-07-01 20:04:27 +08:00
|
|
|
|
using SSPCTester.Devices.Interfaces;
|
|
|
|
|
|
|
2026-06-30 12:10:29 +08:00
|
|
|
|
namespace SSPCTester.Devices.Config;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根设备配置节点。对应 appsettings.json 中的 "Devices" 段。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public sealed class DeviceOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
public const string SectionName = "Devices";
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>旧版全局开关,仅用于兼容读取旧配置。</summary>
|
|
|
|
|
|
public bool MockMode { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public SspcOptions Sspc { get; set; } = new();
|
|
|
|
|
|
public PowerSupplyOptions PowerSupply { get; set; } = new();
|
|
|
|
|
|
public LoadOptions Load { get; set; } = new();
|
|
|
|
|
|
public DaqOptions Daq { get; set; } = new();
|
2026-07-01 20:04:27 +08:00
|
|
|
|
public Pci2312Options Pci2312 { get; set; } = new();
|
2026-06-30 12:10:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// SSPC(24 路 = 3 模块 × 8 路)的串口与 Modbus 配置。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public sealed class SspcOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool UseMock { get; set; }
|
|
|
|
|
|
public bool AutoConnect { get; set; } = true;
|
|
|
|
|
|
public string PortName { get; set; } = "COM1";
|
|
|
|
|
|
public int BaudRate { get; set; } = 9600;
|
|
|
|
|
|
public int DataBits { get; set; } = 8;
|
|
|
|
|
|
public string Parity { get; set; } = "None";
|
|
|
|
|
|
public string StopBits { get; set; } = "One";
|
|
|
|
|
|
|
|
|
|
|
|
public int ReadTimeoutMs { get; set; } = 500;
|
|
|
|
|
|
public int Retry { get; set; } = 2;
|
|
|
|
|
|
public string DeviceProfilePath { get; set; } = "Config/device-profile.json";
|
|
|
|
|
|
public bool CloseAllRelaysOnDisconnect { get; set; }
|
|
|
|
|
|
public bool LogRawFrames { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
|
|
// 旧字段保留用于兼容历史 appsettings,业务通道数固定为 24。
|
|
|
|
|
|
public byte[] ModuleAddresses { get; set; } = new byte[] { 1, 2, 3 };
|
|
|
|
|
|
public int ChannelsPerModule { get; set; } = 8;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public sealed class PowerSupplyOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool UseMock { get; set; }
|
|
|
|
|
|
public bool AutoConnect { get; set; } = true;
|
|
|
|
|
|
public string PortName { get; set; } = "COM2";
|
|
|
|
|
|
public int BaudRate { get; set; } = 9600;
|
|
|
|
|
|
public string Host { get; set; } = "192.168.6.5";
|
|
|
|
|
|
public int Port { get; set; } = 5025;
|
|
|
|
|
|
public double TimeoutSeconds { get; set; } = 2;
|
|
|
|
|
|
public bool RequirePingBeforeConnect { get; set; } = true;
|
|
|
|
|
|
public string Terminator { get; set; } = "\n";
|
|
|
|
|
|
public string IdnCommand { get; set; } = "*IDN?";
|
|
|
|
|
|
public string VoltageCommand { get; set; } = "MEASure:VOLTage?";
|
|
|
|
|
|
public string CurrentCommand { get; set; } = "MEASure:CURRent?";
|
2026-07-12 12:07:41 +08:00
|
|
|
|
public string SetVoltageCommand { get; set; } = "VOLT {0}";
|
|
|
|
|
|
public string SetCurrentLimitCommand { get; set; } = "CURR {0}";
|
|
|
|
|
|
public string OutputStateCommand { get; set; } = "OUTP?";
|
|
|
|
|
|
public string ErrorCommand { get; set; } = "SYST:ERR?";
|
2026-06-30 12:10:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public enum LoadQueryMode
|
|
|
|
|
|
{
|
|
|
|
|
|
Combined,
|
|
|
|
|
|
Separate
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public sealed class LoadOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool UseMock { get; set; }
|
|
|
|
|
|
public bool AutoConnect { get; set; } = true;
|
|
|
|
|
|
public string PortName { get; set; } = "COM3";
|
|
|
|
|
|
public int BaudRate { get; set; } = 9600;
|
|
|
|
|
|
public string Host { get; set; } = "192.168.200.100";
|
|
|
|
|
|
public int Port { get; set; } = 30000;
|
|
|
|
|
|
public double TimeoutSeconds { get; set; } = 3;
|
|
|
|
|
|
public string Terminator { get; set; } = "\n";
|
|
|
|
|
|
public int Channel { get; set; } = 1;
|
|
|
|
|
|
public bool UseFetch { get; set; } = true;
|
|
|
|
|
|
public LoadQueryMode QueryMode { get; set; } = LoadQueryMode.Combined;
|
2026-07-12 12:07:41 +08:00
|
|
|
|
public string SetModeCommand { get; set; } = "";
|
|
|
|
|
|
public string SetValueCommand { get; set; } = "{0} {1}";
|
|
|
|
|
|
public string ResetCommand { get; set; } = "*RST";
|
|
|
|
|
|
public string InputStateCommand { get; set; } = "INP?";
|
|
|
|
|
|
public string ErrorCommand { get; set; } = "SYST:ERR?";
|
2026-06-30 12:10:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public sealed class DaqOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool UseMock { get; set; }
|
|
|
|
|
|
public bool AutoConnect { get; set; } = true;
|
|
|
|
|
|
public int LogicalDeviceId { get; set; }
|
|
|
|
|
|
public int ChannelCount { get; set; } = 1;
|
|
|
|
|
|
public string InputRange { get; set; } = "PlusMinus5V";
|
|
|
|
|
|
public int ClockDivider { get; set; } = 1_000;
|
2026-07-01 20:04:27 +08:00
|
|
|
|
public double PreTriggerMs { get; set; } = 3;
|
|
|
|
|
|
public double PostTriggerMs { get; set; } = 100;
|
2026-06-30 12:10:29 +08:00
|
|
|
|
public List<DaqChannelOptions> Channels { get; set; } =
|
|
|
|
|
|
Enumerable.Range(0, 8).Select(i => new DaqChannelOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
PhysicalChannel = i,
|
2026-07-01 20:04:27 +08:00
|
|
|
|
Role = i == 0 ? nameof(DaqChannelRole.OutputVoltage) : nameof(DaqChannelRole.Unconfigured),
|
|
|
|
|
|
Name = i == 0 ? "输出电压" : $"CH{i}",
|
|
|
|
|
|
IsCalibrated = i == 0
|
2026-06-30 12:10:29 +08:00
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
[System.Text.Json.Serialization.JsonIgnore]
|
|
|
|
|
|
public int DeviceIndex { get => LogicalDeviceId; set => LogicalDeviceId = value; }
|
|
|
|
|
|
[System.Text.Json.Serialization.JsonIgnore]
|
|
|
|
|
|
public int SampleRateHz
|
|
|
|
|
|
{
|
|
|
|
|
|
get => (int)Math.Round(ActualSampleRateHz);
|
|
|
|
|
|
set => ClockDivider = value > 0
|
|
|
|
|
|
? Math.Max(1, (int)Math.Round(100_000_000.0 / value))
|
|
|
|
|
|
: 1_000;
|
|
|
|
|
|
}
|
|
|
|
|
|
[System.Text.Json.Serialization.JsonIgnore]
|
|
|
|
|
|
public double DurationSec => (PreTriggerMs + PostTriggerMs) / 1_000.0;
|
|
|
|
|
|
|
|
|
|
|
|
[System.Text.Json.Serialization.JsonIgnore]
|
|
|
|
|
|
public double ActualSampleRateHz => 100_000_000.0 / Math.Max(1, ClockDivider);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public sealed class DaqChannelOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
public int PhysicalChannel { get; set; }
|
|
|
|
|
|
public string Role { get; set; } = "Unconfigured";
|
|
|
|
|
|
public string Name { get; set; } = "";
|
|
|
|
|
|
public double Scale { get; set; } = 1;
|
|
|
|
|
|
public double Offset { get; set; }
|
|
|
|
|
|
public bool IsCalibrated { get; set; }
|
|
|
|
|
|
}
|
2026-07-01 20:04:27 +08:00
|
|
|
|
|
|
|
|
|
|
public sealed class Pci2312Options
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool Enabled { get; set; } = true;
|
|
|
|
|
|
public bool UseMock { get; set; }
|
|
|
|
|
|
public bool AutoConnect { get; set; } = true;
|
|
|
|
|
|
public int DeviceId { get; set; }
|
|
|
|
|
|
public int EmergencyInputChannel { get; set; }
|
|
|
|
|
|
public bool EmergencyInputActiveHigh { get; set; } = true;
|
|
|
|
|
|
public int AlarmOutputChannel { get; set; }
|
|
|
|
|
|
public bool AlarmOutputActiveHigh { get; set; } = true;
|
|
|
|
|
|
public int PollIntervalMs { get; set; } = 100;
|
|
|
|
|
|
}
|