dsh-serial-trigger:面向 DSH 的串口助手插件

Introduction

When using large models to handle serial communication, a single model inference turn can take several seconds, whereas the timing window for UART communication is often only a few dozen milliseconds. Making the model read the port byte by byte is both slow and difficult to reproduce. This plugin breaks down serial work into three layers: real-time control is handled by a state machine, fault point localization is done by scanning scripts, and planning and decision-making are handled by the model.

What is it

dsh-serial-trigger is a DSH plugin that provides lossless recording, incremental reading, byte-level inspection, workspace scan marking, and a real-time state machine middleware. The plugin is maintained by 1158295269, categorized as client-side, and uses the MIT license. It encapsulates 18 model tools into a serial port operation interface and provides a serial port panel in the sidebar of the conversation interface.

Core Capabilities

Serial Ports and Capture

Use serial_ports to list available ports, serial_open to open and establish lossless recording, serial_tail to incrementally read the tail data, serial_send to send data, and serial_close to close the port. Each port corresponds to a writer; the tool takes over the port when opened, and the panel becomes read-only.

Reverse Lookup and Export

serial_captures searches for historical sessions by project, time, or keyword, serial_grep searches for patterns in a specified capture, and serial_export exports to text, hexadecimal, or CSV format. All bytes are written to a .slog container and indexed to SQLite, allowing capture IDs to be inspected at any time.

Fault Point Scanning

Scanning scripts are stored in the workspace as ESM modules and export a createScanner function. The script receives a context ctx and generates marks in the record callback based on time, direction, offset, and data, returning { anchor: { dir, offset, length }, t, kind, severity, label }. Marks are byte references, not text content. The call chain is serial_scan({ captureId, script }) → serial_marks({ captureId }) → serial_bytes({ captureId, dir, offset, length }).

Real-time State Machine

The state machine is defined in a JSON file using JSON scenes. Use serial_fsm_simulate to simulate on a recording and serial_fsm_start to run on a real port. line:/regex/ and event:<name> define transition conditions. send must declare expect + waitMs + goto, and supports onTimeout fallback strategies (retry / goto / mark / severity / stop). Supports state-level after timers, with one state machine instance per port.

Panel

The panel is registered as a Serial tab in the conversation interface, containing a terminal (real-time tail, filtering, searching, newline strategy, send box), statistics (throughput, bytes/lines), a history list, and a marks list. The terminal supports a takeover indicator, which is displayed when another holder possesses the port.

Installation and Enablement

Prerequisites: DSH Desktop (Test version 0.2.1-rc.2), Node.js ≥ 24, and drivers for USB-to-serial adapters.

  1. Install into the DSH configuration file:
cd "$DSH_HOME/profiles/desktop"      # The profile that will load this configuration
pnpm add dsh-serial-trigger
  1. Restart DSH. The package declares dsh.bundle.patch, and the host will mount serial-trigger from the package and automatically register the browser panel.

  2. Optional: Override settings in the configuration file’s cordis.patch.yml:

- id: serial-trigger
  config:
    dataRoot: 'D:/serial-logs'
    replayRoots:
      - 'D:/device-logs'
  1. Verification: Open a conversation in DSH, look for the Serial tab, or ask the agent to run serial_ports.

Typical Usage

Tool results use a uniform envelope format: success is {ok:true, data:{…}}, and failure is {ok:false, error:{code, message, hint, fix[], retryable}}.

serial_ports                                            // → ports[]
serial_open({ port: 'COM8', project: 'bringup' })       // → { portId, captureId, path }
serial_tail({ portId, timeoutMs: 3000 })                // → { lines[], cursor }
serial_send({ portId, text: 'PING', append: 'lf' })
serial_close({ portId })                                // → { path, bytesRx, bytesTx, lines }

Lookup history:

serial_captures({ project: 'bringup', keyword: 'timeout' })
serial_grep({ captureId, pattern: 'ASSERT', context: 3 })
serial_export({ captureId, format: 'text' })

State machine example:

{
  "name": "handshake",
  "initial": "idle",
  "states": {
    "idle": {
      "on": {
        "event:start": {
          "send": "PING\n",
          "expect": "line:/PING/",
          "waitMs": 800,
          "goto": "linked",
          "onTimeout": { "retry": 2, "retryDelayMs": 100, "goto": "recovering",
                         "mark": "no echo", "severity": "warn" }
        },
        "line:/^READY/": { "goto": "ready" }
      },
      "after": { "ms": 5000, "goto": "recovering", "mark": "no output" }
    },
    "ready": { "on": {} },
    "linked": { "on": {} },
    "recovering": { "on": {} }
  }
}

Scanning script example:

// hb-scan.mjs
export function createScanner(ctx) {
  let prevSeq = null;
  return {
    record({ t, dir, offset, data }) {
      if (dir !== 'rx') return null;
      const text = data.toString('latin1');
      // ... parse lines, return a mark or array of marks
      return { anchor: { dir: 'rx', offset, length: data.length }, t, kind: 'state',
               severity: 'info', label: 'HB ' + text.length + ' bytes' };
    },
    finish() { return null; },
  };
}

Applicable Scenarios and Notes

Suitable for scenarios requiring serial communication to be integrated into the large model workflow, needing long-term session storage for tracing, and needing scripts to automatically locate fault points. The plugin runs with the permissions of the current DSH process; source code and license should be checked before installation. Recorded data is stored in the local dataRoot directory and will not be uploaded.

Summary

dsh-serial-trigger divides responsibilities into layers, entrusting high-speed timing control to the state machine, pattern recognition to scanning scripts, and allowing the model to focus on planning and decision-making. The combination of 18 model tools and a visual panel adds a solution for hardware debugging and embedded interaction to the DSH plugin ecosystem.

Directory Page | GitHub

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye