FocusZeroBuilderTests.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using IvfTl.Control.Entity;
  2. using ivf_tl_SerialHelper.Util;
  3. using Xunit;
  4. namespace ivf_tl_SerialHelper.Tests
  5. {
  6. /// <summary>
  7. /// M-06 回归护栏:CreateReadEEPROMvertMtStartPulse(well) 按 well 产出该 well 的 Z 焦点零点读命令地址。
  8. /// builder 早已支持 case 1-16(地址 0x08+4*(well-1),与 autofocustool 权威表一致),
  9. /// 此前 ComBin.ReadEEPROMvertMtStartPulseWait 硬编码 (1) 致 HAL.ReadWellFocusZeroWait 忽略 well 恒读 well-1(M-06)。
  10. /// 修复=ComBin 加 well 参 + HAL 传 well(集成层 red→green 真机验证:修前各 well 全同→修后各异)。
  11. /// 本类锁住 builder 的 per-well 地址表,防回归;字节为纯逻辑。
  12. /// </summary>
  13. public class FocusZeroBuilderTests
  14. {
  15. // 帧 5E 11 00 09 00 04 [addr] 04 00 + ORC;地址字节在 index[6]。
  16. private static byte AddrOf(int well)
  17. {
  18. var custom = new CustomProtocol();
  19. custom.CreateReadEEPROMvertMtStartPulse(well);
  20. return custom.sendBuffer[6];
  21. }
  22. /// <summary>16 个 well 的焦点零点 EEPROM 地址低字节 = 0x08 + 4*(well-1)(autofocustool 权威表)。</summary>
  23. [Theory]
  24. [InlineData(1, 0x08)]
  25. [InlineData(2, 0x0C)]
  26. [InlineData(3, 0x10)]
  27. [InlineData(4, 0x14)]
  28. [InlineData(5, 0x18)]
  29. [InlineData(6, 0x1C)]
  30. [InlineData(7, 0x20)]
  31. [InlineData(8, 0x24)]
  32. [InlineData(9, 0x28)]
  33. [InlineData(10, 0x2C)]
  34. [InlineData(11, 0x30)]
  35. [InlineData(12, 0x34)]
  36. [InlineData(13, 0x38)]
  37. [InlineData(14, 0x3C)]
  38. [InlineData(15, 0x40)]
  39. [InlineData(16, 0x44)]
  40. public void 各well焦点零点地址按well分槽(int well, byte expectedAddr)
  41. {
  42. Assert.Equal(expectedAddr, AddrOf(well));
  43. }
  44. /// <summary>护栏:不同 well 必产不同地址(防回退到"忽略 well 恒读 well-1")。</summary>
  45. [Fact]
  46. public void 不同well产不同地址_非全well1()
  47. {
  48. Assert.NotEqual(AddrOf(1), AddrOf(2));
  49. Assert.NotEqual(AddrOf(1), AddrOf(16));
  50. }
  51. /// <summary>well-1 完整帧字节(含 ORC)锁定。</summary>
  52. [Fact]
  53. public void well1完整帧字节()
  54. {
  55. var custom = new CustomProtocol();
  56. custom.CreateReadEEPROMvertMtStartPulse(1);
  57. // 5E 11 00 09 00 04 08 04 → ORC 覆写末位占位=前8字节和=0x88(帧 9 字节,CreateORC 不追加)
  58. var expected = new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x04, 0x08, 0x04, 0x88 };
  59. Assert.Equal(expected, custom.sendBuffer);
  60. }
  61. }
  62. }