6
6
__author__ = "Dennis van Gils"
7
7
__authoremail__ = "vangils.dennis@gmail.com"
8
8
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo"
9
- __date__ = "24 -07-2020"
10
- __version__ = "5 .0"
9
+ __date__ = "30 -07-2020"
10
+ __version__ = "6 .0"
11
11
# pylint: disable=bare-except, broad-except
12
12
13
13
import os
23
23
import pyqtgraph as pg
24
24
25
25
from dvg_debug_functions import tprint , dprint , print_fancy_traceback as pft
26
+ from dvg_pyqtgraph_threadsafe import HistoryChartCurve
26
27
from dvg_devices .Arduino_protocol_serial import Arduino
27
28
from dvg_qdeviceio import QDeviceIO
28
29
29
30
from DvG_pyqt_FileLogger import FileLogger
30
- from DvG_pyqt_ChartHistory import ChartHistory
31
31
from DvG_pyqt_controls import create_Toggle_button , SS_GROUP
32
32
33
33
try :
@@ -184,7 +184,7 @@ def __init__(self, parent=None, **kwargs):
184
184
# Bottom frame
185
185
# -------------------------
186
186
187
- # Create PlotItem
187
+ # GraphicsWindow
188
188
self .gw_chart = pg .GraphicsWindow ()
189
189
self .gw_chart .setBackground ([20 , 20 , 20 ])
190
190
self .pi_chart = self .gw_chart .addPlot ()
@@ -209,10 +209,12 @@ def __init__(self, parent=None, **kwargs):
209
209
self .pi_chart .getAxis ("left" ).setStyle (tickTextOffset = 20 )
210
210
self .pi_chart .getAxis ("left" ).setWidth (120 )
211
211
212
- # Create ChartHistory and PlotDataItem and link them together
213
- PEN_01 = pg .mkPen (color = [255 , 255 , 90 ], width = 3 )
214
- num_samples = round (CHART_HISTORY_TIME * 1e3 / DAQ_INTERVAL_MS )
215
- self .CH_1 = ChartHistory (num_samples , self .pi_chart .plot (pen = PEN_01 ))
212
+ self .history_chart_curve = HistoryChartCurve (
213
+ capacity = round (CHART_HISTORY_TIME * 1e3 / DAQ_INTERVAL_MS ),
214
+ linked_curve = self .pi_chart .plot (
215
+ pen = pg .mkPen (color = [255 , 255 , 90 ], width = 3 )
216
+ ),
217
+ )
216
218
217
219
# 'Readings'
218
220
p = {"readOnly" : True }
@@ -300,7 +302,7 @@ def process_qpbt_clear_chart(self):
300
302
)
301
303
302
304
if reply == QtWid .QMessageBox .Yes :
303
- self .CH_1 .clear ()
305
+ self .history_chart_curve .clear ()
304
306
305
307
@QtCore .pyqtSlot ()
306
308
def process_qpbt_record (self ):
@@ -309,6 +311,10 @@ def process_qpbt_record(self):
309
311
else :
310
312
file_logger .stopping = True
311
313
314
+ @QtCore .pyqtSlot (str )
315
+ def set_text_qpbt_record (self , text_str ):
316
+ self .qpbt_record .setText (text_str )
317
+
312
318
@QtCore .pyqtSlot ()
313
319
def process_qpbt_wave_sine (self ):
314
320
qdev_ard .send (ard .write , "sine" )
@@ -321,37 +327,25 @@ def process_qpbt_wave_square(self):
321
327
def process_qpbt_wave_sawtooth (self ):
322
328
qdev_ard .send (ard .write , "sawtooth" )
323
329
324
- @QtCore .pyqtSlot (str )
325
- def set_text_qpbt_record (self , text_str ):
326
- self .qpbt_record .setText (text_str )
327
-
328
-
329
- # ------------------------------------------------------------------------------
330
- # update_GUI
331
- # ------------------------------------------------------------------------------
332
-
333
-
334
- @QtCore .pyqtSlot ()
335
- def update_GUI ():
336
- str_cur_date , str_cur_time , _ = get_current_date_time ()
337
- window .qlbl_cur_date_time .setText ("%s %s" % (str_cur_date , str_cur_time ))
338
- window .qlbl_update_counter .setText ("%i" % qdev_ard .update_counter_DAQ )
339
- window .qlbl_DAQ_rate .setText ("DAQ: %.1f Hz" % qdev_ard .obtained_DAQ_rate_Hz )
340
- window .qlin_reading_t .setText ("%.3f" % state .time )
341
- window .qlin_reading_1 .setText ("%.4f" % state .reading_1 )
342
-
343
-
344
- # ------------------------------------------------------------------------------
345
- # update_chart
346
- # ------------------------------------------------------------------------------
347
-
330
+ @QtCore .pyqtSlot ()
331
+ def update_GUI (self ):
332
+ str_cur_date , str_cur_time , _ = get_current_date_time ()
333
+ self .qlbl_cur_date_time .setText (
334
+ "%s %s" % (str_cur_date , str_cur_time )
335
+ )
336
+ self .qlbl_update_counter .setText ("%i" % qdev_ard .update_counter_DAQ )
337
+ self .qlbl_DAQ_rate .setText (
338
+ "DAQ: %.1f Hz" % qdev_ard .obtained_DAQ_rate_Hz
339
+ )
340
+ self .qlin_reading_t .setText ("%.3f" % state .time )
341
+ self .qlin_reading_1 .setText ("%.4f" % state .reading_1 )
348
342
349
- @QtCore .pyqtSlot ()
350
- def update_chart ():
351
- if DEBUG :
352
- tprint ("update_curve" )
343
+ @QtCore .pyqtSlot ()
344
+ def update_chart (self ):
345
+ if DEBUG :
346
+ tprint ("update_curve" )
353
347
354
- window . CH_1 . update_curve ()
348
+ self . history_chart_curve . update ()
355
349
356
350
357
351
# ------------------------------------------------------------------------------
@@ -430,8 +424,8 @@ def DAQ_function():
430
424
if use_PC_time :
431
425
state .time = time .perf_counter ()
432
426
433
- # Add readings to chart histories
434
- window .CH_1 . add_new_reading (state .time , state .reading_1 )
427
+ # Add readings to chart history
428
+ window .history_chart_curve . append_data (state .time , state .reading_1 )
435
429
436
430
# Logging to file
437
431
if file_logger .starting :
@@ -515,14 +509,14 @@ def DAQ_function():
515
509
qdev_ard .create_worker_DAQ (
516
510
DAQ_function = DAQ_function ,
517
511
DAQ_interval_ms = DAQ_INTERVAL_MS ,
518
- critical_not_alive_count = 3 ,
512
+ critical_not_alive_count = 1 ,
519
513
debug = DEBUG ,
520
514
)
521
515
# fmt: on
522
516
qdev_ard .create_worker_jobs (debug = DEBUG )
523
517
524
518
# Connect signals to slots
525
- qdev_ard .signal_DAQ_updated .connect (update_GUI )
519
+ qdev_ard .signal_DAQ_updated .connect (window . update_GUI )
526
520
qdev_ard .signal_connection_lost .connect (notify_connection_lost )
527
521
528
522
# Start workers
@@ -534,7 +528,7 @@ def DAQ_function():
534
528
535
529
timer_chart = QtCore .QTimer ()
536
530
# timer_chart.setTimerType(QtCore.Qt.PreciseTimer)
537
- timer_chart .timeout .connect (update_chart )
531
+ timer_chart .timeout .connect (window . update_chart )
538
532
timer_chart .start (CHART_INTERVAL_MS )
539
533
540
534
# --------------------------------------------------------------------------
0 commit comments