-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump dependencies & removed global
date-time
variables
- Loading branch information
1 parent
a414a57
commit d9a4457
Showing
7 changed files
with
110 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
__author__ = "Dennis van Gils" | ||
__authoremail__ = "[email protected]" | ||
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo" | ||
__date__ = "16-07-2020" | ||
__date__ = "17-07-2020" | ||
__version__ = "4.1" | ||
# pylint: disable=bare-except, broad-except | ||
|
||
|
@@ -22,15 +22,16 @@ | |
from PyQt5.QtCore import QDateTime | ||
import pyqtgraph as pg | ||
|
||
from dvg_debug_functions import dprint, print_fancy_traceback as pft | ||
from dvg_devices.Arduino_protocol_serial import Arduino | ||
from dvg_qdeviceio import QDeviceIO | ||
|
||
from DvG_pyqt_FileLogger import FileLogger | ||
from DvG_pyqt_ChartHistory import ChartHistory | ||
from DvG_pyqt_controls import create_Toggle_button, SS_GROUP | ||
from dvg_debug_functions import dprint, print_fancy_traceback as pft | ||
|
||
from dvg_devices.Arduino_protocol_serial import Arduino # I.e. the `device` | ||
from dvg_qdeviceio import QDeviceIO | ||
|
||
try: | ||
# To enable OpenGL GPU acceleration: | ||
# `conda install pyopengl` or `pip install pyopengl` | ||
import OpenGL.GL as gl # pylint: disable=unused-import | ||
except: | ||
|
@@ -45,16 +46,21 @@ | |
DAQ_INTERVAL_MS = 10 # 10 [ms] | ||
CHART_INTERVAL_MS = 10 # 10 [ms] | ||
CHART_HISTORY_TIME = 10 # 10 [s] | ||
|
||
# Global variables for date-time keeping | ||
cur_date_time = QDateTime.currentDateTime() | ||
str_cur_date = cur_date_time.toString("dd-MM-yyyy") | ||
str_cur_time = cur_date_time.toString("HH:mm:ss") | ||
# fmt: on | ||
|
||
# Show debug info in terminal? Warning: Slow! Do not leave on unintentionally. | ||
DEBUG = False | ||
|
||
|
||
def get_current_date_time(): | ||
cur_date_time = QDateTime.currentDateTime() | ||
return ( | ||
cur_date_time.toString("dd-MM-yyyy"), # Date | ||
cur_date_time.toString("HH:mm:ss"), # Time | ||
cur_date_time.toString("yyMMdd_HHmmss"), # Reverse notation date-time | ||
) | ||
|
||
|
||
# ------------------------------------------------------------------------------ | ||
# Arduino state | ||
# ------------------------------------------------------------------------------ | ||
|
@@ -148,11 +154,11 @@ def __init__(self, parent=None, **kwargs): | |
self.gw_chart.setBackground([20, 20, 20]) | ||
self.pi_chart = self.gw_chart.addPlot() | ||
|
||
p = {"color": "#BBB", "font-size": "10pt"} | ||
p = {"color": "#CCC", "font-size": "10pt"} | ||
self.pi_chart.showGrid(x=1, y=1) | ||
self.pi_chart.setTitle("Arduino timeseries", **p) | ||
self.pi_chart.setLabel("bottom", text="history (sec)", **p) | ||
self.pi_chart.setLabel("left", text="readings", **p) | ||
self.pi_chart.setLabel("left", text="amplitude", **p) | ||
self.pi_chart.setRange( | ||
xRange=[-1.04 * CHART_HISTORY_TIME, CHART_HISTORY_TIME * 0.04], | ||
yRange=[-1.1, 1.1], | ||
|
@@ -283,6 +289,7 @@ def set_text_qpbt_record(self, text_str): | |
|
||
@QtCore.pyqtSlot() | ||
def update_GUI(): | ||
str_cur_date, str_cur_time, _ = get_current_date_time() | ||
window.qlbl_cur_date_time.setText("%s %s" % (str_cur_date, str_cur_time)) | ||
window.qlbl_update_counter.setText("%i" % qdev_ard.update_counter_DAQ) | ||
window.qlbl_DAQ_rate.setText("DAQ: %.1f Hz" % qdev_ard.obtained_DAQ_rate_Hz) | ||
|
@@ -328,9 +335,10 @@ def stop_running(): | |
def notify_connection_lost(): | ||
stop_running() | ||
|
||
excl = " ! ! ! ! ! ! ! " | ||
excl = " ! ! ! ! ! ! " | ||
window.qlbl_title.setText("%sLOST CONNECTION%s" % (excl, excl)) | ||
|
||
str_cur_date, str_cur_time, _ = get_current_date_time() | ||
str_msg = ("%s %s\n" "Lost connection to Arduino.\n" " '%s': %salive") % ( | ||
str_cur_date, | ||
str_cur_time, | ||
|
@@ -360,10 +368,7 @@ def about_to_quit(): | |
|
||
def DAQ_function(): | ||
# Date-time keeping | ||
global cur_date_time, str_cur_date, str_cur_time | ||
cur_date_time = QDateTime.currentDateTime() | ||
str_cur_date = cur_date_time.toString("dd-MM-yyyy") | ||
str_cur_time = cur_date_time.toString("HH:mm:ss") | ||
str_cur_date, str_cur_time, str_cur_datetime = get_current_date_time() | ||
|
||
# Query the Arduino for its state | ||
success, tmp_state = ard.query_ascii_values("?", delimiter="\t") | ||
|
@@ -396,7 +401,7 @@ def DAQ_function(): | |
|
||
# Logging to file | ||
if file_logger.starting: | ||
fn_log = cur_date_time.toString("yyMMdd_HHmmss") + ".txt" | ||
fn_log = str_cur_datetime + ".txt" | ||
if file_logger.create_log(state.time, fn_log, mode="w"): | ||
file_logger.signal_set_recording_text.emit( | ||
"Recording to file: " + fn_log | ||
|
@@ -480,9 +485,7 @@ def DAQ_function(): | |
debug = DEBUG, | ||
) | ||
# fmt: on | ||
|
||
qdev_ard.create_worker_jobs(debug=DEBUG) | ||
# """ | ||
|
||
# Connect signals to slots | ||
qdev_ard.signal_DAQ_updated.connect(update_GUI) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,9 @@ | |
__author__ = "Dennis van Gils" | ||
__authoremail__ = "[email protected]" | ||
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo" | ||
__date__ = "16-07-2020" | ||
__version__ = "4.0" | ||
__date__ = "17-07-2020" | ||
__version__ = "4.1" | ||
# pylint: disable=bare-except, broad-except | ||
|
||
import os | ||
import sys | ||
|
@@ -21,29 +22,34 @@ | |
from PyQt5.QtCore import QDateTime | ||
import pyqtgraph as pg | ||
|
||
from DvG_pyqt_FileLogger import FileLogger | ||
from DvG_pyqt_ChartHistory import ChartHistory | ||
from DvG_pyqt_controls import create_Toggle_button | ||
from dvg_debug_functions import dprint, print_fancy_traceback as pft | ||
|
||
from dvg_devices.Arduino_protocol_serial import Arduino | ||
from dvg_qdeviceio import QDeviceIO | ||
|
||
from DvG_pyqt_FileLogger import FileLogger | ||
from DvG_pyqt_ChartHistory import ChartHistory | ||
from DvG_pyqt_controls import create_Toggle_button | ||
|
||
# Constants | ||
# fmt: off | ||
DAQ_INTERVAL_MS = 10 # 10 [ms] | ||
DRAW_INTERVAL_CHART = 10 # 10 [ms] | ||
CHART_HISTORY_TIME = 10 # 10 [s] | ||
|
||
# Global variables for date-time keeping | ||
cur_date_time = QDateTime.currentDateTime() | ||
str_cur_date = cur_date_time.toString("dd-MM-yyyy") | ||
str_cur_time = cur_date_time.toString("HH:mm:ss") | ||
DAQ_INTERVAL_MS = 10 # 10 [ms] | ||
CHART_INTERVAL_MS = 10 # 10 [ms] | ||
CHART_HISTORY_TIME = 10 # 10 [s] | ||
# fmt: on | ||
|
||
# Show debug info in terminal? Warning: Slow! Do not leave on unintentionally. | ||
DEBUG = False | ||
|
||
|
||
def get_current_date_time(): | ||
cur_date_time = QDateTime.currentDateTime() | ||
return ( | ||
cur_date_time.toString("dd-MM-yyyy"), # Date | ||
cur_date_time.toString("HH:mm:ss"), # Time | ||
cur_date_time.toString("yyMMdd_HHmmss"), # Reverse notation date-time | ||
) | ||
|
||
|
||
# ------------------------------------------------------------------------------ | ||
# Arduino state | ||
# ------------------------------------------------------------------------------ | ||
|
@@ -304,6 +310,7 @@ def set_text_qpbt_record(self, text_str): | |
|
||
@QtCore.pyqtSlot() | ||
def update_GUI(): | ||
str_cur_date, str_cur_time, _ = get_current_date_time() | ||
window.qlbl_cur_date_time.setText("%s %s" % (str_cur_date, str_cur_time)) | ||
window.qlbl_update_counter.setText("%i" % qdev_ard.update_counter_DAQ) | ||
window.qlbl_DAQ_rate.setText("DAQ: %.1f Hz" % qdev_ard.obtained_DAQ_rate_Hz) | ||
|
@@ -326,8 +333,7 @@ def update_chart(): | |
if DEBUG: | ||
dprint( | ||
" update_curve done in %.2f ms" | ||
% (time.perf_counter() - tick) | ||
* 1000 | ||
% ((time.perf_counter() - tick) * 1000) | ||
) | ||
|
||
|
||
|
@@ -350,9 +356,10 @@ def stop_running(): | |
def notify_connection_lost(): | ||
stop_running() | ||
|
||
excl = " ! ! ! ! ! ! ! ! " | ||
excl = " ! ! ! ! ! ! " | ||
window.qlbl_title.setText("%sLOST CONNECTION%s" % (excl, excl)) | ||
|
||
str_cur_date, str_cur_time, _ = get_current_date_time() | ||
str_msg = ("%s %s\n" "Lost connection to Arduino.\n" " '%s': %salive") % ( | ||
str_cur_date, | ||
str_cur_time, | ||
|
@@ -382,10 +389,7 @@ def about_to_quit(): | |
|
||
def DAQ_function(): | ||
# Date-time keeping | ||
global cur_date_time, str_cur_date, str_cur_time | ||
cur_date_time = QDateTime.currentDateTime() | ||
str_cur_date = cur_date_time.toString("dd-MM-yyyy") | ||
str_cur_time = cur_date_time.toString("HH:mm:ss") | ||
str_cur_date, str_cur_time, str_cur_datetime = get_current_date_time() | ||
|
||
# Query the Arduino for its state | ||
success, tmp_state = ard.query_ascii_values("?", delimiter="\t") | ||
|
@@ -418,7 +422,7 @@ def DAQ_function(): | |
|
||
# Logging to file | ||
if file_logger.starting: | ||
fn_log = cur_date_time.toString("yyMMdd_HHmmss") + ".txt" | ||
fn_log = str_cur_datetime + ".txt" | ||
if file_logger.create_log(state.time, fn_log, mode="w"): | ||
file_logger.signal_set_recording_text.emit( | ||
"Recording to file: " + fn_log | ||
|
@@ -500,9 +504,8 @@ def DAQ_function(): | |
DAQ_interval_ms = DAQ_INTERVAL_MS, | ||
critical_not_alive_count = 3, | ||
debug = DEBUG, | ||
) | ||
) | ||
# fmt: on | ||
|
||
qdev_ard.create_worker_jobs(debug=DEBUG) | ||
|
||
# Connect signals to slots | ||
|
@@ -518,7 +521,7 @@ def DAQ_function(): | |
|
||
timer_chart = QtCore.QTimer() | ||
timer_chart.timeout.connect(update_chart) | ||
timer_chart.start(DRAW_INTERVAL_CHART) | ||
timer_chart.start(CHART_INTERVAL_MS) | ||
|
||
# -------------------------------------------------------------------------- | ||
# Start the main GUI event loop | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,9 @@ | |
__author__ = "Dennis van Gils" | ||
__authoremail__ = "[email protected]" | ||
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo" | ||
__date__ = "16-07-2020" | ||
__version__ = "4.0" | ||
__date__ = "17-07-2020" | ||
__version__ = "4.1" | ||
# pylint: disable=bare-except, broad-except | ||
|
||
import os | ||
import sys | ||
|
@@ -21,27 +22,32 @@ | |
from PyQt5.QtCore import QDateTime | ||
import pyqtgraph as pg | ||
|
||
from DvG_pyqt_ChartHistory import ChartHistory | ||
from dvg_debug_functions import dprint, print_fancy_traceback as pft | ||
|
||
from dvg_devices.Arduino_protocol_serial import Arduino | ||
from dvg_qdeviceio import QDeviceIO | ||
|
||
from DvG_pyqt_ChartHistory import ChartHistory | ||
|
||
# Constants | ||
# fmt: off | ||
DAQ_INTERVAL_MS = 10 # 10 [ms] | ||
DRAW_INTERVAL_CHART = 10 # 10 [ms] | ||
CHART_HISTORY_TIME = 10 # 10 [s] | ||
|
||
# Global variables for date-time keeping | ||
cur_date_time = QDateTime.currentDateTime() | ||
str_cur_date = cur_date_time.toString("dd-MM-yyyy") | ||
str_cur_time = cur_date_time.toString("HH:mm:ss") | ||
DAQ_INTERVAL_MS = 10 # 10 [ms] | ||
CHART_INTERVAL_MS = 10 # 10 [ms] | ||
CHART_HISTORY_TIME = 10 # 10 [s] | ||
# fmt: on | ||
|
||
# Show debug info in terminal? Warning: Slow! Do not leave on unintentionally. | ||
DEBUG = False | ||
|
||
|
||
def get_current_date_time(): | ||
cur_date_time = QDateTime.currentDateTime() | ||
return ( | ||
cur_date_time.toString("dd-MM-yyyy"), # Date | ||
cur_date_time.toString("HH:mm:ss"), # Time | ||
cur_date_time.toString("yyMMdd_HHmmss"), # Reverse notation date-time | ||
) | ||
|
||
|
||
# ------------------------------------------------------------------------------ | ||
# Arduino state | ||
# ------------------------------------------------------------------------------ | ||
|
@@ -82,11 +88,11 @@ def __init__(self, parent=None, **kwargs): | |
self.gw_chart.setBackground([20, 20, 20]) | ||
self.pi_chart = self.gw_chart.addPlot() | ||
|
||
p = {"color": "#BBB", "font-size": "10pt"} | ||
p = {"color": "#CCC", "font-size": "10pt"} | ||
self.pi_chart.showGrid(x=1, y=1) | ||
self.pi_chart.setTitle("Arduino timeseries", **p) | ||
self.pi_chart.setLabel("bottom", text="history (sec)", **p) | ||
self.pi_chart.setLabel("left", text="readings", **p) | ||
self.pi_chart.setLabel("left", text="amplitude", **p) | ||
self.pi_chart.setRange( | ||
xRange=[-1.04 * CHART_HISTORY_TIME, CHART_HISTORY_TIME * 0.04], | ||
yRange=[-1.1, 1.1], | ||
|
@@ -127,10 +133,7 @@ def about_to_quit(): | |
|
||
def DAQ_function(): | ||
# Date-time keeping | ||
global cur_date_time, str_cur_date, str_cur_time | ||
cur_date_time = QDateTime.currentDateTime() | ||
str_cur_date = cur_date_time.toString("dd-MM-yyyy") | ||
str_cur_time = cur_date_time.toString("HH:mm:ss") | ||
str_cur_date, str_cur_time, str_cur_datetime = get_current_date_time() | ||
|
||
# Query the Arduino for its state | ||
success, tmp_state = ard.query_ascii_values("?", delimiter="\t") | ||
|
@@ -154,7 +157,7 @@ def DAQ_function(): | |
return False | ||
|
||
# Use Arduino time or PC time? | ||
use_PC_time = False | ||
use_PC_time = True | ||
if use_PC_time: | ||
state.time = time.perf_counter() | ||
|
||
|
@@ -230,8 +233,8 @@ def DAQ_function(): | |
# -------------------------------------------------------------------------- | ||
|
||
timer_chart = QtCore.QTimer() | ||
timer_chart.timeout.connect(lambda: window.CH_1.update_curve()) | ||
timer_chart.start(DRAW_INTERVAL_CHART) | ||
timer_chart.timeout.connect(window.CH_1.update_curve) | ||
timer_chart.start(CHART_INTERVAL_MS) | ||
|
||
# -------------------------------------------------------------------------- | ||
# Start the main GUI event loop | ||
|
Oops, something went wrong.