类 SlaveListExt

java.lang.Object
com.darra.ethercat.sugar.SlaveListExt

public final class SlaveListExt extends Object
从站列表的高级语法糖 — 提供数组、排序、聚合 helper.

MasterStreams 偏 "Stream + Optional + Map", 这里偏 "List/Array 操作 + 集合代数". 两者互补, 都不修改主线.

典型用法:

 // 1. 拍快照成 Slave[] (跨线程传)
 Slave[] all = SlaveListExt.toArray(master);

 // 2. 按拓扑深度排序 (适合做树形 UI)
 List<Slave> ordered = SlaveListExt.sortedByConfigAddr(master);

 // 3. 统计: 多少个从站当前在 OP
 long opCount = SlaveListExt.countByState(master, EcState.OP);

 // 4. 二元布尔: 全网是否都进了 OP
 if (SlaveListExt.allInState(master, EcState.OP)) launch();
 
从以下版本开始:
2026-05
  • 方法详细资料

    • toArray

      public static Slave[] toArray(EtherCATMaster master)
      拍快照成 Slave[] (跨线程安全 — 主线 List 是 Collections.unmodifiableList).
    • sortedBySlaveNum

      public static List<Slave> sortedBySlaveNum(EtherCATMaster master)
      按从站 1-based 序号排序的 List 副本 (主线已经按序号顺序, 这里 explicit 一次).
    • sortedByConfigAddr

      public static List<Slave> sortedByConfigAddr(EtherCATMaster master)
      按 ConfigAddr 升序排列, 适合按物理拓扑顺序枚举.
    • sortedByVendorThenIndex

      public static List<Slave> sortedByVendorThenIndex(EtherCATMaster master)
      按 VendorId 排序后再按序号排序 (混合多厂商场景, 同厂商排一起).
    • countByState

      public static long countByState(EtherCATMaster master, EcState state)
      处于指定状态的从站数.
    • lostCount

      public static long lostCount(EtherCATMaster master)
      丢失从站数.
    • dcCapableCount

      public static long dcCapableCount(EtherCATMaster master)
      支持 DC 的从站数.
    • allInState

      public static boolean allInState(EtherCATMaster master, EcState state)
      全网从站是否都进入了指定状态. 网络无从站时返回 false (业务上"无从站"通常 不应视为 success).
    • anyInState

      public static boolean anyInState(EtherCATMaster master, EcState state)
      是否存在任意从站处于指定状态.
    • hasLostSlave

      public static boolean hasLostSlave(EtherCATMaster master)
      是否存在丢失从站.
    • identities

      public static List<SlaveIdentity> identities(EtherCATMaster master)
      一次性抓取全网身份快照. 适合跨线程做配置校验.
      返回:
      不可变 List<SlaveIdentity>, 序号顺序