Coverage for / opt / hostedtoolcache / Python / 3.11.14 / x64 / lib / python3.11 / site-packages / rattlesnake / components / abstract_hardware.py: 100%
32 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-27 18:22 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-27 18:22 +0000
1# -*- coding: utf-8 -*-
2"""
3Abstract hardware definition that can be used to implement new hardware devices
5Rattlesnake Vibration Control Software
6Copyright (C) 2021 National Technology & Engineering Solutions of Sandia, LLC
7(NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
8Government retains certain rights in this software.
10This program is free software: you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation, either version 3 of the License, or
13(at your option) any later version.
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
20You should have received a copy of the GNU General Public License
21along with this program. If not, see <https://www.gnu.org/licenses/>.
22"""
24from abc import ABC, abstractmethod
25from typing import List
27import numpy as np
29from .utilities import Channel, DataAcquisitionParameters
32class HardwareAcquisition(ABC):
33 """Abstract class defining the interface between the controller and acquisition
35 This class defines the interfaces between the controller and the
36 data acquisition portion of the hardware. It is run by the Acquisition
37 process, and must define how to get data from the test hardware into the
38 controller."""
40 @abstractmethod
41 def set_up_data_acquisition_parameters_and_channels(
42 self, test_data: DataAcquisitionParameters, channel_data: List[Channel]
43 ):
44 """
45 Initialize the hardware and set up channels and sampling properties
47 The function must create channels on the hardware corresponding to
48 the channels in the test. It must also set the sampling rates.
50 Parameters
51 ----------
52 test_data : DataAcquisitionParameters :
53 A container containing the data acquisition parameters for the
54 controller set by the user.
55 channel_data : List[Channel] :
56 A list of ``Channel`` objects defining the channels in the test
58 Returns
59 -------
60 None.
62 """
64 @abstractmethod
65 def start(self):
66 """Method to start acquiring data from the hardware"""
68 @abstractmethod
69 def read(self) -> np.ndarray:
70 """Method to read a frame of data from the hardware that returns
71 an appropriately sized np.ndarray"""
73 @abstractmethod
74 def read_remaining(self) -> np.ndarray:
75 """Method to read the rest of the data on the acquisition from the hardware
76 that returns an appropriately sized np.ndarray"""
78 @abstractmethod
79 def stop(self):
80 """Method to stop the acquisition"""
82 @abstractmethod
83 def close(self):
84 """Method to close down the hardware"""
86 @abstractmethod
87 def get_acquisition_delay(self) -> int:
88 """Get the number of samples between output and acquisition
90 This function is designed to handle buffering done in the output
91 hardware, ensuring that all data written to the output is read by the
92 acquisition. If a output hardware has a buffer, there may be a non-
93 negligable delay between when output is written to the device and
94 actually played out from the device."""
97class HardwareOutput(ABC):
98 """Abstract class defining the interface between the controller and output
100 This class defines the interfaces between the controller and the
101 output or source portion of the hardware. It is run by the Output
102 process, and must define how to get write data to the hardware from the
103 control system"""
105 @abstractmethod
106 def set_up_data_output_parameters_and_channels(
107 self, test_data: DataAcquisitionParameters, channel_data: List[Channel]
108 ):
109 """
110 Initialize the hardware and set up sources and sampling properties
112 The function must create channels on the hardware corresponding to
113 the sources in the test. It must also set the sampling rates.
115 Parameters
116 ----------
117 test_data : DataAcquisitionParameters :
118 A container containing the data acquisition parameters for the
119 controller set by the user.
120 channel_data : List[Channel] :
121 A list of ``Channel`` objects defining the channels in the test
123 Returns
124 -------
125 None.
127 """
129 @abstractmethod
130 def start(self):
131 """Method to start outputting data to the hardware"""
133 @abstractmethod
134 def write(self, data):
135 """Method to write a np.ndarray with a frame of data to the hardware"""
137 @abstractmethod
138 def stop(self):
139 """Method to stop the output"""
141 @abstractmethod
142 def close(self):
143 """Method to close down the hardware"""
145 @abstractmethod
146 def ready_for_new_output(self) -> bool:
147 """Method that returns true if the hardware should accept a new signal"""