From 93dffdfd1ed8857792f4c05ccb9a8983702de007 Mon Sep 17 00:00:00 2001 From: gudae Date: Wed, 17 Jun 2026 14:52:49 +0900 Subject: [PATCH] =?UTF-8?q?hardware.ini=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hardware.ini | 13 ++++---- Services/EquipmentMeasurementService.cs | 40 ++++++++++++++++++++----- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Hardware.ini b/Hardware.ini index 113d1bb..6ff4377 100644 --- a/Hardware.ini +++ b/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 diff --git a/Services/EquipmentMeasurementService.cs b/Services/EquipmentMeasurementService.cs index 341aff7..2aba356 100644 --- a/Services/EquipmentMeasurementService.cs +++ b/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(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 CreateVisaClientAsync(ScpiChannelSettings channel)