Applicable Scenarios
- I2C/SPI/UART timing of embedded devices needs to be verified with a logic analyzer.
- Need to trigger a Saleae device online to capture digital waveforms on specified channels.
- Need to add protocol decoders to captured waveforms and export the decoded data table (CSV).
- Need to export raw channel waveforms (CSV) for further analysis.
Required Inputs
- Logic 2 desktop software is running, and the automation server is enabled (Settings/Preferences → Automation, or the Automation button in the bottom status bar; it can also be started from the command line with
Logic.exe --automation). - A Saleae device is connected (or test with Logic 2's simulated device,
--include-sim)。 - Capture channels, sample rate, duration.
- When decoding protocols: the protocol type and channel mapping for each decoder.
Dependencies
logic2-automation(pip install logic2-automation)- Logic 2 desktop software (provides the automation server, default port 10430)
Execution Steps
-
First read references/usage.md, to confirm the operation parameters and decoder setting keys.
-
Probe the environment (check package, port, Logic 2 connectivity, and devices):
python scripts/la_tool.py --detect -
List devices:
python scripts/la_tool.py --devices -
Capture and decode. It is recommended to use the repeatable
--analyzer, a single capture can attach multiple decoders, each exporting its own independent CSV:# 单协议:I2C(SCL=CH0, SDA=CH1) python scripts/la_tool.py --capture --channels 0-1 --samplerate 4M --duration 5 \ --analyzer "i2c:scl=0,sda=1" # 多协议同时解码:I2C + UART + SPI python scripts/la_tool.py --capture --channels 0-6 --samplerate 16M --duration 5 \ --analyzer "i2c:scl=0,sda=1" \ --analyzer "uart:rx=2,baud=115200" \ --analyzer "spi:clk=3,mosi=4,miso=5,cs=6" # CAN(单线,500kbps) python scripts/la_tool.py --capture --channels 0 --samplerate 4M --duration 5 \ --analyzer "can:can=0,baud=500000"--analyzerformat is协议:键=值,...:i2c:scl、sda(all required)spi:clk(required),mosi、miso、cs(optional, omit if not connected)uart:rx(required),baud(default 115200)can:can(required, CAN signal channel),baud(default 500000)
When the same protocol appears multiple times, it will automatically be distinguished by
i2c、i2c2in the exported file name. -
Output location: by default saved to the project root
.captures/logic-analyzer/, file names include a timestamp to prevent overwriting (e.g.i2c_20260625_201048.csv)。- The default directory can be overridden with the environment variable
LA_CAPTURE_DIR. - For a single decoder,
--output 路径can be used to specify the file; relative paths are relative to the default directory, absolute paths are used as-is. - Use
--radix hex|dec|bin|asciifor the numeric base (default hex).
- The default directory can be overridden with the environment variable
Natural Language Prompt Template
When having the AI invoke this skill,the channel mapping is physical wiring information that must be stated clearly(the AI cannot detect it); which channel SCL/SDA, CLK, etc. are connected to must be explicit. Template (fill in the blanks and use):
- I2C:
抓 I2C,SCL=通道5,SDA=通道6,采集20秒 - SPI:
抓 SPI,CLK=通道3,MOSI=通道4,MISO=通道5,CS=通道6,采集10秒 - UART:
抓 UART,RX=通道2,波特率115200,采集10秒 - CAN:
抓 CAN,信号接通道0,波特率500k,采集10秒 - Multiple protocols:
同时抓 I2C(SCL=5,SDA=6) 和 UART(RX=2,波特率115200),采集15秒
Optional items (defaults are used if not specified): sample rate (4M is enough for I2C/UART/CAN, 16M~24M is recommended for high-speed SPI), duration (default 5 seconds), port/address (default 10430 / localhost, no need to specify). During capture, make sure there is communication on the bus, otherwise an empty table will be decoded.
Auto-start Logic 2 (--launch, experimental)
The script supports --launch automatically launching Logic 2 (and automatically closing it when done), saving the need to manually open the software. However, in some environments (such as launching the GUI in the background from git bash) it has proven unreliable in practice—the process cannot be maintained and the port cannot come up.By default, it is still recommended to manually open Logic 2 and enable the automation server, using the normal connection mode. Use only when it is confirmed that the local environment supports it --launch。
Backward compatible (legacy single-protocol syntax, still usable)
python scripts/la_tool.py --capture --channels 0-1 --samplerate 4M --duration 5 \
--decode i2c --i2c-scl 0 --i2c-sda 1
New code should prefer --analyzer;--decode Only takes effect when --analyzer is not provided.
Extending with new protocols
To support a new protocol (such as 1-Wire, LIN, Manchester, etc.), just add one entry in each of scripts/la_tool.py the ANALYZER_NAMES and ANALYZER_SPECS : protocol short name → Logic 2 decoder name, mapping from short keys to settings keys, and required key list. Parsing, capture, and export logic are all automatically reused, with no need to change function bodies (CAN was added this way).
Key:settings key names must be exactly consistent with the settings items for that decoder in the Logic 2 interfaceexactly consistent. Do not guess—the most reliable approach is to probe with the API while Logic 2 is running: repeatedly add_analyzer(name, settings=...)for a temporary capture; the set of key names that succeeds is the correct value.
Failure triage
tool-missing: logic2-automation is not installed.connection-failure: cannot connect to the Logic 2 automation service (the software is not running or the automation server is not enabled).no-device: no connected Saleae device was found.capture-failure: an error occurred during capture startup or the process.decode-error: failed to add the protocol decoder (usually a mismatch in settings keys or channel mapping).
Output conventions
Example output format:
结果: ✅ 采集完成 5.0s,2 个解码器: i2c, uart
连接: 127.0.0.1:10430 ch=[0, 1, 2] 16000000Hz 5.0s
📄 输出: E:\work\project\.captures\logic-analyzer\i2c_20260625_201643.csv
📄 输出: E:\work\project\.captures\logic-analyzer\uart_20260625_201643.csv
Exported CSV columns:name,type,start_time,duration,ack,address,read,data(varies slightly by protocol).
The data column is displayed in the base specified by --radix (default hexadecimal, e.g., 0x2C)。
Handoff relationships
- After flashing firmware from
build-keil/build-platformio, use this skill to verify bus timing. - Complementary to
serial-monitor: serial-monitor views serial debug output, while logic-analyzer performs signal-level timing verification. - Complementary to
visa-debug: visa-debug uses an oscilloscope to measure analog quantities, while logic-analyzer decodes digital protocols.