-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConnectionHandler.py
More file actions
53 lines (40 loc) · 1.67 KB
/
ConnectionHandler.py
File metadata and controls
53 lines (40 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Class to handle multiple connections for multiple instruments
"""
import threading
from pslab import ScienceLab
from pslab.instrument.logic_analyzer import LogicAnalyzer
from pslab.instrument.multimeter import Multimeter
from pslab.instrument.oscilloscope import Oscilloscope
from pslab.instrument.power_supply import PowerSupply
from pslab.instrument.waveform_generator import PWMGenerator
from pslab.instrument.waveform_generator import WaveformGenerator
_lock = threading.Lock()
class ConnectionHandler(object):
_instance = None
_device = None
def __init__(self):
raise RuntimeError("ConnectionHandler is a singleton class. Call instance() instead")
def __getScienceLab(self) -> ScienceLab:
with _lock:
self._device = ScienceLab() if self._device is None else self._device
return self._device
@classmethod
def instance(cls):
with _lock:
if cls._instance is None:
cls._instance = cls.__new__(cls)
cls._instance._lock = threading.Lock()
return cls._instance
def getOscilloscope(self) -> Oscilloscope:
return self.__getScienceLab().oscilloscope
def getWaveformGenerator(self) -> WaveformGenerator:
return self.__getScienceLab().waveform_generator
def getPWMGenerator(self) -> PWMGenerator:
return self.__getScienceLab().pwm_generator
def getPowerSupply(self) -> PowerSupply:
return self.__getScienceLab().power_supply
def getLogicAnalyzer(self) -> LogicAnalyzer:
return self.__getScienceLab().logic_analyzer
def getMultimeter(self) -> Multimeter:
return self.__getScienceLab().multimeter