I am currently building software to receive data from device and plotting on my GUI real-time. This set of data is coming as a list from the device. I have looked up many methods and seems like "timer" is useful. However, when I tried to use it to plot, it does not work and crash. Following is my thread of receiving data from device. freq
and sweep_max
is defined from device API file.
class Worker(QThread):
signal_x = pyqtSignal(object, object)
def __init__(self):
super().__init__()
def run(self):
while True:
self.data_x = freqs
self.data_y = sweep_max
self.signal_x.emit(self.data_x, self.data_y)
time.sleep(0.1)
And following is my Main python file with GUI.
import sys
from PyQt5.QtCore import *
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtWidgets import *
import LLAGUI1
from SignalThread import MyWidget, Worker
from sadevice.sa_api import *
from PyQt5 import QtCore, QtWidgets
import pyqtgraph as pg
class MainClass(QDialog,LLAGUI1.Ui_Dialog):
def __init__(self):
super().__init__()
self.setupUi(self)
############Part of real time plotting but getting error because of plotCurve has no input
self.timer = QtCore.QTimer(self)
self.timer.setInterval(100) # in milliseconds
self.timer.start()
self.timer.timeout.connect(self.plotCurve)
#############################################################################
self.mywid = pg.GraphicsWindow()
self.plotItem = self.mywid.addPlot(title="Linewidth Measurement")
self.plotDataItem = self.plotItem.plot([], symbolSize=1, symbolPen=None)
self.graphWidget.addItem(self.plotDataItem)
self.make_connection()
def make_connection(self):
self.w = Worker()
self.w.start()
self.w.signal_x.connect(self.plotCurve)
def plotCurve(self, x, y):
self.plotDataItem.setData(x,y)
print(x)
print(y)
if __name__=='__main__':
app=QApplication(sys.argv)
lla=MainClass()
lla.show()
app.exec_()
I am getting error with following part of my code because there is no input of plotCurve. Without following 4lines, curve is not real time and it just plot and stop even tho it is keep receiving the data. I tried to put make_connection
there but it also gives me error.
self.timer = QtCore.QTimer(self)
self.timer.setInterval(100) # in milliseconds
self.timer.start()
self.timer.timeout.connect(self.plotCurve)
Please save me from this threading error, I really appreciate any idea! Thank you!