Skip to content

Latest commit

 

History

History
107 lines (77 loc) · 4.7 KB

File metadata and controls

107 lines (77 loc) · 4.7 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Build & Run

# Build: open .sln in Visual Studio 2022 with Qt5.15.2 MSVC toolchain
# vcpkg auto-restores dependencies via vcpkg.json manifest
start SignalFlowMaster\SignalFlowMaster.sln

# Run the built binary (from solution output dir)
.\SignalFlowMaster\bin\Release_x64\SignalFlowMaster.exe    # Release
.\SignalFlowMaster\bin\Debug_x64\SignalFlowMaster.exe      # Debug (console enabled)

# Send protocol commands from Python (no LabJack hardware needed)
python SignalFlowMaster\scripts\send_labjack_protocol.py

Prerequisites: VS2022 installed outside default path (no spaces), Qt5.15.2 VS toolchain, LABJACK_PATH system env var pointing to LabJack driver root. vcpkg dependencies: highfive[xtensor], xtensor, xtensor-io, boost, fmt, spdlog, cppzmq.

Git submodules:

git submodule update --init --recursive   # pulls CppToolkit into 3rdPartyLibs/

Architecture

SignalFlowMaster 是一个基于 Qt5 的 LabJack U3 USB 数据采集卡控制平台,管理实时信号输入输出。

三层结构

BrowseDeviceUI (mainwindow)     ← 设备发现窗口,USB 扫描 LabJack U3
    │  找设备 → 打开设备 → 创建新窗口
    ▼
LabJackU3ControlUI              ← 单设备操控窗口(可开多个,每个对应一个 U3)
    │  持有 controller_ 实例
    ▼
LabJackU3Controller             ← 硬件驱动层(非 UI,QObject)
    ├── 执行 Protocol (Operation 序列)
    ├── 流模式信号采集 (StreamDataPack → HDF5)
    ├── ZMQ 网络监听 (:33090, PULL socket)  接受 Python 远程指令
    └── CppToolkit 异步消费者 (SignalDataStorer)

关键数据结构

  • Protocol = {repetitions, infinite_repetition, vector<Operation>} — 可重复执行的步骤序列
  • Operation = {duration_in_ms, bitset<8> eioStates, uuid} — 单步:持续 N ms + 8 路数字输出状态
  • StreamDataPack — stream 模式下每个采集包:AIN 电压 (4ch)、DIO 状态 (8ch)、DIN 状态 (4ch)、Counter (2ch),底层用 xtensor 张量存储

信号 IO 通道

通道 数量 方向 LabJack 引脚
AIN 4 (0-3) Analog In AI0-AI3
EIO (DOut) 8 (0-7) Digital Out EIO0-EIO7
CIO (DIn) 4 (0-3) Digital In CIO0-CIO3
Counter 2 (0-1) Counter FIO4-FIO5

Protocol 执行流程

  1. ExecuteProtocolListAsync()QtConcurrent::run() 在新线程中执行
  2. ExecuteProtocolList() → 逐 Protocol → 逐 Operation
  3. 每个 Operation: 通过 LabJack UD 驱动 eDO() 设置 8 路 EIO → sleep_waiter 等待 duration_in_ms
  4. InterruptProtocol() 通过 epoch 计数器 + sleep_waiter.wake_up() 中断执行
  5. 执行过程中发射 StartOperation(uuid) / FinishOperation(uuid) 信号,UI 上高亮当前正在执行的步骤

ZMQ 网络控制

  • C++ 端:NetworkControlLoop() 线程在 tcp://*:33090 上绑定 ZMQ PULL socket
  • 接收 JSON 格式:{"protocols": [{"repetitions": N, "operations": [{"duration_in_ms": M, "eioStates": [bool*8]}]}]}
  • Python 端:send_labjack_protocol.py 提供 LabJackProtocolSender 类,ZMQ PUSH → tcp://127.0.0.1:33090
  • 网络命令在独立 detach 线程中执行,不阻塞监听循环

信号采集与存储

  • CollectSignalDataAsync() → stream 模式采集,数据通过 SignalDataStorerAsyncConsumer 子类)异步写入 HDF5
  • 存储路径格式: <root_dir>/<prefix>_<timestamp>_<suffix>/
  • HDF5 使用 HighFive 库(已从 HDF5 C++ API 迁移)

数据简化 (SimplifiedDataPack)

SimplifyStreamDataPack() 将高速流数据(~5000Hz)按 counter 或 DOut 值变化边界压缩为 ChannelBoundaryData,只保留状态变化的起止点。

UI 组件

职责
BrowseDeviceUI 主窗口:扫描 USB LabJack U3 设备列表,双击打开操控窗口
LabJackU3ControlUI 设备操控窗口:信号采集 + Protocol 编辑/运行,支持拖放 JSON
ProtocolUI Protocol 编辑器组件:repetitions 设置 + Operation 列表
OperationUI Operation 编辑器组件:duration 设置 + 8 个 EIO checkbox

预设 JSON 格式 (preset/*.json)

{"protocols": [{"repetitions": 1, "infinite_repetition": false,
  "operations": [{"duration_in_ms": 30000, "eioStates": [true,false,true,...]}]}]}

可通过文件 → 加载/拖放 JSON 到窗口中。send_labjack_protocol.py 也可从 JSON 文件读取并发送。

ENABLE_CONSOLE_ 宏

编译 Debug 配置时定义 ENABLE_CONSOLE_main() 会调用 AllocConsole() 创建 Windows 控制台窗口用于 stdout/stderr 输出。