From e576a8f98d09f9b8cb4eb86693b67c5938d6f22e Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Wed, 8 Mar 2023 16:20:03 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E2=80=9C=E6=9C=BA?=
=?UTF-8?q?=E5=BA=8A=E4=B8=BB=E8=BD=B4=E8=BD=AC=E9=80=9F=E2=80=9D=E5=AD=97?=
=?UTF-8?q?=E6=AE=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_machine_connect/models/ftp_client.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/sf_machine_connect/models/ftp_client.py b/sf_machine_connect/models/ftp_client.py
index 3c1d90e3..9da4c5d9 100644
--- a/sf_machine_connect/models/ftp_client.py
+++ b/sf_machine_connect/models/ftp_client.py
@@ -147,6 +147,7 @@ class Machine_ftp(models.Model):
machine_cut_status = fields.Char('机床切削状态')
machine_emg_status = fields.Char('机床急停状态')
machine_mode = fields.Char('机床操作模式')
+ machine_spindle_speed = fields.Char('机床主轴转速')
# 机床采集项目
timestamp = fields.Datetime('时间戳', readonly=True)
From 7074911b6eb061f0925b15742260a8c790a42e4e Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Fri, 10 Mar 2023 18:18:12 +0800
Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=90=88=E5=B9=B6?=
=?UTF-8?q?=E4=B8=8B=E5=8F=91bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_machine_connect/models/ftp_client.py | 31 ++--
sf_machine_connect/views/machine_monitor.xml | 178 +++++++++++--------
sf_machine_connect/wizard/action_up.py | 25 ++-
3 files changed, 142 insertions(+), 92 deletions(-)
diff --git a/sf_machine_connect/models/ftp_client.py b/sf_machine_connect/models/ftp_client.py
index 9da4c5d9..322180e1 100644
--- a/sf_machine_connect/models/ftp_client.py
+++ b/sf_machine_connect/models/ftp_client.py
@@ -157,12 +157,13 @@ class Machine_ftp(models.Model):
time_on_now = fields.Char('本次在线时长', readonly=True)
tool_num = fields.Integer('当前刀具', readonly=True)
program = fields.Char('当前程序', readonly=True)
- run_status = fields.Selection([('0', '空闲中'), ('1', '加工中'), ('2', '加工中'), ('3', '等待中')], string='运行状态',
+ run_status = fields.Selection([('0', '空闲中'), ('1', '加工中'), ('2', '加工中'), ('3', '加工中')], string='运行状态',
readonly=True, default='0')
run_time = fields.Char('总运行时长', readonly=True)
cut_time = fields.Char('总切削时长', readonly=True)
cut_status = fields.Selection([('0', '未切削'), ('1', '切削中'), ('2', '切削中'), ('3', '切削中')], string='切削状态',
readonly=True, default='0')
+ spindle_speed = fields.Char('主轴转速', readonly=True)
tool_num_process_time1 = fields.Char('刀位1', readonly=True, default='0')
tool_num_process_time2 = fields.Char('刀位2', readonly=True, default='0')
@@ -259,17 +260,17 @@ class WorkCenterBarcode(models.Model):
:return:
"""
# 一键下发前删除机床上的全部程序
- # try:
- # filepath = '/nc2machine'
- # del_list = os.listdir(filepath)
- # _logger.info("=====================================", del_list)
- # for f in del_list:
- # file_path = os.path.join(filepath, f)
- # if os.path.isfile(file_path):
- # os.remove(file_path)
- # except Exception as e:
- # _logger.info("=====================================", e)
- # raise UserError('程序删除失败,请重试')
+ try:
+ filepath = '/nc2machine'
+ del_list = os.listdir(filepath)
+ _logger.info("=====================================%s" % del_list)
+ for f in del_list:
+ file_path = os.path.join(filepath, f)
+ if os.path.isfile(file_path):
+ os.remove(file_path)
+ except Exception as e:
+ _logger.info("=====================================", e)
+ raise UserError('程序删除失败,请重试')
# host="192.168.2.158", port=8080, username="MITSUBISHI", password="CNC"
try:
self.compensation()
@@ -281,8 +282,12 @@ class WorkCenterBarcode(models.Model):
username = self.workcenter_id.machine_tool_id.ftp_num
pwd = self.workcenter_id.machine_tool_id.ftp_pwd
remote_path = self.workcenter_id.machine_tool_id.ftp_remote_path
- print(host, port, username, pwd, remote_path)
+ _logger.info("=====================1666666661111================%s,%s,%s,%s" % (host, port, username, pwd))
ftp = ftp_operate.FtpController(host, port, username, pwd)
+ _logger.info("=====================1777777777111================")
+
+
+
try:
for item in self.cnc_ids:
a = item.cnc_id
diff --git a/sf_machine_connect/views/machine_monitor.xml b/sf_machine_connect/views/machine_monitor.xml
index e90e8856..7c43960d 100644
--- a/sf_machine_connect/views/machine_monitor.xml
+++ b/sf_machine_connect/views/machine_monitor.xml
@@ -12,7 +12,7 @@
-
+
@@ -24,79 +24,108 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -126,6 +155,7 @@
+
diff --git a/sf_machine_connect/wizard/action_up.py b/sf_machine_connect/wizard/action_up.py
index 4975409e..e72fa5ff 100644
--- a/sf_machine_connect/wizard/action_up.py
+++ b/sf_machine_connect/wizard/action_up.py
@@ -26,7 +26,18 @@ class UpSelectWizard(models.TransientModel):
def confirm_up(self):
-
+ # 合并下发前删除机床上的全部程序
+ try:
+ filepath = '/nc2machine'
+ del_list = os.listdir(filepath)
+ _logger.info("=====================================%s" % del_list)
+ for f in del_list:
+ file_path = os.path.join(filepath, f)
+ if os.path.isfile(file_path):
+ os.remove(file_path)
+ except Exception as e:
+ _logger.info("=====================================", e)
+ raise UserError('程序删除失败,请重试')
host = self.workcenter_id.machine_tool_id.ftp_host
port = self.workcenter_id.machine_tool_id.ftp_port
username = self.workcenter_id.machine_tool_id.ftp_num
@@ -35,6 +46,8 @@ class UpSelectWizard(models.TransientModel):
print(host, port, username, pwd, remote_path)
ftp = ftp_operate.FtpController(host, port, username, pwd)
sequence_collect = []
+ file_path_local = ''
+ file_path_remote = ''
try:
# 给文件名
begin_name1 = self.program_ids[0].cnc_id.display_name.split('-')
@@ -61,12 +74,12 @@ class UpSelectWizard(models.TransientModel):
with open(file_path_local, mode='ab+') as file:
file.write(datas)
- # 存在本地的文件下发到机床
- _logger.info("==========存在服务器成功,准备下发===========")
- ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
- _logger.info("======%s下发成功======" % a.display_name)
# 下发成功标识
item.button_state = True
+
+ # 存在本地的文件下发到机床
+ _logger.info("==========存在服务器成功,准备下发===========")
+ ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
ftp.close_ftp()
up_time = str(datetime.now())
@@ -78,6 +91,8 @@ class UpSelectWizard(models.TransientModel):
})
_logger.info("==============合并下发成功==============")
except Exception as e:
+ for item in self.program_ids:
+ item.button_state = False
_logger.info("=====================================", e)
raise UserError('NC下发执行超时, 请检查下发状态')
From 5f09b1f5cda86e810fea6d601cf2a3c07600ff5f Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Thu, 16 Mar 2023 10:30:41 +0800
Subject: [PATCH 3/4] =?UTF-8?q?=E5=88=80=E4=BD=8D=E5=AF=B9=E8=B1=A1?=
=?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=BF=E5=91=BD=E7=AD=89=E5=AD=97=E6=AE=B5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_machine_connect/models/ftp_client.py | 43 +++++++++++-
sf_machine_connect/models/ftp_operate.py | 7 ++
sf_machine_connect/views/machine_monitor.xml | 71 ++++++++++++++++++++
3 files changed, 119 insertions(+), 2 deletions(-)
diff --git a/sf_machine_connect/models/ftp_client.py b/sf_machine_connect/models/ftp_client.py
index 322180e1..fa4268af 100644
--- a/sf_machine_connect/models/ftp_client.py
+++ b/sf_machine_connect/models/ftp_client.py
@@ -148,6 +148,31 @@ class Machine_ftp(models.Model):
machine_emg_status = fields.Char('机床急停状态')
machine_mode = fields.Char('机床操作模式')
machine_spindle_speed = fields.Char('机床主轴转速')
+ # 刀位配置
+ tool_num1 = fields.Char('刀位1')
+ tool_num2 = fields.Char('刀位2')
+ tool_num3 = fields.Char('刀位3')
+ tool_num4 = fields.Char('刀位4')
+ tool_num5 = fields.Char('刀位5')
+ tool_num6 = fields.Char('刀位6')
+ tool_num7 = fields.Char('刀位7')
+ tool_num8 = fields.Char('刀位8')
+ tool_num9 = fields.Char('刀位9')
+ tool_num10 = fields.Char('刀位10')
+ tool_num11 = fields.Char('刀位11')
+ tool_num12 = fields.Char('刀位12')
+ tool_num13 = fields.Char('刀位13')
+ tool_num14 = fields.Char('刀位14')
+ tool_num15 = fields.Char('刀位15')
+ tool_num16 = fields.Char('刀位16')
+ tool_num17 = fields.Char('刀位17')
+ tool_num18 = fields.Char('刀位18')
+ tool_num19 = fields.Char('刀位19')
+ tool_num20 = fields.Char('刀位20')
+ tool_num21 = fields.Char('刀位21')
+ tool_num22 = fields.Char('刀位22')
+ tool_num23 = fields.Char('刀位23')
+ tool_num24 = fields.Char('刀位24')
# 机床采集项目
timestamp = fields.Datetime('时间戳', readonly=True)
@@ -286,8 +311,6 @@ class WorkCenterBarcode(models.Model):
ftp = ftp_operate.FtpController(host, port, username, pwd)
_logger.info("=====================1777777777111================")
-
-
try:
for item in self.cnc_ids:
a = item.cnc_id
@@ -337,6 +360,22 @@ class WorkCenterBarcode(models.Model):
requests.post(url, json=json, data=None)
+class CuttingTimeToolType(models.Model):
+ _inherit = 'sf.cutting_tool.type'
+ total_cut_time = fields.Char(string='总切削时长')
+ predict_life_time = fields.Char(string='预估寿命')
+ # 只能看到未被占用的刀位,或者有提示说占没占用
+ tool_position = fields.Char(string='选择刀位')
+ cnc_ids = fields.One2many(string='选择机床')
+ is_connect_tool_position = fields.Boolean(string='是否已绑定刀位', default=False)
+
+ def tool_connect_machine(self):
+ pass
+
+ def tool_unconnect_machine(self):
+ pass
+
+
class DeliveryRecord(models.Model):
"""
扫码托盘码可查到制造订单,由制造订单查工单
diff --git a/sf_machine_connect/models/ftp_operate.py b/sf_machine_connect/models/ftp_operate.py
index 315fa765..dd75ee09 100644
--- a/sf_machine_connect/models/ftp_operate.py
+++ b/sf_machine_connect/models/ftp_operate.py
@@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
import os
+import logging
from ftplib import FTP
+_logger = logging.getLogger(__name__)
+
class FTP_P(FTP):
"""
@@ -41,19 +44,23 @@ class FtpController:
# 三菱机床连接
def __init__(self, host="192.168.2.158", port=8080, username="MITSUBISHI", password="CNC"):
+ _logger.info("===================ftppppp==================")
self.host = host
self.port = port
self.username = username
self.password = password
+ _logger.info("===================ftppppp==================%s,%s,%s,%s" % self.host, self.port, self.username, self.password)
# 测试
print("==============================================")
print(self.username, self.port, self.host, self.password)
ftp = FTP_P()
+ _logger.info("===================connect==================")
# self.ftp.set_debuglevel(2) #打开调试级别2,显示详细信息
ftp.set_pasv(0) # 0主动模式 1 #被动模式
try:
ftp.connect(self.host, self.port)
ftp.login(self.username, self.password)
+ _logger.info("=================连接成功==================")
print("连接成功")
self.ftp = ftp
except Exception as e:
diff --git a/sf_machine_connect/views/machine_monitor.xml b/sf_machine_connect/views/machine_monitor.xml
index 7c43960d..30324ed5 100644
--- a/sf_machine_connect/views/machine_monitor.xml
+++ b/sf_machine_connect/views/machine_monitor.xml
@@ -160,10 +160,81 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ sf_cutting_tool_extension
+ sf.cutting_tool.type
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From 4b82d20f186c7b5a0d05ccc934b607568ddadd53 Mon Sep 17 00:00:00 2001
From: mgw <1392924357@qq.com>
Date: Thu, 16 Mar 2023 11:37:35 +0800
Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=AD=A3bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_machine_connect/models/ftp_client.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sf_machine_connect/models/ftp_client.py b/sf_machine_connect/models/ftp_client.py
index fa4268af..9b5dda7a 100644
--- a/sf_machine_connect/models/ftp_client.py
+++ b/sf_machine_connect/models/ftp_client.py
@@ -366,7 +366,7 @@ class CuttingTimeToolType(models.Model):
predict_life_time = fields.Char(string='预估寿命')
# 只能看到未被占用的刀位,或者有提示说占没占用
tool_position = fields.Char(string='选择刀位')
- cnc_ids = fields.One2many(string='选择机床')
+ # cnc_ids = fields.One2many(string='选择机床')
is_connect_tool_position = fields.Boolean(string='是否已绑定刀位', default=False)
def tool_connect_machine(self):