-
Notifications
You must be signed in to change notification settings - Fork 0
Main modules
Modules and Functionality
The connections
module manages communication with instruments, ensuring reliable and consistent data exchange. It handles the detection and configuration of serial ports, manages baud rate settings, and maintains a registry of connected instruments. This module is designed to support multiple instruments without conflicts, leveraging serial numbers to uniquely identify each device.
Key responsibilities include:
- Detecting available instruments and their communication parameters.
- Establishing and maintaining instrument connections.
- Providing access to instruments through a singleton pattern to ensure consistency across the application.
- Handling instrument disconnections and reconnections dynamically.
The tasks
module provides an execution framework for running measurement and control tasks asynchronously. Each task operates within its own thread and follows a structured lifecycle.
Core features:
- Task management through a singleton
Tasks
class. - Ability to define and register tasks dynamically.
- Each task encapsulates its own execution logic and associated instruments.
- Tasks operate in continuous loops, ensuring real-time data acquisition and processing.
- Safe stopping mechanism using an
Event
flag to gracefully terminate task execution. - Chart data storage for logging and visualization.
Before a task is started, a check is performed to ensure all required instruments are available. If an instrument is missing, the task is not executed, preventing runtime errors.
The instruments
module defines a structured representation of connected devices, abstracting their functionalities to a unified interface. Instruments are identified and accessed through the connections
module, allowing seamless integration within tasks.
Primary functionalities:
- Standardized interface for interacting with different instruments.
- Encapsulation of instrument properties and methods.
- Automatic detection and registration in the system.
- Instrument-specific command execution, including SCPI communication where applicable.
To extend the system with new measurement or control functionalities, users can define custom tasks within the user_defined
module.
- Define a new function that implements the task logic. The function must accept a list of
ChartData
objects and anEvent
flag for controlled execution. - Instantiate a
Task
object, linking it to the function and specifying required instrument aliases. - Register the task within the
Tasks
singleton using theadd_task
method.
from tasks import Task, Tasks, ChartData
from threading import Event
def my_custom_task(data: list[ChartData], exit_flag: Event) -> None:
# Task execution loop
while not exit_flag.is_set():
# Task logic goes here
pass
# Task initialization
new_task = Task(
name="CustomTask",
description="An example custom task",
instrs_aliases=["instrument_1"],
function=my_custom_task
)
# Register the task
Tasks().add_task(new_task)