using System; using System.Collections.Generic; using System.IO.Ports; using IvfTl.Hardware.Impl; namespace IvfTl.Hardware.HilTests.Infrastructure { /// 一个有响应的真舱:串口 + 握手返回的舱号。 public sealed class ChamberInfo { public string Port { get; } public int HouseSn { get; } public ChamberInfo(string port, int houseSn) { Port = port; HouseSn = houseSn; } } /// /// 全套件构造一次:扫描 COM 口、逐口 Open+握手,收集有响应的真舱。 /// 探测完即 Close 释放;各测试用时各自重开端口。 /// 无硬件 / control 正占用串口 → Chambers 为空 → 测试 Skip。 /// public sealed class HardwareRigFixture : IDisposable { public IReadOnlyList Chambers { get; } public HardwareRigFixture() { var found = new List(); string[] ports; try { ports = SerialPort.GetPortNames(); } catch { ports = Array.Empty(); } foreach (var port in ports) { if (port == "COM1" || port == "COM2") continue; // 非舱口 SerialChannelImpl ch = null; try { ch = new SerialChannelImpl(0, port); if (!ch.Open()) continue; int house = ch.ShakeHandsWait(); if (house < 0) continue; found.Add(new ChamberInfo(port, house)); } catch { /* 占口/无响应 → 不计入 */ } finally { try { ch?.Close(); } catch { } } } Chambers = found; } /// 取第一个有舱室 E方(排气阀/灯光/焦点)的真舱,排除舱11(缓冲瓶/总控)。无则返回 null。 public ChamberInfo FirstChamberWithWells() { foreach (var c in Chambers) if (c.HouseSn != 11) return c; return null; } public void Dispose() { } } }