|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Housing.Services;
|
|
|
|
|
|
|
|
|
|
public sealed class EquipmentMeasurementSettings
|
|
|
|
|
{
|
|
|
|
|
public int Timeout { get; set; } = 5000;
|
|
|
|
|
public int SettleMilliseconds { get; set; } = 300;
|
|
|
|
|
public string PreBoardCommand { get; set; } = string.Empty;
|
|
|
|
|
public int PreBoardDelayMilliseconds { get; set; } = 0;
|
|
|
|
|
public string LogoutCommand { get; set; } = string.Empty;
|
|
|
|
|
public ScpiChannelSettings Voltage { get; set; } = new();
|
|
|
|
|
public ScpiChannelSettings Current { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
public static EquipmentMeasurementSettings Load(string filePath)
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(filePath))
|
|
|
|
|
{
|
|
|
|
|
throw new FileNotFoundException("Hardware.ini 파일을 찾을 수 없습니다.", filePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var values = IniFile.LoadSection(filePath, "Equipment");
|
|
|
|
|
return new EquipmentMeasurementSettings
|
|
|
|
|
{
|
|
|
|
|
Timeout = GetInt(values, "Timeout", 5000),
|
|
|
|
|
SettleMilliseconds = GetInt(values, "SettleMilliseconds", 300),
|
|
|
|
|
PreBoardCommand = GetString(values, "PreBoardCommand", string.Empty),
|
|
|
|
|
PreBoardDelayMilliseconds = GetInt(values, "PreBoardDelayMilliseconds", 0),
|
|
|
|
|
LogoutCommand = GetString(values, "LogoutCommand", string.Empty),
|
|
|
|
|
Voltage = LoadChannel(values, "Voltage", "MEAS:VOLT:DC?", "34460,34461,34465,34470,3446,3447"),
|
|
|
|
|
Current = LoadChannel(values, "Current", "MEAS:CURR? CH1", "E362")
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static ScpiChannelSettings LoadChannel(
|
|
|
|
|
Dictionary<string, string> values,
|
|
|
|
|
string prefix,
|
|
|
|
|
string defaultReadCommand,
|
|
|
|
|
string defaultIdnMatch)
|
|
|
|
|
{
|
|
|
|
|
return new ScpiChannelSettings
|
|
|
|
|
{
|
|
|
|
|
Connection = GetString(values, prefix + "Connection", string.Empty),
|
|
|
|
|
ResourceName = GetString(values, prefix + "Resource", string.Empty),
|
|
|
|
|
IdnMatch = GetString(values, prefix + "IdnMatch", defaultIdnMatch),
|
|
|
|
|
Host = GetString(values, prefix + "Host", string.Empty),
|
|
|
|
|
Port = GetInt(values, prefix + "Port", 5025),
|
|
|
|
|
PortName = GetString(values, prefix + "PortName", string.Empty),
|
|
|
|
|
BaudRate = GetInt(values, prefix + "BaudRate", 115200),
|
|
|
|
|
Terminator = GetString(values, prefix + "Terminator", string.Empty),
|
|
|
|
|
SetupCommand = GetString(values, prefix + "SetupCommand", string.Empty),
|
|
|
|
|
CleanupCommand = GetString(values, prefix + "CleanupCommand", string.Empty),
|
|
|
|
|
ReadCommand = GetString(values, prefix + "ReadCommand", defaultReadCommand)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetString(Dictionary<string, string> values, string key, string defaultValue)
|
|
|
|
|
{
|
|
|
|
|
return values.TryGetValue(key, out var value) && !string.IsNullOrWhiteSpace(value)
|
|
|
|
|
? value.Trim()
|
|
|
|
|
: defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int GetInt(Dictionary<string, string> values, string key, int defaultValue)
|
|
|
|
|
{
|
|
|
|
|
return values.TryGetValue(key, out var value) && int.TryParse(value, out var result)
|
|
|
|
|
? result
|
|
|
|
|
: defaultValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sealed class ScpiChannelSettings
|
|
|
|
|
{
|
|
|
|
|
public string Connection { get; set; } = string.Empty;
|
|
|
|
|
public string ResourceName { get; set; } = string.Empty;
|
|
|
|
|
public string IdnMatch { get; set; } = string.Empty;
|
|
|
|
|
public string Host { get; set; } = string.Empty;
|
|
|
|
|
public int Port { get; set; } = 5025;
|
|
|
|
|
public string PortName { get; set; } = string.Empty;
|
|
|
|
|
public int BaudRate { get; set; } = 115200;
|
|
|
|
|
public string Terminator { get; set; } = string.Empty;
|
|
|
|
|
public string SetupCommand { get; set; } = string.Empty;
|
|
|
|
|
public string CleanupCommand { get; set; } = string.Empty;
|
|
|
|
|
public string ReadCommand { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
public string[] GetIdnMatches()
|
|
|
|
|
{
|
|
|
|
|
return IdnMatch
|
|
|
|
|
.Split(',', ';')
|
|
|
|
|
.Select(value => value.Trim())
|
|
|
|
|
.Where(value => !string.IsNullOrWhiteSpace(value))
|
|
|
|
|
.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetTerminator()
|
|
|
|
|
{
|
|
|
|
|
return string.IsNullOrWhiteSpace(Terminator) ? "\n" : Terminator;
|
|
|
|
|
}
|
|
|
|
|
}
|