|
|
@ -153,7 +153,7 @@ public sealed class EquipmentMeasurementService |
|
|
var connection = GetConnectionType(channel); |
|
|
var connection = GetConnectionType(channel); |
|
|
return connection switch |
|
|
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())), |
|
|
"SERIAL" or "COM" => Task.FromResult<IScpiClient>(new SerialScpiClient(channel.PortName, channel.BaudRate, _settings.Timeout, channel.GetIdnMatches(), channel.GetTerminator())), |
|
|
"VISA" or "USB" => CreateVisaClientAsync(channel), |
|
|
"VISA" or "USB" => CreateVisaClientAsync(channel), |
|
|
_ => throw new InvalidOperationException($"{label} 장비 연결 방식은 Visa, Serial, Tcp 중 하나로 설정하세요.") |
|
|
_ => throw new InvalidOperationException($"{label} 장비 연결 방식은 Visa, Serial, Tcp 중 하나로 설정하세요.") |
|
|
@ -167,12 +167,12 @@ public sealed class EquipmentMeasurementService |
|
|
return channel.Connection.Trim().ToUpperInvariant(); |
|
|
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"; |
|
|
return "VISA"; |
|
|
} |
|
|
} |
|
|
@ -182,9 +182,9 @@ public sealed class EquipmentMeasurementService |
|
|
return "SERIAL"; |
|
|
return "SERIAL"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(channel.Host)) |
|
|
if (!string.IsNullOrWhiteSpace(channel.IdnMatch)) |
|
|
{ |
|
|
{ |
|
|
return "TCP"; |
|
|
return "VISA"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return string.Empty; |
|
|
return string.Empty; |
|
|
@ -197,7 +197,33 @@ public sealed class EquipmentMeasurementService |
|
|
throw new InvalidOperationException($"Hardware.ini [Equipment] {label} Host 값을 확인하세요."); |
|
|
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) |
|
|
private async Task<IScpiClient> CreateVisaClientAsync(ScpiChannelSettings channel) |
|
|
|