iflow-mcp_wegitor-logic_analyzer_mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/PKG-INFO +12 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/README.md +271 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/PKG-INFO +12 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/SOURCES.txt +21 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/dependency_links.txt +1 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/entry_points.txt +2 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/requires.txt +7 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/top_level.txt +1 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/pyproject.toml +44 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/setup.cfg +4 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/src/__init__.py +7 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/src/__main__.py +4 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/src/controllers/__init__.py +14 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/src/controllers/logic2_automation_controller.py +139 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/src/controllers/saleae_controller.py +929 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/src/controllers/saleae_parser_controller.py +548 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/src/logic_analyzer_mcp.py +62 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/src/mcp_tools.py +310 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/src/mcp_tools_experimental.py +636 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/src/saleae_manager.py +98 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/tests/test_saleae_connection.py +281 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/tests/test_saleae_controller.py +154 -0
- iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/tests/test_saleae_parser_controller.py +443 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: iflow-mcp_wegitor-logic_analyzer_mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Saleae Logic capture file parser using MCP
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Requires-Dist: logic2-automation>=1.0.7
|
|
7
|
+
Requires-Dist: saleae>=0.12.0
|
|
8
|
+
Requires-Dist: grpcio>=1.71.0
|
|
9
|
+
Requires-Dist: grpcio-tools>=1.71.0
|
|
10
|
+
Requires-Dist: protobuf>=6.30.2
|
|
11
|
+
Requires-Dist: mcp[cli]
|
|
12
|
+
Requires-Dist: pytest
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# Logic analyzer MCP
|
|
2
|
+
|
|
3
|
+
This project provides an MCP (Message Control Protocol) server and automation interface for Saleae logic analyzers. It enables remote control, automation, and integration of Saleae Logic devices and captures, making it easy to script, manage, and analyze logic analyzer data programmatically.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Device configuration management
|
|
8
|
+
- Capture configuration and execution
|
|
9
|
+
- Data export in various formats
|
|
10
|
+
- Logic file analysis and processing
|
|
11
|
+
- Protocol decoding and visualization
|
|
12
|
+
- Diagram generation and analysis
|
|
13
|
+
- MCP (Message Control Protocol) server integration
|
|
14
|
+
- Support for Logic 16 and other Logic 2 devices
|
|
15
|
+
- Capture file parsing and analysis using python-saleae
|
|
16
|
+
|
|
17
|
+
## Requirements
|
|
18
|
+
|
|
19
|
+
- Python 3.10 or higher
|
|
20
|
+
- Saleae Logic 2 software installed
|
|
21
|
+
- Python-saleae module
|
|
22
|
+
- Logic 2 device (Logic 16, Logic Pro 8, etc.)
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
1. Clone the repository
|
|
27
|
+
|
|
28
|
+
2. Create and activate a virtual environment using uv:
|
|
29
|
+
```bash
|
|
30
|
+
# Create virtual environment
|
|
31
|
+
uv venv
|
|
32
|
+
|
|
33
|
+
# Activate virtual environment
|
|
34
|
+
# On Windows:
|
|
35
|
+
.venv\Scripts\activate
|
|
36
|
+
# On Unix/MacOS:
|
|
37
|
+
source .venv/bin/activate
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
3. Install dependencies using uv:
|
|
41
|
+
```bash
|
|
42
|
+
# Install all dependencies
|
|
43
|
+
uv pip install -e .
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
If you encounter any issues with dependencies, you can try installing them directly:
|
|
47
|
+
```bash
|
|
48
|
+
# Install logic2-automation from GitHub
|
|
49
|
+
uv pip install git+https://github.com/saleae/logic2-automation/#subdirectory=python
|
|
50
|
+
|
|
51
|
+
# Install other dependencies
|
|
52
|
+
uv pip install grpcio protobuf grpcio-tools saleae mcp[cli] pytest
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Note: This project requires Python 3.10 or higher due to dependency requirements.
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
### Running the MCP Server
|
|
60
|
+
|
|
61
|
+
To start the MCP server for remote control:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Using uv (recommended)
|
|
65
|
+
uv --directory <project_path> run -m logic_analyzer_mcp
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Note: When using `uv`, make sure you have it installed and in your PATH. The `--directory` argument should point to the root directory of the project.
|
|
69
|
+
|
|
70
|
+
## Current compatibility & Tested Version
|
|
71
|
+
|
|
72
|
+
This project is tested with [Saleae Logic 1.2.40 for Windows](https://downloads.saleae.com/logic/1.2.40/Logic%201.2.40%20(Windows).zip).
|
|
73
|
+
|
|
74
|
+
- Please use this version for best compatibility.
|
|
75
|
+
- Other versions may work, but are not guaranteed or officially supported by this project.
|
|
76
|
+
|
|
77
|
+
## Experimental note (alpha)
|
|
78
|
+
|
|
79
|
+
This is an experimental (alpha) version. The following MCP tool sequence has been tested and works for me:
|
|
80
|
+
|
|
81
|
+
1. saleae_connect (for Saleae Logic 1.2.40)
|
|
82
|
+
2. saleae_configure
|
|
83
|
+
3. saleae_capture — save capture in .logicdata format
|
|
84
|
+
4. parse_capture_file (optional)
|
|
85
|
+
5. get_digital_data_mcp
|
|
86
|
+
6. saleae_export (optional. use csv if needed)
|
|
87
|
+
|
|
88
|
+
Notes:
|
|
89
|
+
- Make sure the Saleae Logic application is running and the scripting socket server is enabled before using these tools.
|
|
90
|
+
- When calling saleae_capture, request the .logicdata format for best compatibility with the controller methods.
|
|
91
|
+
|
|
92
|
+
## Troubleshooting & Important Notes
|
|
93
|
+
|
|
94
|
+
- **Logic Software Must Be Running:**
|
|
95
|
+
- Before using this automation interface, ensure that the Saleae Logic software is already running on your system. The automation scripts will attempt to connect to the running instance.
|
|
96
|
+
- If the software is not running, the script may fail to connect, or may launch a new instance in simulation mode (which will not detect your real device).
|
|
97
|
+
|
|
98
|
+
- **Enable Scripting Socket Server:**
|
|
99
|
+
- In the Logic software, go to `Options` > `Preferences` (or `Edit` > `Preferences`), and ensure that the "Enable scripting socket server" option is checked.
|
|
100
|
+
- The default port is usually 10429. If you change this, update your scripts accordingly.
|
|
101
|
+
- If the scripting server is not enabled, the Python API will not be able to communicate with Logic, and you will see connection errors.
|
|
102
|
+
|
|
103
|
+
- **Device Not Detected:**
|
|
104
|
+
- Make sure your Logic device is connected to your computer and recognized by the Logic software before running any scripts.
|
|
105
|
+
- If the device is not detected, check your USB connection and try restarting the Logic software.
|
|
106
|
+
|
|
107
|
+
- **Architecture Compatibility:**
|
|
108
|
+
- Ensure that both the Logic software and your Python environment are either both 32-bit or both 64-bit. Mismatched architectures can cause connection failures.
|
|
109
|
+
|
|
110
|
+
- **Permissions:**
|
|
111
|
+
- On some systems, you may need to run the Logic software and/or your Python script with administrator privileges to allow socket communication.
|
|
112
|
+
|
|
113
|
+
- **Supported Versions:**
|
|
114
|
+
- This project is designed for Saleae Logic 1.x/2.x automation. Some features may only be available in Logic 2.x with the appropriate automation API installed.
|
|
115
|
+
|
|
116
|
+
### Note on Capture File Formats
|
|
117
|
+
|
|
118
|
+
- **.logicdata format** is the recommended and best-supported file format for captures. All automation and parsing features are designed to work reliably with `.logicdata` files.
|
|
119
|
+
- **.sal files** (used by some older or alternative Saleae software) are currently known to have bugs and compatibility issues. Automated conversion or processing of `.sal` files may fail or require manual fixes. For best results, always use `.logicdata` format for your captures.
|
|
120
|
+
|
|
121
|
+
## API Reference
|
|
122
|
+
|
|
123
|
+
### SaleaeController
|
|
124
|
+
|
|
125
|
+
The main controller class that provides high-level access to Logic 2 functionality.
|
|
126
|
+
|
|
127
|
+
#### Device Configuration Methods:
|
|
128
|
+
|
|
129
|
+
- `create_device_config(name: str, digital_channels: List[int], digital_sample_rate: int, analog_channels: Optional[List[int]] = None, analog_sample_rate: Optional[int] = None, digital_threshold_volts: Optional[float] = None) -> str`
|
|
130
|
+
- Creates a new device configuration with specified channels and sample rates
|
|
131
|
+
- Returns the configuration name
|
|
132
|
+
|
|
133
|
+
- `get_device_config(name: str) -> Optional[LogicDeviceConfiguration]`
|
|
134
|
+
- Retrieves a device configuration by name
|
|
135
|
+
- Returns None if not found
|
|
136
|
+
|
|
137
|
+
- `list_device_configs() -> List[str]`
|
|
138
|
+
- Lists all available device configuration names
|
|
139
|
+
|
|
140
|
+
- `remove_device_config(name: str) -> bool`
|
|
141
|
+
- Removes a device configuration
|
|
142
|
+
- Returns True if successful, False if not found
|
|
143
|
+
|
|
144
|
+
#### Capture Configuration Methods:
|
|
145
|
+
|
|
146
|
+
- `create_capture_config(name: str, duration_seconds: float, buffer_size_megabytes: Optional[int] = None) -> str`
|
|
147
|
+
- Creates a new capture configuration with specified duration
|
|
148
|
+
- Returns the configuration name
|
|
149
|
+
|
|
150
|
+
- `get_capture_config(name: str) -> Optional[CaptureConfiguration]`
|
|
151
|
+
- Retrieves a capture configuration by name
|
|
152
|
+
- Returns None if not found
|
|
153
|
+
|
|
154
|
+
- `list_capture_configs() -> List[str]`
|
|
155
|
+
- Lists all available capture configuration names
|
|
156
|
+
|
|
157
|
+
- `remove_capture_config(name: str) -> bool`
|
|
158
|
+
- Removes a capture configuration
|
|
159
|
+
- Returns True if successful, False if not found
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
## Configurations:
|
|
163
|
+
|
|
164
|
+
### Claude configuration (with uv run):
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"mcpServers": {
|
|
168
|
+
"logic-analyzer-ai-mcp": {
|
|
169
|
+
"type": "stdio",
|
|
170
|
+
"command": "uv",
|
|
171
|
+
"args": [
|
|
172
|
+
"--directory",
|
|
173
|
+
"<path to folder>",
|
|
174
|
+
"run",
|
|
175
|
+
"-m",
|
|
176
|
+
"logic_analyzer_mcp"
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Claude configuration (direct usage):
|
|
184
|
+
```json
|
|
185
|
+
{
|
|
186
|
+
"mcpServers": {
|
|
187
|
+
"logic-analyzer-ai-mcp": {
|
|
188
|
+
"type": "stdio",
|
|
189
|
+
"command": "python",
|
|
190
|
+
"args": [
|
|
191
|
+
"<path to folder>\\src\\logic_analyzer_mcp.py"
|
|
192
|
+
]
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
### Claude configuration (with uv run):
|
|
200
|
+
```json
|
|
201
|
+
{
|
|
202
|
+
"mcpServers": {
|
|
203
|
+
"logic-analyzer-ai-mcp": {
|
|
204
|
+
"type": "stdio",
|
|
205
|
+
"command": "uv",
|
|
206
|
+
"args": [
|
|
207
|
+
"--directory",
|
|
208
|
+
"<path to folder>",
|
|
209
|
+
"run",
|
|
210
|
+
"-m",
|
|
211
|
+
"logic_analyzer_mcp"
|
|
212
|
+
]
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Logic2 parameter description
|
|
219
|
+
|
|
220
|
+
This project includes an opt-in experimental path for Logic2 automation. It is disabled by default. You can enable it in one of three ways:
|
|
221
|
+
|
|
222
|
+
- CLI flag (recommended for one-off runs)
|
|
223
|
+
- Example:
|
|
224
|
+
- python -m logic_analyzer_mcp --logic2
|
|
225
|
+
|
|
226
|
+
- Environment variable (convenient for CI / persistent shells)
|
|
227
|
+
- Example (Unix):
|
|
228
|
+
- LOGIC2=1 python -m logic_analyzer_mcp
|
|
229
|
+
- Example (Windows PowerShell):
|
|
230
|
+
- $env:LOGIC2='1'; python -m logic_analyzer_mcp
|
|
231
|
+
|
|
232
|
+
- Programmatic API (when embedding the library)
|
|
233
|
+
- Call the helper before registering tools:
|
|
234
|
+
- from mcp_tools import set_logic2_enabled, setup_mcp_tools
|
|
235
|
+
- set_logic2_enabled(True)
|
|
236
|
+
- setup_mcp_tools(mcp, controller)
|
|
237
|
+
- Or pass the explicit parameter to setup_mcp_tools:
|
|
238
|
+
- setup_mcp_tools(mcp, controller, enable_logic2=True)
|
|
239
|
+
|
|
240
|
+
Notes
|
|
241
|
+
- Default behavior: Logic2 experimental features are OFF. When disabled the code prefers controller-based or offline fallbacks.
|
|
242
|
+
- Safety: Experimental features may change — enable intentionally and test with your environment before using in production.
|
|
243
|
+
- Troubleshooting: If enabling Logic2 fails, check that the logic2-automation / python-saleae packages are installed and that the Saleae app is running and reachable.
|
|
244
|
+
|
|
245
|
+
## Claude configuration (example)
|
|
246
|
+
|
|
247
|
+
Below is a minimal Claude MCP server configuration example you can adapt. Place this under your Claude configuration file or tooling settings.
|
|
248
|
+
|
|
249
|
+
```json
|
|
250
|
+
{
|
|
251
|
+
"mcpServers": {
|
|
252
|
+
"logic-analyzer-ai-mcp": {
|
|
253
|
+
"type": "stdio",
|
|
254
|
+
"command": "uv",
|
|
255
|
+
"args": [
|
|
256
|
+
"--directory",
|
|
257
|
+
"<path to folder>",
|
|
258
|
+
"run",
|
|
259
|
+
"-m",
|
|
260
|
+
"logic_analyzer_mcp",
|
|
261
|
+
"--logic2"
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Notes:
|
|
269
|
+
- Remove the `--logic2` flag if you do not want experimental Logic2 tools enabled.
|
|
270
|
+
- Adjust `<path to folder>` and other `uv` arguments to match your environment.
|
|
271
|
+
- Use the `python` based configuration if you prefer to invoke the module directly instead of via `uv`.
|
iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/PKG-INFO
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: iflow-mcp_wegitor-logic_analyzer_mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Saleae Logic capture file parser using MCP
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Requires-Dist: logic2-automation>=1.0.7
|
|
7
|
+
Requires-Dist: saleae>=0.12.0
|
|
8
|
+
Requires-Dist: grpcio>=1.71.0
|
|
9
|
+
Requires-Dist: grpcio-tools>=1.71.0
|
|
10
|
+
Requires-Dist: protobuf>=6.30.2
|
|
11
|
+
Requires-Dist: mcp[cli]
|
|
12
|
+
Requires-Dist: pytest
|
iflow_mcp_wegitor_logic_analyzer_mcp-0.1.0/iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/SOURCES.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/PKG-INFO
|
|
4
|
+
iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/SOURCES.txt
|
|
5
|
+
iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/dependency_links.txt
|
|
6
|
+
iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/entry_points.txt
|
|
7
|
+
iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/requires.txt
|
|
8
|
+
iflow_mcp_wegitor_logic_analyzer_mcp.egg-info/top_level.txt
|
|
9
|
+
src/__init__.py
|
|
10
|
+
src/__main__.py
|
|
11
|
+
src/logic_analyzer_mcp.py
|
|
12
|
+
src/mcp_tools.py
|
|
13
|
+
src/mcp_tools_experimental.py
|
|
14
|
+
src/saleae_manager.py
|
|
15
|
+
src/controllers/__init__.py
|
|
16
|
+
src/controllers/logic2_automation_controller.py
|
|
17
|
+
src/controllers/saleae_controller.py
|
|
18
|
+
src/controllers/saleae_parser_controller.py
|
|
19
|
+
tests/test_saleae_connection.py
|
|
20
|
+
tests/test_saleae_controller.py
|
|
21
|
+
tests/test_saleae_parser_controller.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
logic_analyzer_mcp
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=42", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "iflow-mcp_wegitor-logic_analyzer_mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Saleae Logic capture file parser using MCP"
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"logic2-automation>=1.0.7",
|
|
12
|
+
"saleae>=0.12.0",
|
|
13
|
+
"grpcio>=1.71.0",
|
|
14
|
+
"grpcio-tools>=1.71.0",
|
|
15
|
+
"protobuf>=6.30.2",
|
|
16
|
+
"mcp[cli]",
|
|
17
|
+
"pytest"
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[tool.pytest.ini_options]
|
|
21
|
+
pythonpath = [
|
|
22
|
+
"."
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[tool.hatch.metadata]
|
|
26
|
+
allow-direct-references = true
|
|
27
|
+
|
|
28
|
+
[tool.hatch.build.targets.wheel]
|
|
29
|
+
packages = ["src"]
|
|
30
|
+
|
|
31
|
+
[tool.ruff]
|
|
32
|
+
line-length = 100
|
|
33
|
+
target-version = "py310"
|
|
34
|
+
select = ["E", "F", "I", "N", "W", "B"]
|
|
35
|
+
ignore = []
|
|
36
|
+
|
|
37
|
+
[tool.ruff.isort]
|
|
38
|
+
known-first-party = ["src"]
|
|
39
|
+
|
|
40
|
+
[project.scripts]
|
|
41
|
+
logic_analyzer_mcp = "logic_analyzer_mcp:main"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools]
|
|
44
|
+
package-dir = {"logic_analyzer_mcp" = "src"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Controllers package for Saleae Logic Usage.
|
|
3
|
+
|
|
4
|
+
This package contains the Logic2AutomationController for Logic 2 device and capture management:
|
|
5
|
+
- Logic2AutomationController: Device configuration, capture management, and device discovery
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
# Import controllers so they can be imported from the controllers package
|
|
9
|
+
from .logic2_automation_controller import Logic2AutomationController
|
|
10
|
+
from .saleae_controller import SaleaeController
|
|
11
|
+
from .saleae_parser_controller import SaleaeParserController
|
|
12
|
+
# Note: The TemplateController class has been moved to template_controller.py to avoid import issues
|
|
13
|
+
|
|
14
|
+
__all__ = ['Logic2AutomationController']
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
from typing import List, Optional, Dict
|
|
2
|
+
from saleae.automation import Manager, LogicDeviceConfiguration, CaptureConfiguration, TimedCaptureMode, DeviceType
|
|
3
|
+
|
|
4
|
+
class Logic2AutomationController:
|
|
5
|
+
"""Controller for managing Logic 2 automation device configurations and captures."""
|
|
6
|
+
|
|
7
|
+
def __init__(self, manager: Manager):
|
|
8
|
+
"""
|
|
9
|
+
Initialize the Logic 2 automation controller.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
manager (Manager): Logic 2 automation manager instance
|
|
13
|
+
"""
|
|
14
|
+
self.manager = manager
|
|
15
|
+
self._device_configs: Dict[str, LogicDeviceConfiguration] = {}
|
|
16
|
+
self._capture_configs: Dict[str, CaptureConfiguration] = {}
|
|
17
|
+
|
|
18
|
+
def create_device_config(self,
|
|
19
|
+
name: str,
|
|
20
|
+
digital_channels: List[int],
|
|
21
|
+
digital_sample_rate: int,
|
|
22
|
+
analog_channels: Optional[List[int]] = None,
|
|
23
|
+
analog_sample_rate: Optional[int] = None,
|
|
24
|
+
digital_threshold_volts: Optional[float] = None) -> str:
|
|
25
|
+
"""
|
|
26
|
+
Create a new device configuration.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
name (str): Name for the configuration
|
|
30
|
+
digital_channels (List[int]): List of digital channels to enable
|
|
31
|
+
digital_sample_rate (int): Digital sample rate in Hz
|
|
32
|
+
analog_channels (List[int], optional): List of analog channels to enable
|
|
33
|
+
analog_sample_rate (int, optional): Analog sample rate in Hz
|
|
34
|
+
digital_threshold_volts (float, optional): Digital threshold voltage
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
str: Configuration name
|
|
38
|
+
"""
|
|
39
|
+
config = LogicDeviceConfiguration(
|
|
40
|
+
enabled_digital_channels=digital_channels,
|
|
41
|
+
digital_sample_rate=digital_sample_rate,
|
|
42
|
+
enabled_analog_channels=analog_channels or [],
|
|
43
|
+
analog_sample_rate=analog_sample_rate,
|
|
44
|
+
digital_threshold_volts=digital_threshold_volts
|
|
45
|
+
)
|
|
46
|
+
self._device_configs[name] = config
|
|
47
|
+
return name
|
|
48
|
+
|
|
49
|
+
def create_capture_config(self,
|
|
50
|
+
name: str,
|
|
51
|
+
duration_seconds: float,
|
|
52
|
+
buffer_size_megabytes: Optional[int] = None) -> str:
|
|
53
|
+
"""
|
|
54
|
+
Create a new capture configuration.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
name (str): Name for the configuration
|
|
58
|
+
duration_seconds (float): Capture duration in seconds
|
|
59
|
+
buffer_size_megabytes (int, optional): Buffer size in MB
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
str: Configuration name
|
|
63
|
+
"""
|
|
64
|
+
config = CaptureConfiguration(
|
|
65
|
+
capture_mode=TimedCaptureMode(duration_seconds=duration_seconds),
|
|
66
|
+
buffer_size_megabytes=buffer_size_megabytes
|
|
67
|
+
)
|
|
68
|
+
self._capture_configs[name] = config
|
|
69
|
+
return name
|
|
70
|
+
|
|
71
|
+
def get_device_config(self, name: str) -> Optional[LogicDeviceConfiguration]:
|
|
72
|
+
"""Get a device configuration by name."""
|
|
73
|
+
return self._device_configs.get(name)
|
|
74
|
+
|
|
75
|
+
def get_capture_config(self, name: str) -> Optional[CaptureConfiguration]:
|
|
76
|
+
"""Get a capture configuration by name."""
|
|
77
|
+
return self._capture_configs.get(name)
|
|
78
|
+
|
|
79
|
+
def list_device_configs(self) -> List[str]:
|
|
80
|
+
"""List all available device configurations."""
|
|
81
|
+
return list(self._device_configs.keys())
|
|
82
|
+
|
|
83
|
+
def list_capture_configs(self) -> List[str]:
|
|
84
|
+
"""List all available capture configurations."""
|
|
85
|
+
return list(self._capture_configs.keys())
|
|
86
|
+
|
|
87
|
+
def remove_device_config(self, name: str) -> bool:
|
|
88
|
+
"""Remove a device configuration."""
|
|
89
|
+
if name in self._device_configs:
|
|
90
|
+
del self._device_configs[name]
|
|
91
|
+
return True
|
|
92
|
+
return False
|
|
93
|
+
|
|
94
|
+
def remove_capture_config(self, name: str) -> bool:
|
|
95
|
+
"""Remove a capture configuration."""
|
|
96
|
+
if name in self._capture_configs:
|
|
97
|
+
del self._capture_configs[name]
|
|
98
|
+
return True
|
|
99
|
+
return False
|
|
100
|
+
|
|
101
|
+
def get_available_devices(self) -> List[Dict]:
|
|
102
|
+
"""
|
|
103
|
+
Get list of available Logic devices.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
List[Dict]: List of device information dictionaries with masked device IDs
|
|
107
|
+
"""
|
|
108
|
+
devices = self.manager.get_devices()
|
|
109
|
+
return [
|
|
110
|
+
{
|
|
111
|
+
'id': f"{device.device_id[:4]}...{device.device_id[-4:]}" if len(device.device_id) > 8 else "****",
|
|
112
|
+
'type': device.device_type,
|
|
113
|
+
'is_simulation': device.is_simulation
|
|
114
|
+
}
|
|
115
|
+
for device in devices
|
|
116
|
+
]
|
|
117
|
+
|
|
118
|
+
def find_device_by_type(self, device_type: DeviceType) -> Optional[Dict]:
|
|
119
|
+
"""
|
|
120
|
+
Find a device by its type.
|
|
121
|
+
|
|
122
|
+
Args:
|
|
123
|
+
device_type (DeviceType): Type of device to find
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
Optional[Dict]: Device information if found, None otherwise
|
|
127
|
+
|
|
128
|
+
Raises:
|
|
129
|
+
ValueError: If the device type is not supported
|
|
130
|
+
"""
|
|
131
|
+
# Check if device type is supported
|
|
132
|
+
if device_type in [DeviceType.LOGIC, DeviceType.LOGIC_4, DeviceType.LOGIC_16]:
|
|
133
|
+
raise ValueError(f"Device type {device_type.name} is not supported by Logic 2 software")
|
|
134
|
+
|
|
135
|
+
devices = self.get_available_devices()
|
|
136
|
+
for device in devices:
|
|
137
|
+
if device['type'] == device_type:
|
|
138
|
+
return device
|
|
139
|
+
return None
|