Automation¶
High-level automation and data collection
Automation and programmatic data collection for Siglent oscilloscopes.
This module provides high-level APIs for automated data collection, batch processing, and analysis of oscilloscope traces. It simplifies common workflows for users who want to collect and analyze data programmatically.
Example
Simple waveform capture:
from scpi_control import Oscilloscope from scpi_control.automation import DataCollector
collector = DataCollector('192.168.1.100') collector.connect() data = collector.capture_single([1, 2]) # Capture channels 1 and 2 collector.save_data(data, 'measurement.npz') collector.disconnect()
Batch collection with different timebase settings:
collector = DataCollector('192.168.1.100') with collector: ... results = collector.batch_capture( ... channels=[1], ... timebase_scales=['1us', '10us', '100us'], ... triggers_per_config=10 ... ) ... collector.save_batch(results, 'batch_data')
Time-series collection:
collector = DataCollector('192.168.1.100') with collector: ... collector.start_continuous_capture( ... channels=[1, 2], ... duration=60, # 60 seconds ... interval=1.0, # 1 capture per second ... output_dir='time_series_data' ... )
DataCollector
¶
DataCollector(host: str, port: int = 5024, timeout: float = 5.0, connection: Optional[BaseConnection] = None)
High-level API for automated oscilloscope data collection.
This class wraps the Oscilloscope class and provides convenient methods for common data collection workflows, batch processing, and automated measurements.
Initialize data collector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
IP address or hostname of the oscilloscope |
required |
port
|
int
|
TCP port for SCPI communication (default: 5024) |
5024
|
timeout
|
float
|
Command timeout in seconds (default: 5.0) |
5.0
|
connection
|
Optional[BaseConnection]
|
Optional connection implementation (e.g., MockConnection for offline tests) |
None
|
Source code in scpi_control/automation.py
connect
¶
disconnect
¶
capture_single
¶
Capture waveforms from specified channels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
List[int]
|
List of channel numbers to capture (e.g., [1, 2, 3]) |
required |
auto_setup
|
bool
|
If True, run auto-setup before capture |
False
|
Returns:
| Type | Description |
|---|---|
Dict[int, WaveformData]
|
Dictionary mapping channel number to WaveformData object |
Example
data = collector.capture_single([1, 2]) print(f"Channel 1: {len(data[1].voltage)} samples") print(f"Sample rate: {data[1].sample_rate} Hz")
Source code in scpi_control/automation.py
batch_capture
¶
batch_capture(channels: List[int], timebase_scales: Optional[List[str]] = None, voltage_scales: Optional[Dict[int, List[str]]] = None, triggers_per_config: int = 1, progress_callback: Optional[Callable[[int, int, str], None]] = None) -> List[Dict[str, Any]]
Capture multiple waveforms with different configurations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
List[int]
|
List of channel numbers to capture |
required |
timebase_scales
|
Optional[List[str]]
|
List of timebase scale strings (e.g., ['1us', '10us', '100us']) |
None
|
voltage_scales
|
Optional[Dict[int, List[str]]]
|
Dict mapping channel number to list of voltage scale strings (e.g., {1: ['1V', '2V'], 2: ['500mV', '1V']}) |
None
|
triggers_per_config
|
int
|
Number of captures per configuration |
1
|
progress_callback
|
Optional[Callable[[int, int, str], None]]
|
Optional callback function(current, total, status) |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of dictionaries containing waveforms and configuration metadata |
Example
results = collector.batch_capture( ... channels=[1], ... timebase_scales=['1us', '10us', '100us'], ... triggers_per_config=5 ... ) print(f"Collected {len(results)} captures")
Source code in scpi_control/automation.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
start_continuous_capture
¶
start_continuous_capture(channels: List[int], duration: float, interval: float = 1.0, output_dir: Optional[Union[str, Path]] = None, file_format: str = 'npz', progress_callback: Optional[Callable[[int, str], None]] = None) -> List[Dict[str, Any]]
Capture waveforms continuously over a time period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
List[int]
|
List of channel numbers to capture |
required |
duration
|
float
|
Total capture duration in seconds |
required |
interval
|
float
|
Time between captures in seconds |
1.0
|
output_dir
|
Optional[Union[str, Path]]
|
Optional directory to save captures (saves to memory if None) |
None
|
file_format
|
str
|
Format for saved files ('npz', 'csv', 'mat', 'h5') |
'npz'
|
progress_callback
|
Optional[Callable[[int, str], None]]
|
Optional callback function(captures_done, status) |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of capture dictionaries (or empty list if output_dir is specified) |
Example
Capture for 60 seconds, save to files¶
collector.start_continuous_capture( ... channels=[1, 2], ... duration=60, ... interval=2.0, ... output_dir='continuous_data', ... file_format='npz' ... )
Source code in scpi_control/automation.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
save_data
¶
Save captured waveform data to file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
waveforms
|
Dict[int, WaveformData]
|
Dictionary mapping channel number to WaveformData |
required |
filename
|
str
|
Output filename |
required |
format
|
str
|
File format ('npz', 'csv', 'mat', 'h5') |
'npz'
|
Example
data = collector.capture_single([1, 2]) collector.save_data(data, 'measurement.npz')
Source code in scpi_control/automation.py
save_batch
¶
Save batch capture results to directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_results
|
List[Dict[str, Any]]
|
List of batch capture results |
required |
output_dir
|
str
|
Output directory path |
required |
format
|
str
|
File format ('npz', 'csv', 'mat', 'h5') |
'npz'
|
Example
results = collector.batch_capture(...) collector.save_batch(results, 'batch_output')
Source code in scpi_control/automation.py
analyze_waveform
¶
Analyze a waveform and extract common measurements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
waveform
|
WaveformData
|
WaveformData object to analyze |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
Dictionary of measurement names and values |
Example
data = collector.capture_single([1]) stats = collector.analyze_waveform(data[1]) print(f"Peak-to-peak: {stats['vpp']:.3f}V") print(f"RMS: {stats['rms']:.3f}V")
Source code in scpi_control/automation.py
TriggerWaitCollector
¶
TriggerWaitCollector(host: str, port: int = 5024, timeout: float = 5.0, connection: Optional[BaseConnection] = None)
Specialized collector for waiting on specific trigger conditions.
Useful for capturing events that occur sporadically or based on specific signal conditions.
Initialize trigger wait collector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
IP address or hostname of the oscilloscope |
required |
port
|
int
|
TCP port for SCPI communication |
5024
|
timeout
|
float
|
Command timeout in seconds |
5.0
|
connection
|
Optional[BaseConnection]
|
Optional connection implementation (e.g., MockConnection for offline tests) |
None
|
Source code in scpi_control/automation.py
wait_for_trigger
¶
wait_for_trigger(channels: List[int], max_wait: float = 60.0, save_on_trigger: bool = True, output_dir: Optional[str] = None) -> Optional[Dict[int, WaveformData]]
Wait for a trigger event and capture waveform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
List[int]
|
List of channel numbers to capture |
required |
max_wait
|
float
|
Maximum time to wait for trigger in seconds |
60.0
|
save_on_trigger
|
bool
|
If True, save waveform when triggered |
True
|
output_dir
|
Optional[str]
|
Directory to save waveforms (required if save_on_trigger=True) |
None
|
Returns:
| Type | Description |
|---|---|
Optional[Dict[int, WaveformData]]
|
Captured waveforms or None if timeout |
Example
with TriggerWaitCollector('192.168.1.100') as tc: ... # Configure trigger on channel 1, edge = rising, level = 1V ... tc.collector.scope.trigger.set_source(1) ... tc.collector.scope.trigger.set_slope('POS') ... tc.collector.scope.trigger.set_level(1, 1.0) ... ... # Wait for trigger ... data = tc.wait_for_trigger([1, 2], max_wait=30.0) ... if data: ... print("Trigger captured!")
Source code in scpi_control/automation.py
See Also¶
- Oscilloscope - Main oscilloscope control class for SCPI communication
- Waveform - Waveform acquisition and data handling
- Measurement - Automated measurements (frequency, voltage, timing)