Data Get
31670 /S
Update 2 AI_PC
3Mins /次
Import "Hggw"
PI Data
AA@BB@0@20240908_115221_31781
AA@BB@0@20240908_115521_31781
AA@BB@0@20240908_115821_31781
1、From PIdata Copy 2 AI PC
2、AI PC UI Chart & Logic OK NG
Pump::
import pygame
import os
import numpy as np
import random
import pyautogui
import datetime
import random
import time
from HslCommunication import MelsecMcNet
import pandas as pd
import json
import copy
import requests
import threading
# 初始化pygame
pygame.init()
# 设置窗口大小和标题
WINDOW_WIDTH = 1920
WINDOW_HEIGHT = 1080
WINDOW_TITLE = "Pump"
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption(WINDOW_TITLE)
# 设置字体(这里暂时未使用到,但保留以备后用)
font = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 30)
font2 = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 23)
font3 = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 600)
font6 = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 50)
font66 = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 90)
# Setting Demo Error
Pump_Error_Bf = pyautogui.prompt('请选择模式,Sample:1,NG Mode',default='0')
Pump_Error=int(Pump_Error_Bf)
# Setting Torndo
Tim_Time_Buffer=pyautogui.prompt('请输入龙卷风报警间隔时间,Sample:600 = 10 Mins ,最大 10 年',default='3')
Tim_Time=int(Tim_Time_Buffer)
print('LJF GAP Second =>',Tim_Time)
#LJF设定
class Tornado():
def __init__(self, url, jobCat, scene, tag, userId, proxies_http,
proxies_https):
super().__init__()
self.url = url
self.proxies_http = proxies_http
self.proxies_https = proxies_https
self._body = {
'userId': userId,
'desc': '',
'scene': scene,
'tag': tag,
'jobCat': jobCat,
'jobStatus': 'N'
}
self.api_lock = threading.Lock()
def send_msg(self, desc):
msg = {'desc': desc}
_body = copy.deepcopy(self._body)
_body.update(msg)
header = {
"Content-Type": 'application/x-www-form-urlencoded; charset=UTF-8'''
}
# For Fab Domain
proxies = {'http': self.proxies_http, 'https': self.proxies_https}
self.api_lock.acquire()
try:
r_post_ft = requests.post(url=self.url,
data=_body,
headers=header,
proxies=proxies)
return r_post_ft
except Exception as ex:
return ex
finally:
self.api_lock.release()
def send_msg(msg, tag=''):
td_cfg = {
"url": "http://10.8.15.222/security/SendMsgByTornado",
"jobCat": "S17_FAB_Alarm",
"scene": "PAC_LIMIT_ALARM",
"tag": "OCA",
"userId": "LAM",
"proxies_http": "10.9.9.5:8080",
"proxies_https": "10.9.9.5:8080"
}
td = Tornado(**td_cfg)
return td.send_msg(msg)
# res = td.send_msg(msg)
# print(res)
text = "结果"
text2 = "曲线说明:绿色表示OOC(Out of Control),红色表示OOS(Out of Spec)"
text3 = "Up Sensor "
text4 = "Down Sensor"
text5 = "叶片异常:"
text6 = "轴承内圈故障:"
text7 = "轴承外圈故障:"
text8 = "不对中:"
text51 = "齿轮磨损:"
text61 = "齿轮断齿:"
text71 = "齿轮偏心:"
text81 = "滚珠损伤:"
text52 = "轴弯曲:"
text62 = "不对中:"
text9 = "OK"
text999 ="NG"
text10 = "健康度(0.8 以上OK,小于0.8 NG)"
text14='The Best View 1920 * 1080 '
text100 = "Pump PHM"
# 主循环
running = True
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# 填充背景
screen.fill((255, 255, 255))
##PLC
nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
##PLC
# 定义文件路径
file_path = r'D:\PumpData.txt'
with open(file_path, 'a', encoding='utf-8') as file:
current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
random_value2 = round(random.uniform(0.216, 0.456), 4)
random_value3 = round(random.uniform(0.326, 0.76), 4)
random_value4 = round(random.uniform(0.216, 0.456), 4)
random_value5 = round(random.uniform(0.326, 0.76), 4)
# 构造要写入文件的行
line = f'{current_time}\t{random_value2}\t{random_value3}\t{random_value4}\t{random_value5}\n'
print(line)
# 写入文件
file.write(line)
file.flush() # 确保数据被写入磁盘
# 每0.01秒生成一行数据
time.sleep(0.0001)
# 读取文件
file_path = r"d:\PumpData.txt"
if not os.path.exists(file_path):
raise FileNotFoundError(f"File {file_path} not found.")
with open(file_path, 'r', encoding='utf-8') as file:
lines = file.readlines()
# 解析数据,只将第二列和第三列转换为浮点数
data = [[line.strip().split('\t')[0], float(line.strip().split('\t')[1]), float(line.strip().split('\t')[2])] for line in lines]
# 提取日期字符串、第二列和第三列数据(注意:这里我们假设每行至少有三列)
x_data = [row[0] for row in data] # 日期字符串列表
y_data1 = [row[1] for row in data] # 第二列数据(曲线1的y轴数据)
y_data2 = [row[2] for row in data] # 第三列数据(曲线2的y轴数据)
# 只保留最新的50笔数据
x_data = x_data[-300:]
y_data1 = y_data1[-300:]
y_data2 = y_data2[-300:]
# 将数据转换为pygame可以使用的格式
# 注意:这里我们假设x轴是时间顺序,因此直接使用索引作为x值
x_points1 = [(i * WINDOW_WIDTH // len(x_data) + 190, int(WINDOW_HEIGHT - y_data1[i] * 200)) for i in range(len(x_data))]
x_points22 = [(i * WINDOW_WIDTH // len(x_data) + 190, int(WINDOW_HEIGHT - 118)) for i in range(len(x_data))]
x_points2 = [(i * WINDOW_WIDTH // len(x_data) + 190, int(WINDOW_HEIGHT - 108)) for i in range(len(x_data))]
x_points3 = [(i * WINDOW_WIDTH // len(x_data) + 190, int(WINDOW_HEIGHT - 30)) for i in range(len(x_data))]
x_points33 = [(i * WINDOW_WIDTH // len(x_data) + 190, int(WINDOW_HEIGHT - 20)) for i in range(len(x_data))]
x_points4 = [(i * WINDOW_WIDTH // len(x_data) + WINDOW_WIDTH //100 +150, int(WINDOW_HEIGHT - y_data2[i] * 480)) for i in range(len(x_data))]
x_points5 = [(i * WINDOW_WIDTH // len(x_data) + WINDOW_WIDTH //100 +150, int(WINDOW_HEIGHT - 388)) for i in range(len(x_data))]
x_points55 = [(i * WINDOW_WIDTH // len(x_data) + WINDOW_WIDTH //100 +150, int(WINDOW_HEIGHT - 378)) for i in range(len(x_data))]
x_points6 = [(i * WINDOW_WIDTH // len(x_data) + WINDOW_WIDTH //100 +150, int(WINDOW_HEIGHT - 140)) for i in range(len(x_data))]
x_points66 = [(i * WINDOW_WIDTH // len(x_data) + WINDOW_WIDTH //100 +150, int(WINDOW_HEIGHT - 130)) for i in range(len(x_data))]
# 绘制曲线的颜色
COLOR1 = (0, 255, 255) # 红色
COLOR2 = (40, 255, 30) # 绿色
BLACK = (0, 0, 0)
Green =(0,255,0)
COLOR3 =(204,204,255) #青色
Yellow =(150, 0, 0) # 黄色
REDD = (190, 0, 0) # 红色
# 绘制曲线1
pygame.draw.lines(screen, COLOR3, False, x_points1, 2)
pygame.draw.lines(screen, Green, False, x_points2, 2)
pygame.draw.lines(screen, Yellow, False, x_points22, 2)
pygame.draw.lines(screen, Green, False, x_points3, 2)
pygame.draw.lines(screen, Yellow, False, x_points33, 2)
# 绘制曲线2
pygame.draw.lines(screen, COLOR1, False, x_points4, 2)
pygame.draw.lines(screen, Yellow, False, x_points5, 2)
pygame.draw.lines(screen, Green, False, x_points55, 2)
pygame.draw.lines(screen, Green, False, x_points6, 2)
pygame.draw.lines(screen, Yellow, False, x_points66, 2)
# 绘制分割线,这里假设分割线在窗口高度的中间位置
pygame.draw.line(screen, BLACK, (0, WINDOW_HEIGHT // 2+100), (WINDOW_WIDTH, WINDOW_HEIGHT // 2+100), 2)
#文本设定
t5 = round(random.uniform(0.8, 1), 3)
t6 = round(random.uniform(0.8, 1), 3)
t7 = round(random.uniform(0.581, 0.787), 3)
t777 = round(random.uniform(0.8, 1), 3)
t8 = round(random.uniform(0.8, 1), 3)
t51 = round(random.uniform(0.8, 1), 3)
t61 = round(random.uniform(0.8, 1), 3)
t71 = round(random.uniform(0.8, 1), 3)
t81 = round(random.uniform(0.8, 1), 3)
t52 = round(random.uniform(0.8, 1), 3)
# 计算文本位置和大小
text_surface = font.render(text, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-890, WINDOW_HEIGHT // 2-500)) # 实时数据显示370
# 绘制文本到窗口
screen.blit(text_surface, text_rect)
# 计算文本位置和大小
text_surface = font6.render(text10, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+560, WINDOW_HEIGHT // 2-385)) # 实时数据显示370
# 绘制文本到窗口
screen.blit(text_surface, text_rect)
# 计算文本位置和大小
text_surface = font66.render(text100, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+10, WINDOW_HEIGHT // 2-485)) # 实时数据显示370
# 绘制文本到窗口
screen.blit(text_surface, text_rect)
# 计算文本位置和大小 2
text_surface = font.render(text2, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-320, WINDOW_HEIGHT // 2+120)) # 实时数据显示370
# 绘制文本到窗口 2
screen.blit(text_surface, text_rect)
# 计算文本位置和大小3
text_surface = font.render(text3, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-870, WINDOW_HEIGHT // 2+270)) # 实时数据显示370
# 绘制文本到窗口 3
screen.blit(text_surface, text_rect)
# 计算文本位置和大小4
text_surface = font.render(text4, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-860, WINDOW_HEIGHT // 2+475)) # 实时数据显示370
# 绘制文本到窗口 4
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
if Pump_Error == 1:
text_surface = font3.render(text999, True, REDD)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2 -600, WINDOW_HEIGHT // 2-180)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
if Pump_Error == 0:
text_surface = font3.render(text9, True, Green)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2 -600, WINDOW_HEIGHT // 2-180)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
############################################################3
# 计算文本位置和大小55
text_surface = font2.render(text5, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+200, WINDOW_HEIGHT // 2-180)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font2.render(str(t5), True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+290, WINDOW_HEIGHT // 2-180)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
############################################################3
# 计算文本位置和大小55
text_surface = font2.render(text6, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+380, WINDOW_HEIGHT // 2-90)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font2.render(str(t6), True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+490, WINDOW_HEIGHT // 2-90)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
############################################################3
if Pump_Error == 1:
# 计算文本位置和大小55
text_surface = font2.render(text7, True, REDD)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+500, WINDOW_HEIGHT // 2-180)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font2.render(str(t7), True, REDD)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+610, WINDOW_HEIGHT // 2-180)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
if Pump_Error == 0:
# 计算文本位置和大小55
text_surface = font2.render(text7, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+500, WINDOW_HEIGHT // 2-180)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font2.render(str(t777), True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+610, WINDOW_HEIGHT // 2-180)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
############################################################3
# 计算文本位置和大小55
text_surface = font2.render(text8, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+700, WINDOW_HEIGHT // 2-90)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font2.render(str(t8), True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+780, WINDOW_HEIGHT // 2-90)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
############################################################3
# 计算文本位置和大小55
text_surface = font2.render(text51, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+200, WINDOW_HEIGHT // 2-1)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font2.render(str(t51), True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+290, WINDOW_HEIGHT // 2-1)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
############################################################3
# 计算文本位置和大小55
text_surface = font2.render(text61, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+470, WINDOW_HEIGHT // 2-1)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font2.render(str(t61), True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+560, WINDOW_HEIGHT // 2-1)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
############################################################3
# 计算文本位置和大小55
text_surface = font2.render(text71, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+355, WINDOW_HEIGHT // 2-270)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font2.render(str(t71), True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+490, WINDOW_HEIGHT // 2-270)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
############################################################3
# 计算文本位置和大小55
text_surface = font2.render(text81, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+698, WINDOW_HEIGHT // 2-270)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font2.render(str(t81), True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+786, WINDOW_HEIGHT // 2-270)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 加载图像
image = pygame.image.load(r"D:\PUMP.png")
# 设置缩放后的图像宽度和高度
scaled_width = 400
scaled_height = 410
# 调整图像大小
scaled_image = pygame.transform.scale(image, (scaled_width, scaled_height))
# 在画布上绘制缩放后的图像
screen.blit(scaled_image, (653, 155))
# 将画布绘制到窗口
screen.blit(screen, (0, 0))
pygame.display.update() #就连设置颜色都需要更新一次
# 更新显示
pygame.display.flip()
clock.tick(60) # 设置帧率为60FPS
#截取图片
current_time2 = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
Trigger = datetime.datetime.now().strftime('%H_%M_%S')
# print(current_time2)
# print(Trigger)
Now1 = datetime.datetime.now().strftime('%H%M%S')
Trigger1 = [(104136), (104139), (104141)]
# print(Now1)
# 检查当前时间是否在设定的时段内
current_data = datetime.datetime.now().strftime('%H:%M:%S.%f')[:-5]
a1="08:00:00.0" #切割区间
a11="08:00:01.5" #切割区间
a2="11:00:10.0" #切割区间
a22="11:00:11.5" #切割区间
a3="14:00:00.0" #切割区间
a33="14:00:01.5" #切割区间
a4="17:00:00.0" #切割区间
a44="17:00:01.5" #切割区间
a5="20:00:00.0" #切割区间
a55="20:00:01.5" #切割区间
a6="23:00:00.0" #切割区间
a66="23:00:01.5" #切割区间
a7="02:00:00.0" #切割区间
a77="02:00:01.5" #切割区间
a8="10:50:00.0" #切割区间
a88="10:50:00.9" #切割区间
print("自动切割文件时间:" + (a1) + "和" + (a2) + "和" + (a3)+ "和" + (a4)+ "和" + (a5)+ "和" + (a6)+ "和" + (a7)+ "和" + (a8))
if current_data > a1 and current_data <= a11 or current_data > a2 and current_data <= a22 or current_data > a3 and current_data <= a33 or current_data > a4 and current_data <= a44 or current_data > a5 and current_data <= a55 or current_data > a6 and current_data <= a66 or current_data > a7 and current_data <= a77 or current_data > a8 and current_data <= a88 :
# 构造文件名
filename = f"{current_time2}.jpg"
aa=r'd:\data3\aa_'
FName =aa+filename
# 截图并保存到文件
pyautogui.screenshot().save(filename)
pyautogui.screenshot().save(FName)
print(f"Screenshot saved as {filename}")
print(f"Screenshot saved as {FName}")
print('LJF GAP Second =>',Tim_Time)
# 每2 S 采集数据
time.sleep(0.0001)
time.sleep(Tim_Time)
#AOI_9 = melsecNet.ReadInt16( "M6030" ).Content
if Pump_Error==0 and __name__ == '__main__':
#messagebox.showinfo('Show information',f'当前值是:{vaule}')
print('从PLC 读取时间为=>' + time.strftime('%Y-%m-%d %H:%M:%S'))
ret = send_msg('''
如下为 9 # Pump PHM 运行状况定期汇报
*****************************************************************************************************************
Inline 9# Pump PHM Running Well
*****************************************************************************************************************
''')
print(ret)
else:
print('从PLC 读取时间为=>' + time.strftime('%Y-%m-%d %H:%M:%S'))
### 格式不对,闪退!ret = send_msg('Inline 9# 生产Model为=>',Model,'Inline 9# AOI 当前状态为=>',AOI_9,' AOI 当前状态说明:1为=>开启 0为=>关闭')
#ret = send_msg(Model)
#ret = send_msg('''Inline 9# AOI 当前状态为=>''')
#ret = send_msg(AOI_9)
#ret = send_msg(''' AOI 当前状态说明:1为=>开启 0为=>关闭''')
ret = send_msg('''
如下为 9 # PHM 运行状况定期汇报
*****************************************************************************************************************
Inline 9# Pump PHM 侦测到异常,请现场确认。
*****************************************************************************************************************
''')
print(ret)
# 退出pygame
pygame.quit()
'''
#################################################3
# 构造文件名
filename = f"{current_time2}.jpg"
aa=r'd:\data3\PIC2\aa_'
FName =aa+filename
# 截图并保存到文件
#pyautogui.screenshot().save(filename)
pyautogui.screenshot().save(FName)
#print(f"Screenshot saved as {filename}")
print(f"Screenshot saved as {FName}")
##################################################
'''
Robot:
import pygame
import os
import numpy as np
import pyautogui
import datetime
import random
import time
import datetime
import sys
from HslCommunication import MelsecMcNet
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import colors
import pyautogui
import csv
from pygame.locals import *
from math import pi
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWidgets import QApplication
import matplotlib
matplotlib.use('Qt5Agg')
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
import time
import datetime as d
from sklearn import linear_model
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
import numpy as np
from pandas import DataFrame,Series
from sklearn.model_selection import train_test_split
from numpy import *
import csv
from statistics import median
from math import isnan
from itertools import filterfalse
import matplotlib.pyplot as plt
from guietta import _, Gui, Quit
from sklearn import linear_model
from sklearn.metrics import mean_squared_error,r2_score
import sklearn
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error
from sklearn.metrics import mean_absolute_percentage_error
from sklearn.metrics import median_absolute_error
from sklearn.metrics import mean_squared_log_error
import statsmodels.api as sm
import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.ensemble import IsolationForest
from sklearn.neighbors import LocalOutlierFactor
from sklearn.svm import OneClassSVM
from sklearn.preprocessing import StandardScaler
# PLC参数设定
PLC_IP = '192.168.1.30' # 设定PLC IP地址 Line9 AOI
PLC_port = 8002 # 设定PLC 端口地址 Line9 AOI
# 存储文件路径&名称设定
filePath = r'D:\Data3\D'
fileName = 'ata.csv'
fullName=filePath + fileName
# 存储文件路径&名称设定2
filePath3 = r'D:\Data3\D'
fileName3 = 'ata_Add_SN.csv'
fullName3=filePath3 + fileName3
# 读取数据模块
# ————————————————————————————————程序主体——————————————————————————————
# 建立空表表头
if not os.path.exists(filePath+fileName):
data = pd.DataFrame({'Datetime':[],'Axis_1_Tor':[],'Axis_1_Peak':[],'Axis_2_Tor':[],'Axis_2_Peak':[],'Axis_3_Tor':[],'Axis_3_Peak':[],'Axis_4_Tor':[],'Axis_4_Peak':[]})
data3 = pd.DataFrame({'Datetime':[],'Axis_1_Tor':[],'Axis_1_Peak':[],'Axis_2_Tor':[],'Axis_2_Peak':[],'Axis_3_Tor':[],'Axis_3_Peak':[],'Axis_4_Tor':[],'Axis_4_Peak':[],'Recipe':[],'Step':[]})
data.to_csv(fullName,index=False,mode='a',header=True)
data3.to_csv(fullName3,index=False,mode='a',header=True)
print("Creat form sucessful")
else:
print("The file " + fullName + " is created")
print("The file " + fullName3 + " is created")
# 初始化pygame
pygame.init()
Ques = pyautogui.prompt('Screenshot,1 ON,0 Off, 请输入数值 0 Or 1',default='0')
filepath6=r'D:\data3.txt'
# 设置窗口大小和标题
WINDOW_WIDTH = 1920
WINDOW_HEIGHT = 1080
WINDOW_TITLE = "Robot"
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption(WINDOW_TITLE)
# 设置字体(这里暂时未使用到,但保留以备后用)
font = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 30)
font2 = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 18)
font3 = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 360)
font66 = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 90)
font22 = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 36)
font222 = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 28)
# 文本内容
text = "结果"
text2 = "曲线说明:绿色表示OOC(Out of Control),红色表示OOS(Out of Spec)"
text3 = "轴 1 "
text4 = "轴 2"
text5 = "轴 3"
text6 = "轴 4"
text7 = "OK" #Swap 8 & 7 同Test
text8="NG" #Swap 8 & 7 同Test
text10="Remark"
text11='实时数据显示AI对采集数据处理后结果'
text12='By Axis 1 2 3 4 AI运算结果均OK'
text13='则结果显示OK'
text14='The Best View 1920 * 1080 '
text100 = "Robot PHM"
text600 = "轴 1"
text601 = " "
text700 = "轴 2"
text701 = " "
text800 = "轴 3"
text801 = " "
text900 = "轴 4"
text901 = " "
aaa=0
# 主循环
running = True
clock = pygame.time.Clock()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
#判断时间是否到达,开始切割文件
current_data = datetime.datetime.now().strftime('%H:%M:%S.%f')[:-5]
#nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
print("当前时间:"+(current_data))
a1="08:00:00.0" #切割区间
a11="08:00:01.5" #切割区间
a2="11:00:10.0" #切割区间
a22="11:00:11.5" #切割区间
a3="14:00:00.0" #切割区间
a33="14:00:01.5" #切割区间
a4="17:00:00.0" #切割区间
a44="17:00:01.5" #切割区间
a5="20:00:00.0" #切割区间
a55="20:00:01.5" #切割区间
a6="23:00:00.0" #切割区间
a66="23:00:01.5" #切割区间
a7="02:00:00.0" #切割区间
a77="02:00:01.5" #切割区间
a8="05:00:00.0" #切割区间
a88="05:00:01.5" #切割区间
print("自动切割文件时间:" + (a1) + "和" + (a2) + "和" + (a3)+ "和" + (a4)+ "和" + (a5)+ "和" + (a6)+ "和" + (a7)+ "和" + (a8))
if current_data > a1 and current_data <= a11 or current_data > a2 and current_data <= a22 or current_data > a3 and current_data <= a33 or current_data > a4 and current_data <= a44 or current_data > a5 and current_data <= a55 or current_data > a6 and current_data <= a66 or current_data > a7 and current_data <= a77 or current_data > a8 and current_data <= a88 :
##################截图
# 构造文件名
filename = f"{current_time2}.jpg"
aa=r'd:\data3\aa_'
FName =aa+filename
# 截图并保存到文件
#pyautogui.screenshot().save(filename)
pyautogui.screenshot().save(FName)
print(f"Screenshot saved as {filename}")
print(f"Screenshot saved as {FName}")
##################截图
filename = r"D:\Data3\Data.csv"#需要进行分割的文件,请修改文件名
filename3 = r"D:\Data3\Data_Add_SN.csv"#需要进行分割的文件,请修改文件名
size = 28000000 #分割大小约1M,2M=2000000
current_time = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
def mk_SubFile(srcName,sub,buf):
[des_filename, extname] = os.path.splitext(srcName)
filename = des_filename + '_' + str(sub) + '_' + current_time + extname
filename3 = des_filename + '_' + str(sub) + '_' + current_time + extname
print( '正在生成子文件: %s' %filename + '以及%s' %filename3)
with open(filename,'wb') as fout:
fout.write(buf)
return sub+1
with open(filename3,'wb') as fout:
fout.write(buf)
return sub+1
def split_By_size(filename,size):
with open(filename,'rb') as fin:
buf = fin.read(size)
sub = 1
while len(buf)>0:
sub = mk_SubFile(filename,sub,buf)
buf = fin.read(size)
with open(filename3,'rb') as fin:
buf = fin.read(size)
sub = 1
while len(buf)>0:
sub = mk_SubFile(filename3,sub,buf)
buf = fin.read(size)
print("ok")
if __name__=="__main__":
split_By_size(filename, size)
split_By_size(filename3, size)
else:
# 填充背景
screen.fill((255, 255, 255))
# 定义文件路径
file_path = r'D:\data3.txt'
with open(file_path, 'a', encoding='utf-8') as file:
current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
random_value2 = round(random.uniform(0.216, 0.456), 4)
random_value3 = round(random.uniform(0.326, 0.76), 4)
random_value4 = round(random.uniform(0.216, 0.456), 4)
random_value5 = round(random.uniform(0.326, 0.76), 4)
# 构造要写入文件的行
line = f'{current_time}\t{random_value2}\t{random_value3}\t{random_value4}\t{random_value5}\n'
print(line)
# 写入文件
file.write(line)
file.flush() # 确保数据被写入磁盘
# 每0.001秒生成一行数据
time.sleep(0.0001)
# 读取文件
file_path2 = r'D:\data3.txt'
if not os.path.exists(file_path2):
raise FileNotFoundError(f"File {file_path2} not found.")
with open(file_path2, 'r', encoding='utf-8') as file:
lines = file.readlines()
# 解析数据,第1234列转换为浮点数
data = [[line.strip().split('\t')[0], float(line.strip().split('\t')[1]), float(line.strip().split('\t')[2]), float(line.strip().split('\t')[3]),float(line.strip().split('\t')[4])] for line in lines]
# 提取日期字符串、第二列和第三列数据(注意:这里我们假设每行至少有三列)
x_data = [row[0] for row in data] # 日期字符串列表
y_data1 = [row[1] for row in data] # 第二列数据(曲线1的y轴数据)
y_data2 = [row[2] for row in data] # 第三列数据(曲线2的y轴数据)
y_data3 = [row[3] for row in data] # 第si列数据(曲线1的y轴数据)
y_data4 = [row[4] for row in data] # 第wu列数据(曲线2的y轴数据)
# 只保留最新的50笔数据
x_data = x_data[-300:]
y_data1 = y_data1[-300:]
y_data2 = y_data2[-300:]
y_data3 = y_data3[-300:]
y_data4 = y_data4[-300:]
# 将数据转换为pygame可以使用的格式;注意:这里我们假设x轴是时间顺序,因此直接使用索引作为x值
# 4
x_points1 = [(i * WINDOW_WIDTH // len(x_data) +120 , int(WINDOW_HEIGHT - y_data1[i] * 180-5)) for i in range(len(x_data))]
x_points11 = [(i * WINDOW_WIDTH // len(x_data) +120 , int(WINDOW_HEIGHT - 115)) for i in range(len(x_data))]
x_points111 = [(i * WINDOW_WIDTH // len(x_data) +120 , int(WINDOW_HEIGHT - 120)) for i in range(len(x_data))]
x_points1111 = [(i * WINDOW_WIDTH // len(x_data) +120 , int(WINDOW_HEIGHT - 20)) for i in range(len(x_data))]
x_points11111 = [(i * WINDOW_WIDTH // len(x_data) +120 , int(WINDOW_HEIGHT - 25)) for i in range(len(x_data))]
# 3
x_points2 = [(i * WINDOW_WIDTH // len(x_data) +120 , int(WINDOW_HEIGHT - y_data2[i] * 300-45)) for i in range(len(x_data))]
x_points22 = [(i * WINDOW_WIDTH // len(x_data) +120 , int(WINDOW_HEIGHT - 290)) for i in range(len(x_data))]
x_points222 = [(i * WINDOW_WIDTH // len(x_data) +120 , int(WINDOW_HEIGHT - 295)) for i in range(len(x_data))]
x_points2222 = [(i * WINDOW_WIDTH // len(x_data) +120 , int(WINDOW_HEIGHT - 125)) for i in range(len(x_data))]
x_points22222 = [(i * WINDOW_WIDTH // len(x_data) +120 , int(WINDOW_HEIGHT - 130)) for i in range(len(x_data))]
# 2
x_points3 = [(i * WINDOW_WIDTH // len(x_data)+120, int(WINDOW_HEIGHT - y_data3[i] * 300-248-12)) for i in range(len(x_data))]
x_points33 = [(i * WINDOW_WIDTH // len(x_data)+120, int(WINDOW_HEIGHT - 413)) for i in range(len(x_data))]
x_points333 = [(i * WINDOW_WIDTH // len(x_data)+120, int(WINDOW_HEIGHT - 418)) for i in range(len(x_data))]
x_points3333 = [(i * WINDOW_WIDTH // len(x_data)+120, int(WINDOW_HEIGHT - 305)) for i in range(len(x_data))]
x_points33333 = [(i * WINDOW_WIDTH // len(x_data)+120, int(WINDOW_HEIGHT - 310)) for i in range(len(x_data))]
# 1
x_points4 = [(i * WINDOW_WIDTH // len(x_data)+120, int(WINDOW_HEIGHT - y_data4[i] * 300-345)) for i in range(len(x_data))]
x_points44 = [(i * WINDOW_WIDTH // len(x_data)+120, int(WINDOW_HEIGHT - 588)) for i in range(len(x_data))]
x_points444 = [(i * WINDOW_WIDTH // len(x_data)+120, int(WINDOW_HEIGHT - 593)) for i in range(len(x_data))]
x_points4444 = [(i * WINDOW_WIDTH // len(x_data)+120, int(WINDOW_HEIGHT - 425)) for i in range(len(x_data))]
x_points44444 = [(i * WINDOW_WIDTH // len(x_data)+120, int(WINDOW_HEIGHT - 430)) for i in range(len(x_data))]
# 绘制曲线的颜色
COLOR1 = (0, 255, 255) # 红色
COLOR2 = (128, 255, 30) # 绿色
BLACK = (0, 0, 0)
Green =(0,255,0)
COLOR3 = (0, 128, 255) # 红色
COLOR =(2604,204,255) #青色
Yellow =(150, 0, 0) # 黄色
REDD = (190, 0, 0) # 红色
# 绘制曲线1
pygame.draw.lines(screen, COLOR1, False, x_points1, 2)
pygame.draw.lines(screen, Green, False, x_points11, 2)
pygame.draw.lines(screen, Yellow, False, x_points111, 2)
pygame.draw.lines(screen, Yellow, False, x_points1111, 2)
pygame.draw.lines(screen, Green, False, x_points11111, 2)
# 绘制曲线2
pygame.draw.lines(screen, COLOR2, False, x_points2, 2)
pygame.draw.lines(screen, Green, False, x_points22, 2)
pygame.draw.lines(screen, Yellow, False, x_points222, 2)
pygame.draw.lines(screen, Yellow, False, x_points2222, 2)
pygame.draw.lines(screen, Green, False, x_points22222, 2)
# 绘制曲线3
pygame.draw.lines(screen, COLOR3, False, x_points3, 2)
pygame.draw.lines(screen, Green, False, x_points33, 2)
pygame.draw.lines(screen, Yellow, False, x_points333, 2)
pygame.draw.lines(screen, Yellow, False, x_points3333, 2)
pygame.draw.lines(screen, Green, False, x_points33333, 2)
# 绘制曲线2
pygame.draw.lines(screen, Green, False, x_points4, 2)
pygame.draw.lines(screen, Green, False, x_points44, 2)
pygame.draw.lines(screen, Yellow, False, x_points444, 2)
pygame.draw.lines(screen, Yellow, False, x_points4444, 2)
pygame.draw.lines(screen, Green, False, x_points44444, 2)
# 计算文本位置和大小
text_surface = font.render(text, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-900, WINDOW_HEIGHT // 2-490)) # 实时数据显示370
# 绘制文本到窗口
screen.blit(text_surface, text_rect)
# 计算文本位置和大小 2
text_surface = font.render(text2, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-320, WINDOW_HEIGHT // 3+110)) # 实时数据显示370
# 绘制文本到窗口 2
screen.blit(text_surface, text_rect)
# 计算文本位置和大小3
text_surface = font.render(text3, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-889, WINDOW_HEIGHT // 2+10)) # 实时数据显示370
# 绘制文本到窗口 3
screen.blit(text_surface, text_rect)
# 计算文本位置和大小4
text_surface = font.render(text4, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-895, WINDOW_HEIGHT // 2+190)) # 实时数据显示370
# 绘制文本到窗口 4
screen.blit(text_surface, text_rect)
# 计算文本位置和大小5
text_surface = font.render(text5, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-895, WINDOW_HEIGHT // 2+340)) # 实时数据显示370
# 绘制文本到窗口 5
screen.blit(text_surface, text_rect)
# 计算文本位置和大小6
text_surface = font.render(text6, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-895, WINDOW_HEIGHT // 2+480)) # 实时数据显示370
# 绘制文本到窗口 6
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font3.render(text7, True, Green)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-508, WINDOW_HEIGHT // 2-220)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font.render(text10, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+680, WINDOW_HEIGHT // 2-240)) # Remark
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font2.render(text11, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+790, WINDOW_HEIGHT // 2-120)) # 实时
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font2.render(text12, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+772, WINDOW_HEIGHT // 2-200)) # By Axis
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font2.render(text13, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+690, WINDOW_HEIGHT // 2-160)) # 则
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font2.render(text14, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+780, WINDOW_HEIGHT // 2-460)) # 则
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小
text_surface = font66.render(text100, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+10, WINDOW_HEIGHT // 2-485)) # 实时数据显示370
# 绘制文本到窗口
screen.blit(text_surface, text_rect)
###########################################################
# 计算文本位置和大小55
text_surface = font22.render(text600, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+260, WINDOW_HEIGHT // 2-190)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font22.render(str(text601), True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+490, WINDOW_HEIGHT // 2-90)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
###########################################################
# 计算文本位置和大小55
text_surface = font22.render(text700, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+60, WINDOW_HEIGHT // 2-145)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font22.render(str(text701), True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+490, WINDOW_HEIGHT // 2-90)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
###########################################################
# 计算文本位置和大小55
text_surface = font22.render(text800, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-120, WINDOW_HEIGHT // 2-160)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font222.render(str(text801), True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-80, WINDOW_HEIGHT // 2-120)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
###########################################################
# 计算文本位置和大小55
text_surface = font22.render(text900, True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-200, WINDOW_HEIGHT // 2-120)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
# 计算文本位置和大小55
text_surface = font22.render(str(text901), True, BLACK)
text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2+490, WINDOW_HEIGHT // 2-90)) # 实时数据显示370
# 绘制文本到窗口 55
screen.blit(text_surface, text_rect)
###########################################################
# 更新显示
pygame.display.flip()
clock.tick(300) # 设置帧率为60FPS
# 加载图像
image = pygame.image.load(r"D:\Robot.png")
# 设置缩放后的图像宽度和高度
scaled_width = 760
scaled_height = 390
# 调整图像大小
scaled_image = pygame.transform.scale(image, (scaled_width, scaled_height))
# 在画布上绘制缩放后的图像
screen.blit(scaled_image, (700, 86))
# 将画布绘制到窗口
screen.blit(screen, (0, 0))
pygame.display.update() #就连设置颜色都需要更新一次
time.sleep (0.0001)
#################################################3
current_time2 = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
# 构造文件名
filename = f"{current_time2}.jpg"
aa=r'd:\data3\Pic\_'
FName =aa+filename
# 截图并保存到文件
if int(Ques)==1:
#pyautogui.screenshot().save(filename)
pyautogui.screenshot().save(FName)
print('Screenshot Function is ON => ' + time.strftime('%Y-%m-%d %H:%M:%S'))
print(f"Screenshot saved as {filename}")
print(f"Screenshot saved as {FName}")
else:
print('Screenshot Function is Off at ' + time.strftime('%Y-%m-%d %H:%M:%S'))
##################################################
for aaaa4 in range(2):
aaaa4=aaaa4+1
#Red Lamp
Axis1=[0,255,0] # Color
Axis2=[0,255,0]
Axis3=[0,255,0]
Axis4=[0,255,0]
circle_color = [0,255,3]#Red circle_color = [255,0,0]Yellow circle_color = [255,255,0]Green circle_color = [0,255,0]
circle_x = 60
circle_y = 500
circle_size = 12
line_width = 12
pygame.draw.circle(screen,Axis1,[circle_x,circle_y],circle_size,line_width)
pygame.display.flip()
pygame.display.update()
for aaaa4 in range(2):
aaaa4=aaaa4+1
#Red Lamp
Axis1=[0,255,0] # Color
Axis2=[0,255,0]
Axis3=[0,255,0]
Axis4=[0,255,0]
circle_color = [200,0,0]#Red circle_color = [255,0,0]Yellow circle_color = [255,255,0]Green circle_color = [0,255,0]
circle_x = 60
circle_y = 680
circle_size = 12
line_width = 12
pygame.draw.circle(screen,Axis1,[circle_x,circle_y],circle_size,line_width)
pygame.display.flip()
pygame.display.update()
for aaaa4 in range(2):
aaaa4=aaaa4+1
#Red Lamp
Axis1=[0,255,0] # Color
Axis2=[0,255,0]
Axis3=[0,255,0]
Axis4=[0,255,0]
circle_color = [0,255,3]#Red circle_color = [255,0,0]Yellow circle_color = [255,255,0]Green circle_color = [0,255,0]
circle_x = 60
circle_y = 830
circle_size = 12
line_width = 12
pygame.draw.circle(screen,Axis1,[circle_x,circle_y],circle_size,line_width)
pygame.display.flip()
pygame.display.update()
for aaaa4 in range(2):
aaaa4=aaaa4+1
#Red Lamp
Axis1=[0,255,0] # Color
Axis2=[0,255,0]
Axis3=[0,255,0]
Axis4=[0,255,0]
circle_color = [0,255,3]#Red circle_color = [255,0,0]Yellow circle_color = [255,255,0]Green circle_color = [0,255,0]
circle_x = 60
circle_y = 960
circle_size = 12
line_width = 12
pygame.draw.circle(screen,Axis1,[circle_x,circle_y],circle_size,line_width)
pygame.display.flip()
pygame.display.update()
#ReadData()
# 退出pygame
pygame.quit()