当前位置: 首页 > article >正文

2025版自动控制流程_工业级连接_智能重连监控系统_增强型工业连接协议 ‘s Vision+Robot EPSON

import time
import tkinter as tk  
from tkinter import messagebox  
from PIL import Image, ImageTk  
import socket  
import threading  
from datetime import datetime  
import logging  
import subprocess  # 确保导入 subprocess 库  
import os
import pyautogui
from HslCommunication import MelsecMcNet
Response=0
#定义文件夹路径
folder_path = r'c:\Log'  #C:\v5\Public_Release
 
# 检查文件夹是否存在,如果不存在则创建
if not os.path.exists(folder_path):
    os.makedirs(folder_path)

# 设置日志配置  
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')  

class TextHandler(logging.Handler):  
    def __init__(self, widget):  
        super().__init__()  
        self.widget = widget  

    def emit(self, record):  
        msg = self.format(record)  
        self.widget.insert(tk.END, msg + '\n')  
        self.widget.yview_moveto(1)  

class MyClass(tk.Frame):
    def __init__(self, root, parent):
        super().__init__(parent)  # 关键:初始化父类
        self.root = root
        self.parent = parent

class TCPClientApp:  
    def __init__(self, root, parent=None):  
        self.root = root  
        self.vision_client_socket = None  
        self.robot_client_socket = None  
        self.connected_to_vision = False  
        self.connected_to_robot = False  
        self.vision_ip = "127.0.0.1"  
        self.vision_port = 8888  
        self.robot_ip = "192.168.0.1"    #192.168.0.1
        self.robot_port = 2009           #2004
        self.setup_ui()  
        self.setup_logging()  
        self.app3_process = None  # 用于存储子进程的引用

        self.parent = parent or root  # 自动降级处理
        self.plc = None
        self.last_y79_state = False  # 新增状态缓存
        self.setup_plc()
        self.start_plc_monitoring()

        self.init_plc_connection()
        self.start_plc_monitoring()


    def setup_ui(self):  
        self.root.title("Design by Tim")  
        self.root.geometry("800x600")  

        # Grid weights for resizing behavior  
        self.root.grid_columnconfigure(0, weight=1)  
        self.root.grid_columnconfigure(1, weight=2)  
        self.root.grid_columnconfigure(2, weight=1)  
        self.root.grid_rowconfigure(0, weight=1)  
        self.root.grid_rowconfigure(1, weight=1)  

        # Left Frame  
        left_frame = tk.Frame(self.root)  
        left_frame.grid(row=0, column=0, padx=5, pady=5, sticky="nsew")  
        self.create_left_panel(left_frame)  

        # Middle Frame  
        middle_frame = tk.Frame(self.root)  
        middle_frame.grid(row=0, column=1, padx=5, pady=5, sticky="nsew")  
        self.create_middle_panel(middle_frame)  

        # Right Frame  
        right_frame = tk.Frame(self.root)  
        right_frame.grid(row=0, column=2, padx=5, pady=5, sticky="nsew")  
        self.create_right_panel(right_frame)  

        # Bottom Frame  
        bottom_frame = tk.Frame(self.root, bg='lightgray')  
        bottom_frame.grid(row=1, column=0, columnspan=3, padx=5, pady=5, sticky="nsew")  
        self.create_bottom_panel(bottom_frame)  

    def create_left_panel(self, parent): 
        self.plc = MelsecMcNet("192.168.0.11", 1028)
        conn = self.plc.ConnectServer() 
        if conn.IsSuccess:
            #status_bar = tk.Label(parent, text="PLC Connected...", fg="gray",bg='green')
            status_bar = tk.Label(parent, text="PLC Connected...", fg="green")
            status_bar.pack(side=tk.BOTTOM, fill=tk.X)
            logging.info(f"[{datetime.now().strftime('%H:%M:%S')}],PLC No Command")
        else:
            #status_bar = tk.Label(parent, text="PLC is not connect...", fg="gray",bg='red')
            status_bar = tk.Label(parent, text="PLC is not connect...", fg="gray")
            status_bar.pack(side=tk.BOTTOM, fill=tk.X)
            logging.info(f"[{datetime.now().strftime('%H:%M:%S')}],Recive PLC Start Command")                

        main_label = tk.Label(parent, text="", font=("Helvetica", 14))  
        main_label.pack(pady=(10, 5))  
        main_label = tk.Label(parent, text="Main", font=("Helvetica", 26))  
        main_label.pack(pady=(10, 50))  

        launch_button = tk.Button(parent, text="Launch Vision", command=self.launch_application)  
        launch_button.pack(pady=(10,30))  

        start_button = tk.Button(parent, text="Start",command=self.start_auto_command,
            bg="#32CD32",
            fg="white",
            font=("Segoe UI", 12)) 
        start_button.pack(pady=(0, 30)) 

        vision_control_and_label_frame = tk.Frame(parent)  
        vision_control_and_label_frame.pack(anchor='center', pady=(10, 0), expand=True)  
        self.create_connection_buttons(vision_control_and_label_frame, "Vision", self.connect_to_vision, self.disconnect_from_vision)  

        robot_control_and_label_frame = tk.Frame(parent)  
        robot_control_and_label_frame.pack(anchor='center', pady=(10, 0), expand=True)  
        self.create_connection_buttons(robot_control_and_label_frame, "Robot", self.connect_to_robot, self.disconnect_from_robot)  

    def create_connection_buttons(self, parent, label_text, connect_cmd, disconnect_cmd):  
        connect_button = tk.Button(parent, text=f"Connect {label_text}", command=connect_cmd, width=10, height=2)  
        connect_button.pack(side=tk.LEFT, anchor='center', padx=5)  

        disconnect_button = tk.Button(parent, text=f"Disconnect {label_text}", command=disconnect_cmd, width=10, height=2)  
        disconnect_button.pack(side=tk.LEFT, anchor='center', padx=5)  

        status_indicator = tk.Frame(parent, width=20, height=20, bg='red')  
        setattr(self, f"{label_text.lower()}_status_indicator", status_indicator)  # Store as attribute  
        status_indicator.pack(side=tk.LEFT, anchor='center', padx=(0, 5))  

    def create_middle_panel(self, parent):  


        # Vision Recive  
        vision_frame = tk.Frame(parent, width=100, height=100)  
        vision_frame.pack(side=tk.LEFT, padx=5, pady=5)  

        log_label = tk.Label(vision_frame, text="", font=("Helvetica", 14))  
        log_label.pack(pady=(1,1))  
        log_label = tk.Label(vision_frame, text="Vision", font=("Helvetica", 26))  
        log_label.pack(pady=(10, 50))  
                                                                    # 3F 11 Fab 8
        self.vision_data_text = tk.Text(vision_frame, wrap=tk.WORD, height=8, width=35, font=("Helvetica", 12), fg="purple")  
        self.vision_data_text.pack(padx=10, pady=10)  

        self.vision_char_text = tk.Text(vision_frame, wrap=tk.WORD, height=8, width=35, font=("Helvetica", 12), fg="orange")  
        self.vision_char_text.pack(padx=10, pady=10)  

        # Robot Recive  
       


