MainCode/adalm1000_logger.py aktualisiert
Thread Safety Violations:
Qt objects (like QWidgets) must only be accessed from the main thread (GUI thread)
Your measurement thread is directly interacting with GUI elements
Painter Conflicts:
Multiple threads trying to paint to the same canvas simultaneously
Recursive repaint calls
Segmentation Fault:
Likely caused by improper thread cleanup or accessing deleted objects
This commit is contained in:
parent
f75d1dbcf7
commit
df69d0e832
@ -13,13 +13,13 @@ from collections import deque
|
|||||||
|
|
||||||
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel,
|
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel,
|
||||||
QPushButton, QLineEdit, QCheckBox, QFrame, QMessageBox, QFileDialog)
|
QPushButton, QLineEdit, QCheckBox, QFrame, QMessageBox, QFileDialog)
|
||||||
from PyQt5.QtCore import Qt, QTimer, pyqtSignal, pyqtSlot, QObject
|
from PyQt5.QtCore import Qt, QTimer, pyqtSignal, pyqtSlot, QObject, QThread
|
||||||
import pysmu
|
import pysmu
|
||||||
|
|
||||||
class DeviceDisconnectedError(Exception):
|
class DeviceDisconnectedError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class MeasurementThread(QObject):
|
class MeasurementThread(QThread):
|
||||||
update_signal = pyqtSignal(float, float, float)
|
update_signal = pyqtSignal(float, float, float)
|
||||||
error_signal = pyqtSignal(str)
|
error_signal = pyqtSignal(str)
|
||||||
|
|
||||||
@ -67,6 +67,7 @@ class MeasurementThread(QObject):
|
|||||||
|
|
||||||
class BatteryTester(QMainWindow):
|
class BatteryTester(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.plot_mutex = threading.Lock()
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
# Color scheme
|
# Color scheme
|
||||||
@ -392,7 +393,7 @@ class BatteryTester(QMainWindow):
|
|||||||
del self.session
|
del self.session
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
self.session = pysmu.Session(ignore_dataflow=True, queue_size=10000)
|
self.session = pysmu.Session(ignore_dataflow=True, queue_size=10000)
|
||||||
@ -418,8 +419,8 @@ class BatteryTester(QMainWindow):
|
|||||||
self.measurement_thread.update_signal.connect(self.update_measurements)
|
self.measurement_thread.update_signal.connect(self.update_measurements)
|
||||||
self.measurement_thread.error_signal.connect(self.handle_device_error)
|
self.measurement_thread.error_signal.connect(self.handle_device_error)
|
||||||
|
|
||||||
self.thread = threading.Thread(target=self.measurement_thread.run, daemon=True)
|
# Start the QThread directly (no need for threading.Thread)
|
||||||
self.thread.start()
|
self.measurement_thread.start()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.handle_device_error(str(e))
|
self.handle_device_error(str(e))
|
||||||
@ -842,10 +843,11 @@ class BatteryTester(QMainWindow):
|
|||||||
if not self.time_data:
|
if not self.time_data:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.line_voltage.set_data(self.time_data, self.voltage_data)
|
with self.plot_mutex:
|
||||||
self.line_current.set_data(self.time_data, self.current_data)
|
self.line_voltage.set_data(self.time_data, self.voltage_data)
|
||||||
self.auto_scale_axes()
|
self.line_current.set_data(self.time_data, self.current_data)
|
||||||
self.canvas.draw_idle()
|
self.auto_scale_axes()
|
||||||
|
self.canvas.draw_idle()
|
||||||
|
|
||||||
def auto_scale_axes(self):
|
def auto_scale_axes(self):
|
||||||
"""Auto-scale plot axes with appropriate padding and strict boundaries"""
|
"""Auto-scale plot axes with appropriate padding and strict boundaries"""
|
||||||
@ -968,6 +970,8 @@ class BatteryTester(QMainWindow):
|
|||||||
|
|
||||||
if hasattr(self, 'measurement_thread'):
|
if hasattr(self, 'measurement_thread'):
|
||||||
self.measurement_thread.stop()
|
self.measurement_thread.stop()
|
||||||
|
self.measurement_thread.quit()
|
||||||
|
self.measurement_thread.wait(1000) # Wait up to 1 second
|
||||||
|
|
||||||
if hasattr(self, 'session') and self.session:
|
if hasattr(self, 'session') and self.session:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user