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 = 5025, timeout: float = 5.0, connection: Optional[BaseConnection] = None, dialect: Optional[str] = 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: 5025, the Siglent raw SCPI socket; 5024 is the telnet-style port with prompts and is not recommended) |
5025
|
timeout
|
float
|
Command timeout in seconds (default: 5.0) |
5.0
|
connection
|
Optional[BaseConnection]
|
Optional connection implementation (e.g., MockConnection for offline tests) |
None
|
dialect
|
Optional[str]
|
Optional SCPI dialect override passed to Oscilloscope ("legacy" or "modern"; None auto-detects) |
None
|
Source code in scpi_control/automation.py
from_scope
classmethod
¶
Wrap an Oscilloscope the caller already owns and connected.
init builds its own Oscilloscope from a host, which leaves no way to reuse capture_single's arm-and-wait logic against an existing session. The scope's lifetime stays with the caller: this does not connect, and disconnect() on the result would close a session it did not open.
Source code in scpi_control/automation.py
connect
¶
disconnect
¶
capture_single
¶
capture_single(channels: List[int], auto_setup: bool = False, max_wait: Optional[float] = None) -> Dict[int, WaveformData]
Capture waveforms from specified channels.
If the scope is already in NORM trigger mode, this waits for the next natural trigger instead of arming a single acquisition -- the user's configured mode is left running rather than being overwritten. In any other mode (including the default) it arms a single acquisition as before. Previously this method always forced a single-shot regardless of mode; a NORM-mode caller upgrading past this change will see capture_single wait for a real trigger instead of forcing one.
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
|
max_wait
|
Optional[float]
|
Seconds to wait for the acquisition to complete. Must be positive. None (default) derives a budget from the current timebase. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[int, WaveformData]
|
Dictionary mapping channel number to WaveformData object |
Raises:
| Type | Description |
|---|---|
InvalidParameterError
|
If max_wait is not positive. |
SiglentTimeoutError
|
If the acquisition does not complete in time. Reading anyway would return the PREVIOUS acquisition, which is what this replaced. |
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
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 | |
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, max_consecutive_failures: Optional[int] = 3) -> 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
|
max_consecutive_failures
|
Optional[int]
|
Stop the run after this many back-to-back
capture timeouts, counted ACROSS configurations and reset by any
success. Guards the common unattended failure -- a trigger level
set where the signal never crosses it -- which otherwise times
out on every capture for the whole run: at a 70 s timeout and
100 triggers per configuration that is hours of waiting to
collect nothing. Pass None to disable the breaker entirely; a
run with genuinely sparse triggers should raise |
3
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of dictionaries containing waveforms and configuration metadata. |
List[Dict[str, Any]]
|
When the breaker trips (or the run is interrupted) everything gathered |
List[Dict[str, Any]]
|
so far is still returned -- failed entries carry an |
List[Dict[str, Any]]
|
rather than being discarded. |
Raises:
| Type | Description |
|---|---|
InvalidParameterError
|
If a scale cannot be parsed, or
|
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
241 242 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 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
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. Without |
List[Dict[str, Any]]
|
carries the captured |
List[Dict[str, Any]]
|
arrays are omitted (they are on disk) and each entry instead lists |
List[Dict[str, Any]]
|
the |
List[Dict[str, Any]]
|
happened and where they went. |
Raises:
| Type | Description |
|---|---|
SiglentError
|
If the very first save fails and no file was written.
That means the run is misconfigured -- a rejected |
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
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | |
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
|
Optional[str]
|
File format - one of 'CSV', 'CSV_ENHANCED', 'NPY', 'MAT', 'HDF5'. If None (default), the format is auto-detected from each generated per-channel filename's extension. |
None
|
Example
data = collector.capture_single([1, 2]) collector.save_data(data, 'measurement.npz')
writes measurement_ch1.npz and measurement_ch2.npz -- one file¶
per channel, suffixed with "_ch{n}" before the extension.¶
Source code in scpi_control/automation.py
save_batch
¶
save_batch(batch_results: List[Dict[str, Any]], output_dir: str, format: Optional[str] = None) -> None
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
|
Optional[str]
|
File format - one of 'CSV', 'CSV_ENHANCED', 'NPY', 'MAT', 'HDF5'. If None (default), the format is auto-detected from each generated filename's extension. |
None
|
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 = 5025, timeout: float = 5.0, connection: Optional[BaseConnection] = None, dialect: Optional[str] = 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 (default: 5025, the Siglent raw SCPI socket; 5024 is the telnet-style port with prompts and is not recommended) |
5025
|
timeout
|
float
|
Command timeout in seconds |
5.0
|
connection
|
Optional[BaseConnection]
|
Optional connection implementation (e.g., MockConnection for offline tests) |
None
|
dialect
|
Optional[str]
|
Optional SCPI dialect override passed to Oscilloscope ("legacy" or "modern"; None auto-detects) |
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.
If the trigger mode has been set to NORMAL beforehand (e.g. via
trigger.set_mode('NORMAL')), that mode is preserved and the wait
completes on the first trigger event. In any other mode, the scope is
switched to SINGLE and armed for a one-shot acquisition.
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)