【发布时间】:2016-06-24 07:17:59
【问题描述】:
我目前正在开发控制系统 GUI,但在跨线程存储和访问数据时遇到了障碍。目前,我正在从仪表读取压力,并更新 UI 中的 LCD 显示屏,效果很好。我遇到的这个问题是当我试图控制我的系统时。我需要在同时更新压力显示的同时实时访问我的控制回路的压力表数据,但如果我尝试同时向压力表发送两个命令(控制反馈和显示),我会收到串行读取错误.因此,我想知道是否有一种好方法可以让函数从仪表中读取数据,存储它,并在必要时将数据发送到压力显示器和控制功能。这是我的简化代码:
类 MainWindow():
#has a bunch of buttons and images that are used
#Define the threading object
self.obj=Reader.worker()
self.thread=QThread()
self.obj.moveToThread(self.thread)
def PresDisplay(self,i):
self.presNumber.display("%s", i)
def on_presReadButton_clicked(self):
self.obj.intReady.connect(self.presDisplay)
self.thread.started.connect(self.obj.collector)
self.thread.start()
这部分代码运行良好。但是,从这里开始,我对自己应该做什么感到有些迷茫。在我的工人阶级中,我有以下内容: #
类工作者(QObject):
intReady=pyqtSignal(str)
pres=pyqtSignal(str)
def collector(self):
while True:
i=gauge.check() #read the pressure from the gauge
self.pres.connect(self.presSender)
self.pres.emit(i)
def presSender(self,i):
self.intReady.emit(i)
def control(self, setpoint, i):
#This method must take in the pressure setpoint from the main GUi thread and use the pressure readings from collector at any given time to conduct the close loop control. It will be initiated from the click of a button (not the pressure read button above)
我知道这是一个非常开放的问题,但可能有很多方法可以解决它。
如果有人有任何想法,我愿意尝试一下。三个星期以来,我一直在努力解决这个问题。
【问题讨论】:
-
你为什么要将工作器上的信号连接到自身,只是为了发出具有相同参数的另一个信号?
标签: python multithreading user-interface pyqt