Skip to content

Commit f29fe0a

Browse files
Removed unnecessary self.mutex.
1 parent d21a3a2 commit f29fe0a

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

WaveGeneratorArduino.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import time
1212
import datetime
1313

14-
from qtpy import QtCore
1514
import numpy as np
1615

1716
from dvg_debug_functions import dprint, print_fancy_traceback as pft
@@ -30,9 +29,12 @@ class State:
3029
"""Container for the process and measurement variables of the wave
3130
generator Arduino."""
3231

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]"""
3638

3739
def __init__(
3840
self,
@@ -49,11 +51,11 @@ def __init__(
4951
# Container for the process and measurement variables
5052
self.state = self.State
5153

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()
5759

5860
def set_waveform_to_sine(self):
5961
"""Send the instruction to the Arduino to change to a sine wave."""
@@ -73,6 +75,9 @@ def perform_DAQ(self) -> bool:
7375
7476
Returns: True if successful, False otherwise.
7577
"""
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+
7681
# Query the Arduino for its state
7782
success, reply = self.query_ascii_values("?", delimiter="\t")
7883
if not success:
@@ -84,8 +89,11 @@ def perform_DAQ(self) -> bool:
8489

8590
# Parse readings into separate state variables
8691
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]
8997
except Exception as err: # pylint: disable=broad-except
9098
pft(err, 3)
9199
dprint(
@@ -115,7 +123,7 @@ class State:
115123
time = np.nan # [s]
116124
reading_1 = np.nan # [arbitrary units]
117125

118-
def __init__(self, *args, **kwargs):
126+
def __init__(self):
119127
self.serial_settings = {}
120128
self.name = "FakeArd"
121129
self.long_name = "FakeArduino"
@@ -124,12 +132,6 @@ def __init__(self, *args, **kwargs):
124132
# Container for the process and measurement variables
125133
self.state = self.State
126134

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-
133135
self.wave_freq = 0.3 # [Hz]
134136
self.wave_type = "sine"
135137

@@ -169,6 +171,6 @@ def close(self):
169171
"""Close the serial connection to the Arduino."""
170172
return
171173

172-
def auto_connect(self, *args, **kwargs):
174+
def auto_connect(self):
173175
"""Auto connect to the Arduino via serial."""
174176
return True

0 commit comments

Comments
 (0)