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