Compare commits

...

3 Commits

3 changed files with 12 additions and 11 deletions

View File

@ -11,10 +11,10 @@ class CircBuffer:
self.__buffer = np.zeros( self.__buffer = np.zeros(
(channels, size), dtype=np.double (channels, size), dtype=np.double
) # or dtype of your choice ) # or dtype of your choice
self.__time = np.zeros(size, dtype=np.double)
self.__index = [0 for i in range(channels)] self.__index = [0 for i in range(channels)]
self.__is_full = [False for i in range(channels)] self.__is_full = [False for i in range(channels)]
self.__totalcount = [0 for i in range(channels)] self.__totalcount = [0 for i in range(channels)]
self.__time = [0.0 for i in range(channels)]
self.__overflows = [0 for i in range(channels)] self.__overflows = [0 for i in range(channels)]
@property @property
@ -42,7 +42,9 @@ class CircBuffer:
self.__buffer[channel, self.write_index(channel)] = item self.__buffer[channel, self.write_index(channel)] = item
self.__index[channel] = (self.write_index(channel) + 1) % self.__size self.__index[channel] = (self.write_index(channel) + 1) % self.__size
self.__totalcount[channel] += 1 self.__totalcount[channel] += 1
self.__time[channel] += 1 / self.__samplereate self.__time[self.write_index(channel=0)] = (
self.__time[self.write_index(channel=0) - 1] + 1 / self.__samplereate
)
if self.__index[channel] == 0: if self.__index[channel] == 0:
self.__is_full[channel] = True self.__is_full[channel] = True
self.__overflows[channel] += 1 self.__overflows[channel] += 1
@ -107,11 +109,11 @@ class CircBuffer:
extend = self.size extend = self.size
return start, extend return start, extend
def get(self, index: int = -1, channel: int = 0): def get(self, index: int = -1, channel: int = 0) -> Tuple[np.double, float]:
# easy case first, we can spare the effort of further checking # easy case first, we can spare the effort of further checking
if index >= 0 and index <= self.write_index(channel): if index >= 0 and index <= self.write_index(channel):
if self.has_value(index, channel): if self.has_value(index, channel):
return self.__buffer[channel, index] return (self.__buffer[channel, index], self.__time[index])
else: else:
raise IndexError( raise IndexError(
f"Invalid index {index} on ring buffer for channel{channel}" f"Invalid index {index} on ring buffer for channel{channel}"
@ -120,7 +122,7 @@ class CircBuffer:
if index < 0: if index < 0:
index = self.write_index() - 1 index = self.write_index() - 1
if self.has_value(index, channel): if self.has_value(index, channel):
return self.__buffer[channel, index] return (self.__buffer[channel, index], self.__time[index])
else: else:
raise IndexError( raise IndexError(
f"Invalid index {index} on ring buffer for channel{channel}" f"Invalid index {index} on ring buffer for channel{channel}"

View File

@ -32,10 +32,8 @@ class SinProducer:
log.debug("producing Sin") log.debug("producing Sin")
start_time = time.time() start_time = time.time()
t = 0 t = 0
while time.time() - start_time < 2: while time.time() - start_time < 20:
s = AMPLITUDE * np.sin(2 * np.pi * FREQUENCY * t) s = AMPLITUDE * np.sin(2 * np.pi * FREQUENCY * t)
self.buffer.append(s) self.buffer.append(s)
t += 1 / self.buffer.samplerate t += 1 / self.buffer.samplerate
time.sleep(1 / self.buffer.samplerate) time.sleep(1 / self.buffer.samplerate)

View File

@ -78,8 +78,9 @@ class PyRelacs(QMainWindow):
widget.setLayout(layout) widget.setLayout(layout)
self.setCentralWidget(widget) self.setCentralWidget(widget)
SAMPLERATE = 10000 SAMPLERATE = 1000
self.buffer = CircBuffer(size=1_000_000, samplerate=SAMPLERATE) BUFFERSIZE = 1_000
self.buffer = CircBuffer(size=BUFFERSIZE, samplerate=SAMPLERATE)
# self.connect_dac() # self.connect_dac()
# self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1]) # self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1])
@ -210,7 +211,7 @@ class PyRelacs(QMainWindow):
sinus_pro.signals.progress.connect(self.progress_fn) sinus_pro.signals.progress.connect(self.progress_fn)
self.threadpool.start(sinus_pro) self.threadpool.start(sinus_pro)
time.sleep(0.05) # time.sleep(0.05)
self.continously_plot.plot_daq() self.continously_plot.plot_daq()
def stop_recording(self): def stop_recording(self):