http://www.kler.cn/a/561565.html

相关文章:

  • 机器学习数学通关指南——微积分基本概念
  • MacOS 终端选型
  • Visual Studio Code 远程开发方法
  • 安宝特方案 | 电力行业的“智能之眼”,AR重新定义高效运维!
  • 数据安全_笔记系列05:数据合规与隐私保护(GDPR、CCPA、中国《数据安全法》)深度解析
  • 【2025.2.25更新】wordpress免费AI插件,文章内容、图片自动生成、视频自动生成、网站AI客服、批量采集文章,内置deepseek联网满血版
  • 34.Java 阻塞队列(阻塞队列架构、阻塞队列分类、阻塞队列核心方法)
  • 算法精讲--动态规划(三):树形DP与状态机模型
  • 常见的keil 编译报警记录。
  • Windows Server 搭建 RADIUS 认证服务器
  • 【Leetcode】动态规划:从经典例题剖析解题精要
  • SQL进阶实战技巧:汽车转向次数分析 | 真实场景案例
  • 计算机网络之路由协议(OSPF路由协议)
  • HTTP/HTTPS 服务端口监测的简易实现
  • 2025年智能电力系统与数据驱动创新国际学术会议(IPSDDI 2025)
  • 从两地三中心到多地多中心,OceanBase如何实现金融级高可用
  • 【Python专栏】Python 开发-pycharm安装
  • 接上一主题,在Qt中,用信号代替函数指针,最终目标都是能直接使用lambda表达式,效果一样。
  • 【LLM】本地部署LLM大语言模型+可视化交互聊天,附常见本地部署硬件要求(以Ollama+OpenWebUI部署DeepSeekR1为例)
  • 【Linux网络编程】 HTTP协议