You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用JavaScript检测COM端口与EZB设备的连接状态?

实现ARC中EZB设备连接状态检测的JavaScript方案

核心实现代码

function isEZBConnected(boardIndex) {
  // 验证板卡索引有效性(ARC中索引从0开始)
  if (typeof boardIndex !== 'number' || boardIndex < 0 || boardIndex >= EZBC.Count) {
    console.error('无效的板卡索引');
    return false;
  }
  // 获取对应板卡实例并返回连接状态
  const targetBoard = EZBC.GetBoard(boardIndex);
  return targetBoard ? targetBoard.Connected : false;
}

// 使用示例:检测索引为0的EZB设备连接状态
console.log(isEZBConnected(0));

关键说明

  • ARC的JavaScript环境提供全局内置的EZBC对象,是管理所有EZB设备的核心入口
  • EZBC.Count:返回当前已配置的EZB板卡总数,用于快速校验输入的索引是否合法
  • EZBC.GetBoard(index):获取指定索引的板卡实例,其Connected属性为布尔值,直接标识设备是否处于激活连接状态
  • 板卡索引从0开始,与EZ Script中IsConnected(boardIndex)的参数逻辑完全一致

内容的提问来源于stack exchange,提问作者dschulpius

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 22:29:54