11
11
import time
12
12
import datetime
13
13
14
- from qtpy import QtCore
15
14
import numpy as np
16
15
17
16
from dvg_debug_functions import dprint , print_fancy_traceback as pft
@@ -30,9 +29,12 @@ class State:
30
29
"""Container for the process and measurement variables of the wave
31
30
generator Arduino."""
32
31
33
- time_0 = np .nan # [s] Start of data acquisition
34
- time = np .nan # [s]
35
- reading_1 = np .nan # [arbitrary units]
32
+ time_0 = np .nan
33
+ """[s] Time at start of data acquisition"""
34
+ time = np .nan
35
+ """[s] Time at reading_1"""
36
+ reading_1 = np .nan
37
+ """[arbitrary units]"""
36
38
37
39
def __init__ (
38
40
self ,
@@ -49,11 +51,11 @@ def __init__(
49
51
# Container for the process and measurement variables
50
52
self .state = self .State
51
53
52
- # Mutex for proper multithreading. If the state variables are not
53
- # atomic or thread-safe, you should lock and unlock this mutex for each
54
- # read and write operation. In this demo we don't need it, but I keep it
55
- # as reminder.
56
- self .mutex = QtCore .QMutex ()
54
+ """Remember, you might need a mutex for proper multithreading. If the
55
+ state variables are not atomic or thread-safe, you should lock and
56
+ unlock this mutex for each read and write operation. In this demo we
57
+ don't need it, hence it's commented out but I keep it as a reminder."""
58
+ # self.mutex = QtCore.QMutex()
57
59
58
60
def set_waveform_to_sine (self ):
59
61
"""Send the instruction to the Arduino to change to a sine wave."""
@@ -73,6 +75,9 @@ def perform_DAQ(self) -> bool:
73
75
74
76
Returns: True if successful, False otherwise.
75
77
"""
78
+ # We will catch any exceptions and report on them, but will deliberately
79
+ # not reraise them. Design choice: The show must go on regardless.
80
+
76
81
# Query the Arduino for its state
77
82
success , reply = self .query_ascii_values ("?" , delimiter = "\t " )
78
83
if not success :
@@ -84,8 +89,11 @@ def perform_DAQ(self) -> bool:
84
89
85
90
# Parse readings into separate state variables
86
91
try :
87
- self .state .time , self .state .reading_1 = reply
88
- self .state .time /= 1000
92
+ ( # pylint: disable=unbalanced-tuple-unpacking
93
+ self .state .time ,
94
+ self .state .reading_1 ,
95
+ ) = reply
96
+ self .state .time /= 1000 # Transform [ms] to [s]
89
97
except Exception as err : # pylint: disable=broad-except
90
98
pft (err , 3 )
91
99
dprint (
@@ -115,7 +123,7 @@ class State:
115
123
time = np .nan # [s]
116
124
reading_1 = np .nan # [arbitrary units]
117
125
118
- def __init__ (self , * args , ** kwargs ):
126
+ def __init__ (self ):
119
127
self .serial_settings = {}
120
128
self .name = "FakeArd"
121
129
self .long_name = "FakeArduino"
@@ -124,12 +132,6 @@ def __init__(self, *args, **kwargs):
124
132
# Container for the process and measurement variables
125
133
self .state = self .State
126
134
127
- # Mutex for proper multithreading. If the state variables are not
128
- # atomic or thread-safe, you should lock and unlock this mutex for each
129
- # read and write operation. In this demo we don't need it, but I keep it
130
- # as reminder.
131
- self .mutex = QtCore .QMutex ()
132
-
133
135
self .wave_freq = 0.3 # [Hz]
134
136
self .wave_type = "sine"
135
137
@@ -169,6 +171,6 @@ def close(self):
169
171
"""Close the serial connection to the Arduino."""
170
172
return
171
173
172
- def auto_connect (self , * args , ** kwargs ):
174
+ def auto_connect (self ):
173
175
"""Auto connect to the Arduino via serial."""
174
176
return True
0 commit comments