2023-07-31 11:20:14 +00:00
|
|
|
import logging
|
2023-07-31 13:24:46 +00:00
|
|
|
import serial
|
2023-07-31 11:20:14 +00:00
|
|
|
from serial.tools.list_ports import comports
|
2023-07-31 06:50:34 +00:00
|
|
|
from nqrduck.module.module_controller import ModuleController
|
|
|
|
|
2023-07-31 11:20:14 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2023-07-31 06:50:34 +00:00
|
|
|
class AutoTMController(ModuleController):
|
2023-07-31 13:24:46 +00:00
|
|
|
BAUDRATE = 115200
|
2023-07-31 11:20:14 +00:00
|
|
|
|
2023-07-31 13:24:46 +00:00
|
|
|
def find_devices(self) -> None:
|
2023-07-31 11:20:14 +00:00
|
|
|
"""Scan for available serial devices and add them to the model as available devices. """
|
|
|
|
logger.debug("Scanning for available serial devices")
|
|
|
|
ports = comports()
|
|
|
|
self.module.model.available_devices = [port.device for port in ports]
|
|
|
|
logger.debug("Found %s devices", len(self.module.model.available_devices))
|
|
|
|
for device in self.module.model.available_devices:
|
|
|
|
logger.debug("Found device: %s", device)
|
2023-07-31 13:24:46 +00:00
|
|
|
|
|
|
|
def connect(self, device : str) -> None:
|
|
|
|
"""Connect to the specified device. """
|
|
|
|
logger.debug("Connecting to device %s", device)
|
|
|
|
try:
|
|
|
|
self.module.model.serial = serial.Serial(device, self.BAUDRATE, timeout=0.1)
|
|
|
|
logger.debug("Connected to device %s", device)
|
|
|
|
except serial.SerialException as e:
|
|
|
|
logger.error("Failed to connect to device %s", device)
|
|
|
|
logger.error(e)
|
2023-07-31 13:43:54 +00:00
|
|
|
|
2023-08-01 07:08:51 +00:00
|
|
|
def start_frequency_sweep(self, start_frequency : float, stop_frequency : float) -> None:
|
|
|
|
""" This starts a frequency sweep on the device in the specified range."""
|
|
|
|
pass
|