Browse Source

hardware.ini 수정

main
gudae 2 months ago
parent
commit
93dffdfd1e
  1. 13
      Hardware.ini
  2. 40
      Services/EquipmentMeasurementService.cs

13
Hardware.ini

@ -32,19 +32,20 @@ PreBoardDelayMilliseconds=2000
LogoutCommand=OUTP OFF, (@1);OUTP OFF, (@2)
; 34465A DMM
VoltageConnection=Tcp
VoltageConnection=LAN
VoltageResource=
VoltageIdnMatch=34460,34461,34465,34470,3446,3447
VoltageIdnMatch=34465A
VoltageHost=192.168.0.3
VoltagePort=5025
VoltageSetupCommand=
VoltageReadCommand=MEAS:VOLT:DC?
; E36200 Series Power Supply
CurrentConnection=Tcp
; E36233A Power Supply
CurrentConnection=LAN
CurrentResource=
CurrentIdnMatch=E362
CurrentHost=
CurrentIdnMatch=E36233A
; Change this to the E36233A LAN IP if the instrument uses a different address.
CurrentHost=192.168.0.4
CurrentPort=5025
CurrentPortName=
CurrentBaudRate=9600

40
Services/EquipmentMeasurementService.cs

@ -153,7 +153,7 @@ public sealed class EquipmentMeasurementService
var connection = GetConnectionType(channel);
return connection switch
{
"TCP" or "LAN" => CreateTcpClientAsync(label, channel),
"TCP" or "LAN" or "ETHERNET" => CreateTcpClientAsync(label, channel),
"SERIAL" or "COM" => Task.FromResult<IScpiClient>(new SerialScpiClient(channel.PortName, channel.BaudRate, _settings.Timeout, channel.GetIdnMatches(), channel.GetTerminator())),
"VISA" or "USB" => CreateVisaClientAsync(channel),
_ => throw new InvalidOperationException($"{label} 장비 연결 방식은 Visa, Serial, Tcp 중 하나로 설정하세요.")
@ -167,12 +167,12 @@ public sealed class EquipmentMeasurementService
return channel.Connection.Trim().ToUpperInvariant();
}
if (!string.IsNullOrWhiteSpace(channel.ResourceName))
if (!string.IsNullOrWhiteSpace(channel.Host))
{
return "VISA";
return "TCP";
}
if (!string.IsNullOrWhiteSpace(channel.IdnMatch))
if (!string.IsNullOrWhiteSpace(channel.ResourceName))
{
return "VISA";
}
@ -182,9 +182,9 @@ public sealed class EquipmentMeasurementService
return "SERIAL";
}
if (!string.IsNullOrWhiteSpace(channel.Host))
if (!string.IsNullOrWhiteSpace(channel.IdnMatch))
{
return "TCP";
return "VISA";
}
return string.Empty;
@ -197,7 +197,33 @@ public sealed class EquipmentMeasurementService
throw new InvalidOperationException($"Hardware.ini [Equipment] {label} Host 값을 확인하세요.");
}
return await TcpScpiClient.ConnectAsync(channel.Host, channel.Port, _settings.Timeout);
var client = await TcpScpiClient.ConnectAsync(channel.Host, channel.Port, _settings.Timeout);
try
{
await ValidateTcpIdnAsync(label, channel, client);
return client;
}
catch
{
client.Dispose();
throw;
}
}
private static async Task ValidateTcpIdnAsync(string label, ScpiChannelSettings channel, IScpiClient client)
{
var idnMatches = channel.GetIdnMatches();
if (idnMatches.Length == 0)
{
return;
}
var idn = await client.QueryAsync("*IDN?");
var isMatch = idnMatches.Any(token => idn.Contains(token, StringComparison.OrdinalIgnoreCase));
if (!isMatch)
{
throw new InvalidOperationException($"{label} LAN IDN mismatch. Expected: {string.Join(", ", idnMatches)} / Actual: {idn}");
}
}
private async Task<IScpiClient> CreateVisaClientAsync(ScpiChannelSettings channel)

Loading…
Cancel
Save