提交现有代码
This commit is contained in:
+276
@@ -0,0 +1,276 @@
|
||||
from PySide6.QtCore import *
|
||||
from datetime import datetime
|
||||
from config import *
|
||||
class DataCenter(QObject):
|
||||
plcAlive = Signal(bool)
|
||||
dataReady = Signal(dict)
|
||||
send_temperature_data = Signal(str, dict)
|
||||
readFinished = Signal()
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.settings = QSettings("TGZZ", "TGX") # 设置存储位置
|
||||
self.temp_timer = QTimer(self)
|
||||
self.temp_timer.timeout.connect(self.update_temp_timer)
|
||||
|
||||
self.debug_timer = QTimer(self)
|
||||
self.debug_timer.timeout.connect(self.update_debug_timer)
|
||||
if YSMODE:
|
||||
self.debug_timer.start(1000)
|
||||
self.temp_timer.start(1000)
|
||||
self.temp_data = {}
|
||||
self.device_object = {
|
||||
"scanner1":{
|
||||
"acquisition_board":{
|
||||
"temperature": 0 ,
|
||||
"temperature_alarm_line": 0,
|
||||
"communication_status": 0,
|
||||
"failure_status": 1,
|
||||
"failure_info": "采集板故障",
|
||||
"usage_duration": 15,
|
||||
"useful_life": 365
|
||||
},
|
||||
"power":{
|
||||
"voltage_value": 0,
|
||||
"voltage_setting_value": 0,
|
||||
"current_value": 0,
|
||||
"current_setting_value": 0,
|
||||
"filament_current_value": 0,
|
||||
"filament_current_setting_value": 0,
|
||||
"filament_preheating_current_value": 0,
|
||||
"filament_preheating_current_setting_value": 0,
|
||||
"communication_status": 0,
|
||||
"failure_status": 1,
|
||||
"failure_info": "电源故障",
|
||||
"enable_status": 0,
|
||||
"safety_lock": 0,
|
||||
"switch": 0,
|
||||
"temperature": 0,
|
||||
"temperature_alarm_line": 80,
|
||||
"usage_duration": 15,
|
||||
"useful_life": 365
|
||||
},
|
||||
"xray":{
|
||||
"enable_status": 0,
|
||||
"oil_temperature": 0,
|
||||
"oil_temperature_alarm_line": 50,
|
||||
"liquid_level": 0,
|
||||
"usage_duration": 15,
|
||||
"useful_life": 365,
|
||||
"failure_status": 1,
|
||||
"failure_info": "射线故障"
|
||||
},
|
||||
"motor":{
|
||||
"communication_status": 0,
|
||||
"position": 0,
|
||||
"direction": 0,
|
||||
"velocity": 0,
|
||||
"setting_velocity": 0,
|
||||
"usage_duration": 15,
|
||||
"useful_life": 365,
|
||||
"failure_status": 1,
|
||||
"failure_info": "电机故障"
|
||||
}
|
||||
},
|
||||
"scanner2":{
|
||||
"acquisition_board":{
|
||||
"temperature": 0 ,
|
||||
"temperature_alarm_line": 0,
|
||||
"communication_status": 0,
|
||||
"failure_status": 1,
|
||||
"failure_info": "采集板故障",
|
||||
"usage_duration": 15,
|
||||
"useful_life": 365
|
||||
},
|
||||
"power":{
|
||||
"voltage_value": 0,
|
||||
"voltage_setting_value": 0,
|
||||
"current_value": 0,
|
||||
"current_setting_value": 0,
|
||||
"filament_current_value": 0,
|
||||
"filament_current_setting_value": 0,
|
||||
"filament_preheating_current_value": 0,
|
||||
"filament_preheating_current_setting_value": 0,
|
||||
"communication_status": 0,
|
||||
"failure_status": 1,
|
||||
"failure_info": "电源故障",
|
||||
"enable_status": 0,
|
||||
"safety_lock": 0,
|
||||
"switch": 0,
|
||||
"temperature": 0,
|
||||
"temperature_alarm_line": 80,
|
||||
"usage_duration": 15,
|
||||
"useful_life": 365
|
||||
},
|
||||
"xray":{
|
||||
"enable_status": 0,
|
||||
"oil_temperature": 0,
|
||||
"oil_temperature_alarm_line": 50,
|
||||
"liquid_level": 0,
|
||||
"usage_duration": 15,
|
||||
"useful_life": 365,
|
||||
"failure_status": 1,
|
||||
"failure_info": "射线故障"
|
||||
},
|
||||
"motor":{
|
||||
"communication_status": 0,
|
||||
"position": 0,
|
||||
"direction": 0,
|
||||
"velocity": 0,
|
||||
"setting_velocity": 0,
|
||||
"usage_duration": 15,
|
||||
"useful_life": 365,
|
||||
"failure_status": 1,
|
||||
"failure_info": "电机故障"
|
||||
}
|
||||
},
|
||||
"global_dev":{
|
||||
"device":{
|
||||
"cw_flow_rate": 0,
|
||||
"cw_flow_rate_lower_limit": 0,
|
||||
"custom_intvl": 0,
|
||||
"water_temperature": 0,
|
||||
"water_temperature_alarm_line": 50,
|
||||
"light": False,
|
||||
"outlet_air_temperature": 0,
|
||||
"outlet_air_temperature_alarm_line": 50,
|
||||
"control_board_temperature": 0,
|
||||
"control_board_temperature_alarm_line": 30,
|
||||
"failure_info": "通用设备故障1,2",
|
||||
"sports_mode": "fast"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def appendTempData(self, data1, data2, max_count=3600):
|
||||
dateTimeData = self.temp_data.get("datetime", [])
|
||||
scanner1data = self.temp_data.get("SCANNER1", [])
|
||||
scanner2data = self.temp_data.get("SCANNER2", [])
|
||||
|
||||
timestamp = int(datetime.now().timestamp())
|
||||
if len(dateTimeData) >= max_count:
|
||||
dateTimeData.pop(0)
|
||||
dateTimeData.append(timestamp)
|
||||
if len(scanner1data) >= max_count:
|
||||
scanner1data.pop(0)
|
||||
scanner1data.append(data1)
|
||||
|
||||
if len(scanner2data) >= max_count:
|
||||
scanner2data.pop(0)
|
||||
scanner2data.append(data2)
|
||||
self.temp_data["SCANNER1"] = scanner1data
|
||||
self.temp_data["SCANNER2"] = scanner2data
|
||||
self.temp_data["datetime"] = dateTimeData
|
||||
self.temp_data["method"] = "temperature"
|
||||
|
||||
def update_debug_timer(self):
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
def update_temp_timer(self):
|
||||
data1 = self.device_object["scanner1"]["xray"]["oil_temperature"]
|
||||
data2 = self.device_object["scanner2"]["xray"]["oil_temperature"]
|
||||
self.appendTempData(data1, data2)
|
||||
|
||||
@Slot(str, int)
|
||||
def get_temperature(self, cid, duration):
|
||||
self.send_temperature_data.emit(cid, self.temp_data)
|
||||
@Slot(int, dict)
|
||||
def update_voltage_info(self, voltage_index, info):
|
||||
self.device_object[f"scanner{voltage_index}"]["power"] = info
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
@Slot(dict)
|
||||
def update_motor_globaldev_info(self, info):
|
||||
self.device_object[f"global_dev"]["device"]["sports_mode"] = info["sports_mode"]
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
@Slot(dict)
|
||||
def update_globaldev_info(self, info):
|
||||
self.device_object[f"global_dev"] = info
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
@Slot(int, dict)
|
||||
def update_xray_info(self, xray_index, info):
|
||||
self.device_object[f"scanner{xray_index}"]["xray"] = info
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
@Slot(int, dict)
|
||||
def update_acquisition_info(self, acquisition_index, info):
|
||||
self.device_object[f"scanner{acquisition_index}"]["acquisition_board"]["temperature"] = info["temp"]/10
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
@Slot(int, dict)
|
||||
def update_motor_info(self, motor_index, info):
|
||||
self.device_object[f"scanner{motor_index}"]["motor"] = info
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
@Slot(int, int)
|
||||
def update_motor_position(self, motor_index, position):
|
||||
self.device_object[f"scanner{motor_index}"]["motor"]["position"] = position
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
@Slot(int, int)
|
||||
def update_motor_direction(self, motor_index, direction):
|
||||
self.device_object[f"scanner{motor_index}"]["motor"]["direction"] = direction
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
@Slot(int,float)
|
||||
def update_motor_velocity(self, motor_index, velocity):
|
||||
self.device_object[f"scanner{motor_index}"]["motor"]["velocity"] = velocity
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
@Slot(int, dict)
|
||||
def update_alu_info(self, alu_index, info):
|
||||
self.device_object["global_dev"]["device"]["light"] = info["light"]
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
@Slot(int, dict)
|
||||
def update_wsu_info(self, wsu_index, info):
|
||||
self.device_object["global_dev"]["device"]["cw_flow_rate"] = info["flow_rate"]
|
||||
self.device_object["global_dev"]["device"]["water_temperature"] = info["water_temp"]
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
@Slot(int, dict)
|
||||
def update_osu_info(self, osu_index, info):
|
||||
self.device_object[f"scanner{osu_index}"]["xray"]["oil_temperature"] = info["oil_temp"]
|
||||
self.device_object[f"scanner{osu_index}"]["xray"]["liquid_level"] = info["oil_level"]
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
|
||||
@Slot(int, dict)
|
||||
def update_hsv_info(self, hsv_index, info):
|
||||
self.device_object[f"scanner{hsv_index}"]["power"]["voltage_value"] = info["voltage"]
|
||||
self.device_object[f"scanner{hsv_index}"]["power"]["current_value"] = info["current"]
|
||||
self.device_object[f"scanner{hsv_index}"]["power"]["filament_current_value"] = info["current_filament"]
|
||||
self.device_object[f"scanner{hsv_index}"]["power"]["temperature"] = info["internal_temperature"]
|
||||
self.device_object[f"scanner{hsv_index}"]["power"]["enable_status"] = 1 if info["switch_status"] == True else 0
|
||||
|
||||
# self.device_object[f"scanner{hsv_index}"]["xray"]["enable_status"] = 1 if info["xray_status"] == True else 0
|
||||
# self.device_object[f"scanner{hsv_index}"]["power"]["voltage_setting_value"] = info["param"]["kV"]
|
||||
# self.device_object[f"scanner{hsv_index}"]["power"]["current_setting_value"] = info["param"]["mA"]
|
||||
#TODO
|
||||
# self.device_object[f"scanner{hsv_index}"]["power"]["filament_current_setting_value"] = info["param"]["filament_limit"]
|
||||
# self.device_object[f"scanner{hsv_index}"]["power"]["filament_preheating_current_setting_value"] = info["param"]["filament_preheat"]
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
@Slot(int,float)
|
||||
def update_motor_setting_velocity(self, motor_index, setting_velocity):
|
||||
self.device_object[f"scanner{motor_index}"]["motor"]["setting_velocity"] = setting_velocity
|
||||
self.dataReady.emit(self.device_object)
|
||||
|
||||
@Slot(str, int)
|
||||
def write_data(self, dbname, num):
|
||||
self.settings.setValue(dbname, num) # 保存到设置中
|
||||
return True
|
||||
|
||||
def reapply_write_settings(self):
|
||||
""" 从 QSettings 加载之前保存的写入日志 """
|
||||
dbnames = self.settings.allKeys() # 获取所有键
|
||||
for dbname in dbnames:
|
||||
num = self.settings.value(dbname) # 获取对应的值
|
||||
print(f"Reapplying write: {dbname} = {num}")
|
||||
self.write_data(dbname, num)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user