feat:新增上料下料按钮触发
This commit is contained in:
parent
343178c1a3
commit
5b7a0bb439
BIN
db/jtDB.db
BIN
db/jtDB.db
Binary file not shown.
@ -2,20 +2,19 @@ from pymodbus.client import ModbusTcpClient
|
||||
import time
|
||||
client = ModbusTcpClient('localhost', port=5020)
|
||||
client.connect()
|
||||
client.write_registers(address=11, values=[2247])
|
||||
client.write_registers(address=3, values=[0])
|
||||
|
||||
# client.write_registers(address=20, values=[0])
|
||||
# time.sleep(2)
|
||||
# client.write_registers(address=20, values=[1])
|
||||
# client.write_registers(address=11, values=[2247])
|
||||
# client.write_registers(address=3, values=[0])
|
||||
time.sleep(2)
|
||||
client.write_registers(address=0, values=[0])
|
||||
client.write_registers(address=4, values=[0])
|
||||
|
||||
# client.write_registers(address=30, values=[25])
|
||||
# client.write_registers(address=5, values=[16])
|
||||
# 贴标完成
|
||||
# client.write_registers(address=24, values=[1])s
|
||||
client.write_registers(address=13, values=[1])
|
||||
# client.write_registers(address=13, values=[1])
|
||||
|
||||
|
||||
result = client.read_holding_registers(address=11, count=1)
|
||||
result = client.read_holding_registers(address=0, count=1)
|
||||
print(result.registers[0],"123===")
|
||||
client.close()
|
||||
@ -48,12 +48,12 @@ class ModbusMonitor(QObject):
|
||||
register_error = Signal(int, str)
|
||||
monitor_status_changed = Signal(bool, str)
|
||||
|
||||
def __init__(self, polling_interval=2.0, max_errors=3, retry_interval=5.0):
|
||||
def __init__(self, polling_interval=1.0, max_errors=3, retry_interval=5.0):
|
||||
"""
|
||||
初始化Modbus监控器
|
||||
|
||||
Args:
|
||||
polling_interval: 轮询间隔(秒),默认2.0秒,比原来的1.0秒增加了一倍
|
||||
polling_interval: 轮询间隔(秒),默认1.0秒,比原来的1.0秒增加了一倍
|
||||
max_errors: 最大错误次数,超过此次数将暂停特定寄存器的监控
|
||||
retry_interval: 重试间隔(秒)
|
||||
"""
|
||||
@ -77,7 +77,7 @@ class ModbusMonitor(QObject):
|
||||
def _initialize_registers(self):
|
||||
"""初始化要监控的寄存器列表"""
|
||||
# 默认监控的寄存器地址
|
||||
register_addresses = [5, 6, 11, 13, 20, 21, 22, 23, 24, 25, 30]
|
||||
register_addresses = [0, 4, 5, 6, 11, 13, 20, 21, 22, 23, 24, 25, 30]
|
||||
for address in register_addresses:
|
||||
self.registers[address] = RegisterValue(address)
|
||||
|
||||
|
||||
@ -211,6 +211,12 @@ class MainWindow(MainWindowUI):
|
||||
|
||||
# 恢复开始按钮原始样式
|
||||
self.restore_start_button_style()
|
||||
|
||||
# 恢复上料和下料按钮原始样式
|
||||
if hasattr(self, 'restore_input_button_style'):
|
||||
self.restore_input_button_style()
|
||||
if hasattr(self, 'restore_output_button_style'):
|
||||
self.restore_output_button_style()
|
||||
|
||||
def get_axios_num(self,tray_id):
|
||||
"""获取托盘号对应的轴号"""
|
||||
@ -645,8 +651,9 @@ class MainWindow(MainWindowUI):
|
||||
if success3:
|
||||
logging.info(f"停止下料操作:当前层数 {self._current_unload_num}/{self._total_unload_num}")
|
||||
QMessageBox.information(self, "操作提示", "已停止下料操作")
|
||||
# 恢复按钮原始样式
|
||||
# 恢复开始按钮和下料按钮原始样式
|
||||
self.restore_start_button_style()
|
||||
self.restore_output_button_style()
|
||||
else:
|
||||
QMessageBox.warning(self, "错误", "停止下料操作失败")
|
||||
else:
|
||||
@ -657,8 +664,9 @@ class MainWindow(MainWindowUI):
|
||||
self._is_loading_active = False # 标记上料任务已停止
|
||||
logging.info("停止上料操作")
|
||||
QMessageBox.information(self, "操作提示", "已停止上料操作")
|
||||
# 恢复按钮原始样式
|
||||
# 恢复开始按钮和上料按钮原始样式
|
||||
self.restore_start_button_style()
|
||||
self.restore_input_button_style()
|
||||
else:
|
||||
QMessageBox.warning(self, "错误", "停止上料操作失败")
|
||||
|
||||
@ -2127,13 +2135,117 @@ class MainWindow(MainWindowUI):
|
||||
# 在这里可以添加错误处理逻辑
|
||||
pass
|
||||
|
||||
# 上料按钮样式控制方法
|
||||
def restore_input_button_style(self):
|
||||
"""恢复上料按钮的原始样式"""
|
||||
try:
|
||||
button_style = """
|
||||
QPushButton {
|
||||
padding: 8px 16px;
|
||||
font-weight: bold;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #2196f3;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #bbdefb;
|
||||
}
|
||||
"""
|
||||
self.input_button.setStyleSheet(button_style)
|
||||
logging.info("已恢复上料按钮原始样式")
|
||||
except Exception as e:
|
||||
logging.error(f"恢复上料按钮样式失败: {str(e)}")
|
||||
|
||||
def fill_input_button_style(self):
|
||||
"""填充上料按钮样式 - 蓝色背景,白色字体"""
|
||||
try:
|
||||
button_style = """
|
||||
QPushButton {
|
||||
padding: 8px 16px;
|
||||
font-weight: bold;
|
||||
border-radius: 4px;
|
||||
background-color: #2196F3;
|
||||
color: white;
|
||||
border: 1px solid #2196F3;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #1e88e5;
|
||||
color: white;
|
||||
}
|
||||
"""
|
||||
self.input_button.setStyleSheet(button_style)
|
||||
logging.info("已填充上料按钮样式")
|
||||
except Exception as e:
|
||||
logging.error(f"填充上料按钮样式失败: {str(e)}")
|
||||
|
||||
# 下料按钮样式控制方法
|
||||
def restore_output_button_style(self):
|
||||
"""恢复下料按钮的原始样式"""
|
||||
try:
|
||||
button_style = """
|
||||
QPushButton {
|
||||
padding: 8px 16px;
|
||||
font-weight: bold;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #ffc107;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #ffecb3;
|
||||
}
|
||||
"""
|
||||
self.output_button.setStyleSheet(button_style)
|
||||
logging.info("已恢复下料按钮原始样式")
|
||||
except Exception as e:
|
||||
logging.error(f"恢复下料按钮样式失败: {str(e)}")
|
||||
|
||||
def fill_output_button_style(self):
|
||||
"""填充下料按钮样式 - 黄色背景,白色字体"""
|
||||
try:
|
||||
button_style = """
|
||||
QPushButton {
|
||||
padding: 8px 16px;
|
||||
font-weight: bold;
|
||||
border-radius: 4px;
|
||||
background-color: #FFC107;
|
||||
color: white;
|
||||
border: 1px solid #FFC107;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #ffb300;
|
||||
color: white;
|
||||
}
|
||||
"""
|
||||
self.output_button.setStyleSheet(button_style)
|
||||
logging.info("已填充下料按钮样式")
|
||||
except Exception as e:
|
||||
logging.error(f"填充下料按钮样式失败: {str(e)}")
|
||||
|
||||
@Slot(int, int)
|
||||
def handle_register_change(self, address, value):
|
||||
"""处理寄存器变化"""
|
||||
logging.info(f"[处理] 寄存器D{address}变化: {value}")
|
||||
|
||||
# 当D0寄存器有值时,填充上料按钮样式
|
||||
if address == 0 and value > 0:
|
||||
self.fill_input_button_style()
|
||||
logging.info(f"D0寄存器有值({value}),填充上料按钮样式")
|
||||
|
||||
# 当D4寄存器有值时,填充下料按钮样式
|
||||
elif address == 4 and value > 0:
|
||||
self.fill_output_button_style()
|
||||
logging.info(f"D4寄存器有值({value}),填充下料按钮样式")
|
||||
|
||||
# 当D0寄存器为 0 时,恢复上料按钮样式
|
||||
if address == 0 and value == 0:
|
||||
self.restore_input_button_style()
|
||||
logging.info(f"D0寄存器为 0 ,恢复上料按钮样式")
|
||||
|
||||
# 当D4寄存器为 0 时,恢复下料按钮样式
|
||||
elif address == 4 and value == 0:
|
||||
self.restore_output_button_style()
|
||||
logging.info(f"D4寄存器为 0 ,恢复下料按钮样式")
|
||||
|
||||
# 当D11寄存器变为0时,复位D10寄存器为0
|
||||
if address == 11 and value == 0:
|
||||
elif address == 11 and value == 0:
|
||||
try:
|
||||
logging.info("检测到D11寄存器变为0,正在复位D10寄存器")
|
||||
modbus = ModbusUtils()
|
||||
@ -2190,6 +2302,9 @@ class MainWindow(MainWindowUI):
|
||||
else:
|
||||
# 上料任务完成,清除状态显示
|
||||
self.clear_operation_status("input")
|
||||
# 上料任务完成,恢复上料按钮样式
|
||||
self.restore_input_button_style()
|
||||
logging.info("上料任务完成,恢复上料按钮样式")
|
||||
|
||||
QMessageBox.information(self, "上料操作", desc)
|
||||
except Exception as e:
|
||||
@ -2275,6 +2390,9 @@ class MainWindow(MainWindowUI):
|
||||
self.clear_operation_status("output")
|
||||
self.unloading_level_label.setText("下料层数:--")
|
||||
self.unloading_position_label.setText("下料位置:--")
|
||||
# 下料任务完成,恢复下料按钮样式
|
||||
self.restore_output_button_style()
|
||||
logging.info("下料任务完成,恢复下料按钮样式")
|
||||
elif "请启动" in desc:
|
||||
QMessageBox.information(self, "下料层完成", desc)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user