ISerialChannel.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. namespace IvfTl.Hardware
  3. {
  4. /// <summary>
  5. /// 单 COM 口的唯一持有者。封装 SerialPort 打开/独占 + 同步请求-响应收发。
  6. /// 蓝本:autofocustool SerialMotor + HouseMotor + Protocol(最权威),
  7. /// 并补回 control/operate 的温压门 / 写EEPROM / 气阀 能力。
  8. /// 所有方法同步阻塞到下位机回复;内部对该口的收发用实例锁串行化(一个 COM 口同一时刻一条在途指令)。
  9. /// 接口签名权威:13 文档 §3.2。返回值约定:位置/计数失败 -1,温压失败 -1m,布尔操作失败 false。
  10. /// </summary>
  11. public interface ISerialChannel : IDisposable
  12. {
  13. string PortName { get; }
  14. bool IsOpen { get; }
  15. Action<string> Log { get; set; }
  16. // ── 生命周期 ──
  17. /// <summary>打开串口(含 DiscardIn/OutBuffer)。已开返回 true。独占失败返回 false。</summary>
  18. bool Open();
  19. void Close();
  20. // ── 读超时策略(按命令类型分超时,13 §3.5/3;属性化,禁止写死单一超时)──
  21. /// <summary>移动类命令(0x05)读超时(ms),需覆盖最大行程开环回复,默认 12000。</summary>
  22. int MoveReadTimeoutMs { get; set; }
  23. /// <summary>查询类命令读超时(ms),下位机立即回复,默认 3000。</summary>
  24. int QueryReadTimeoutMs { get; set; }
  25. /// <summary>电机到位后默认稳定延时(ms),移动后等机械停稳再抓图,默认 1500(真机标定)。</summary>
  26. int MotorSettleMs { get; set; }
  27. // ── 通用收发(底层)──
  28. /// <summary>发送完整命令帧(含校验),按命令码定长阻塞收帧并校验。extraWaitMs:收到回复后额外等待。失败返回 null。</summary>
  29. byte[] SendWait(byte[] frame, int extraWaitMs = 0);
  30. // ── 握手 / 自检 ──
  31. /// <summary>握手,返回下位机自报 houseSn。失败 -1。</summary>
  32. int ShakeHandsWait();
  33. // ── EEPROM ──
  34. /// <summary>读本舱相机序列号 CCDSN(EEPROM int)。失败 -1。</summary>
  35. int ReadCcdSnWait();
  36. /// <summary>读 EEPROM 灯光亮度(只读)。失败 -1。</summary>
  37. int ReadLightBrightnessWait();
  38. /// <summary>读第 well(1-16) 的水平电机位置脉冲(EEPROM)。失败 -1。</summary>
  39. int ReadWellHorizontalPosWait(int well);
  40. /// <summary>读第 well(1-16) 的 Z 对焦零点脉冲(EEPROM)。失败 -1。</summary>
  41. int ReadWellFocusZeroWait(int well);
  42. /// <summary>读垂直电机扫描间隔脉冲(每层 Z 步距,EEPROM)。失败 -1。</summary>
  43. int ReadScanStepWait();
  44. /// <summary>写第 well(1-16) 的水平电机位置脉冲(命令码 0x12)。
  45. /// ⚠ 需真机验证:写命令字节序/地址表须按 control Commander.cs 复核(13 §⑤ V1)。</summary>
  46. bool WriteWellHorizontalPosWait(int well, int pulseValue);
  47. // ── 电机:垂直(Z=对焦轴)/ 水平(皿孔定位)──
  48. /// <summary>Z 绝对运动到脉冲,delayMs 缺省用 MotorSettleMs;扫描小步可传短延时提速。失败 false。</summary>
  49. bool VerticalMoveToWait(int pulse, int delayMs = -1);
  50. bool VerticalForwardWait(int pulse, int delayMs = -1);
  51. bool VerticalBackwardWait(int pulse, int delayMs = -1);
  52. bool VerticalResetWait(int delayMs = -1);
  53. /// <summary>读 Z 当前位置脉冲。失败 -1。</summary>
  54. int ReadVerticalPositionWait();
  55. bool HorizontalMoveToWait(int pulse, int delayMs = -1);
  56. bool HorizontalForwardWait(int pulse, int delayMs = -1);
  57. bool HorizontalBackwardWait(int pulse, int delayMs = -1);
  58. bool HorizontalResetWait(int delayMs = -1);
  59. int ReadHorizontalPositionWait();
  60. // ── 环境量(温压门,control/operate 有,af 无)──
  61. /// <summary>下盖板温度(℃),失败 -1m。</summary>
  62. decimal TemperatureWait();
  63. decimal ShangTemperatureWait(); // 上盖板
  64. decimal BoLiTemperatureWait(); // 玻璃片下方
  65. decimal PressureWait(); // 舱内气压
  66. (decimal pressure, decimal t1, decimal t2) BufferBottleStateWait(); // 缓冲瓶
  67. /// <summary>仓门状态。失败返回 未知。</summary>
  68. DoorState DoorStatusWait();
  69. // ── IO / LED / 气阀(control/operate 全,af 仅 LED)──
  70. bool OpenLedWait();
  71. bool CloseLedWait();
  72. bool OpenIntakeValveWait();
  73. bool CloseIntakeValveWait();
  74. bool OpenExhaustValveWait();
  75. bool CloseExhaustValveWait();
  76. bool HouseAerationWait(); // 舱室补气
  77. bool HouseVentWait(); // 舱室排气
  78. bool BufferBottleAerationWait(); // 缓冲瓶补气
  79. /// <summary>自动气体交换开/关(对应 operate AutoWait)。</summary>
  80. bool AutoAirSwapWait(bool on);
  81. // ── 直通底层 ComBin(迁移期过渡:调试/采集若需要 ComBin 上 HAL 接口未覆盖的方法可暂取裸实例)──
  82. /// <summary>桥接对象:返回内部包装的具体 ComBin(object 以避免 HAL 接口耦合具体类型)。
  83. /// 仅供迁移期老调用方过渡使用,新代码应只用本接口方法。</summary>
  84. object RawComBin { get; }
  85. }
  86. /// <summary>仓门状态(对应 control State 枚举的 未知/打开/关闭 子集)。</summary>
  87. public enum DoorState { 未知, 打开, 关闭 }
  88. }