66__author__ = "Dennis van Gils"
77__authoremail__ = "[email protected] " 88__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"
1111# pylint: disable=bare-except, broad-except
1212
1313import os
2323import pyqtgraph as pg
2424
2525from dvg_debug_functions import tprint , dprint , print_fancy_traceback as pft
26+ from dvg_pyqtgraph_threadsafe import HistoryChartCurve
2627from dvg_devices .Arduino_protocol_serial import Arduino
2728from dvg_qdeviceio import QDeviceIO
2829
2930from DvG_pyqt_FileLogger import FileLogger
30- from DvG_pyqt_ChartHistory import ChartHistory
3131from DvG_pyqt_controls import create_Toggle_button , SS_GROUP
3232
3333try :
@@ -184,7 +184,7 @@ def __init__(self, parent=None, **kwargs):
184184 # Bottom frame
185185 # -------------------------
186186
187- # Create PlotItem
187+ # GraphicsWindow
188188 self .gw_chart = pg .GraphicsWindow ()
189189 self .gw_chart .setBackground ([20 , 20 , 20 ])
190190 self .pi_chart = self .gw_chart .addPlot ()
@@ -209,10 +209,12 @@ def __init__(self, parent=None, **kwargs):
209209 self .pi_chart .getAxis ("left" ).setStyle (tickTextOffset = 20 )
210210 self .pi_chart .getAxis ("left" ).setWidth (120 )
211211
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+ )
216218
217219 # 'Readings'
218220 p = {"readOnly" : True }
@@ -300,7 +302,7 @@ def process_qpbt_clear_chart(self):
300302 )
301303
302304 if reply == QtWid .QMessageBox .Yes :
303- self .CH_1 .clear ()
305+ self .history_chart_curve .clear ()
304306
305307 @QtCore .pyqtSlot ()
306308 def process_qpbt_record (self ):
@@ -309,6 +311,10 @@ def process_qpbt_record(self):
309311 else :
310312 file_logger .stopping = True
311313
314+ @QtCore .pyqtSlot (str )
315+ def set_text_qpbt_record (self , text_str ):
316+ self .qpbt_record .setText (text_str )
317+
312318 @QtCore .pyqtSlot ()
313319 def process_qpbt_wave_sine (self ):
314320 qdev_ard .send (ard .write , "sine" )
@@ -321,37 +327,25 @@ def process_qpbt_wave_square(self):
321327 def process_qpbt_wave_sawtooth (self ):
322328 qdev_ard .send (ard .write , "sawtooth" )
323329
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 )
348342
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" )
353347
354- window . CH_1 . update_curve ()
348+ self . history_chart_curve . update ()
355349
356350
357351# ------------------------------------------------------------------------------
@@ -430,8 +424,8 @@ def DAQ_function():
430424 if use_PC_time :
431425 state .time = time .perf_counter ()
432426
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 )
435429
436430 # Logging to file
437431 if file_logger .starting :
@@ -515,14 +509,14 @@ def DAQ_function():
515509 qdev_ard .create_worker_DAQ (
516510 DAQ_function = DAQ_function ,
517511 DAQ_interval_ms = DAQ_INTERVAL_MS ,
518- critical_not_alive_count = 3 ,
512+ critical_not_alive_count = 1 ,
519513 debug = DEBUG ,
520514 )
521515 # fmt: on
522516 qdev_ard .create_worker_jobs (debug = DEBUG )
523517
524518 # Connect signals to slots
525- qdev_ard .signal_DAQ_updated .connect (update_GUI )
519+ qdev_ard .signal_DAQ_updated .connect (window . update_GUI )
526520 qdev_ard .signal_connection_lost .connect (notify_connection_lost )
527521
528522 # Start workers
@@ -534,7 +528,7 @@ def DAQ_function():
534528
535529 timer_chart = QtCore .QTimer ()
536530 # timer_chart.setTimerType(QtCore.Qt.PreciseTimer)
537- timer_chart .timeout .connect (update_chart )
531+ timer_chart .timeout .connect (window . update_chart )
538532 timer_chart .start (CHART_INTERVAL_MS )
539533
540534 # --------------------------------------------------------------------------
0 commit comments