You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.5 KiB
Python

7 months ago
import time
from PyQt5.QtCore import QThread, pyqtSignal
from protocol.TCP.RTDTC import RTDTCClient
from protocol.TCP.Analog import AnalogClient
from protocol.Hart.HartSimulate import HartSimulate
from utils import Globals
class FFThread(QThread):
getExpandedSignal = pyqtSignal()
refreshViewSignal = pyqtSignal()
def __init__(self, FFCom, window):#向线程中传递参数以便在run方法中使用
super(FFThread, self).__init__()
self.FFCom = FFCom
self.window = window
self.isPause = False
self.isRun = True
self.finished.connect(self.deleteLater)
def __del__(self):
self.wait()
def start(self):
self.isRun = True
self.isPause = False
super(FFThread, self).start()
def run(self):#重写run方法
while self.isRun:
time.sleep(0.5)
if not self.isPause:
# expandedParams = self.window.getExpandedParams()
self.getExpandedSignal.emit()
self.FFCom.refreshParams(self.window.expandedParams)
self.refreshViewSignal.emit()
def pause(self):
self.isPause = True
def reStart(self):
self.isPause = False
def quitThread(self):
self.isRun = False
self.quit()
self.wait()
class AnalogThread(FFThread):
# getValueList = pyqtSignal()
def __init__(self, window):#向线程中传递参数以便在run方法中使用
super(AnalogThread, self).__init__(None, window)
self.AnalogCom = AnalogClient('192.168.4.218:6541')
def run(self):#重写run方法
while self.isRun:
time.sleep(1)
if not self.isPause:
try:
self.AnalogCom.writeData(self.window.realList)
except Exception as e:
print(e)
class RTDTCThread(FFThread):
# getValueList = pyqtSignal()
def __init__(self, window):#向线程中传递参数以便在run方法中使用
super(RTDTCThread, self).__init__(None, window)
self.RTDTCCom = RTDTCClient('127.0.0.1:6350')
def run(self):#重写run方法
while self.isRun:
time.sleep(1)
if not self.isPause:
try:
self.RTDTCCom.writeData(self.window.mvList)
except Exception as e:
print(e)
class FFSimulateThread(FFThread):
def __init__(self, window):#向线程中传递参数以便在run方法中使用
super(FFSimulateThread, self).__init__(None, window)
self.FFSimulate = FFSimulate()
# print(self.FFSimulate, 111)
def run(self):
while self.isRun:
time.sleep(0.5)
if not self.isPause:
try:
self.window.valueList = self.FFSimulate.readValue()
except Exception as e:
print(e)
class HartSimulateThread(FFThread):
def __init__(self, window):#向线程中传递参数以便在run方法中使用
super(HartSimulateThread, self).__init__(None, window)
self.HartSimulate = HartSimulate()
# print(self.HartSimulate, 111)
def run(self):
while self.isRun:
time.sleep(1)
if not self.isPause:
try:
self.window.valueList = self.HartSimulate.readValue()
except Exception as e:
print(e)