合并代码

This commit is contained in:
gqh
2023-03-21 13:59:42 +08:00
parent d68f75ede5
commit b42ee83805
4 changed files with 260 additions and 92 deletions

View File

@@ -147,6 +147,32 @@ class Machine_ftp(models.Model):
machine_cut_status = fields.Char('机床切削状态')
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)
@@ -156,12 +182,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')
@@ -258,17 +285,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()
@@ -280,8 +307,10 @@ 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
@@ -331,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):
"""
扫码托盘码可查到制造订单,由制造订单查工单

View File

@@ -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:

View File

@@ -12,7 +12,7 @@
<notebook>
<page string="机床监控">
<!-- <group string="监控">-->
<group>
<group col='12'>
<field name="timestamp"/>
<field name="signed"/>
<field name="status"/>
@@ -24,79 +24,108 @@
<!-- <field name="cut_time"/>-->
<field name="program"/>
<field name="tool_num"/>
<!-- <div class="o_address_format">-->
<!-- <label for="tool_num_process_time1" string="刀位1"/>-->
<!-- <field name="tool_num_process_time1" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time2" string="刀位1"/>-->
<!-- <field name="tool_num_process_time2" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time3" string="刀位1"/>-->
<!-- <field name="tool_num_process_time3" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time4" string="刀位1"/>-->
<!-- <field name="tool_num_process_time4" class="o_form_label"/>-->
<!-- <div></div>-->
<!-- <label for="tool_num_process_time5" string="刀位1"/>-->
<!-- <field name="tool_num_process_time5" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time6" string="刀位1"/>-->
<!-- <field name="tool_num_process_time6" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time7" string="刀位1"/>-->
<!-- <field name="tool_num_process_time7" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time8" string="刀位1"/>-->
<!-- <field name="tool_num_process_time8" class="o_form_label"/>-->
<!-- <div></div>-->
<!-- <label for="tool_num_process_time9" string="刀位1"/>-->
<!-- <field name="tool_num_process_time9" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time10" string="刀位1"/>-->
<!-- <field name="tool_num_process_time10" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time11" string="刀位1"/>-->
<!-- <field name="tool_num_process_time11" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time12" string="刀位1"/>-->
<!-- <field name="tool_num_process_time12" class="o_form_label"/>-->
<!-- <div></div>-->
<!-- <label for="tool_num_process_time13" string="刀位1"/>-->
<!-- <field name="tool_num_process_time13" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time14" string="刀位1"/>-->
<!-- <field name="tool_num_process_time14" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time15" string="刀位1"/>-->
<!-- <field name="tool_num_process_time15" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time16" string="刀位1"/>-->
<!-- <field name="tool_num_process_time16" class="o_form_label"/>-->
<!-- <div></div>-->
<!-- <label for="tool_num_process_time17" string="刀位1"/>-->
<!-- <field name="tool_num_process_time17" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time18" string="刀位1"/>-->
<!-- <field name="tool_num_process_time18" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time19" string="刀位1"/>-->
<!-- <field name="tool_num_process_time19" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time20" string="刀位1"/>-->
<!-- <field name="tool_num_process_time20" class="o_form_label"/>-->
<!-- <div></div>-->
<!-- <label for="tool_num_process_time21" string="刀位1"/>-->
<!-- <field name="tool_num_process_time21" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time22" string="刀位1"/>-->
<!-- <field name="tool_num_process_time22" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time23" string="刀位1"/>-->
<!-- <field name="tool_num_process_time23" class="o_form_label"/>-->
<!-- <span>&amp;nbsp;</span>-->
<!-- <label for="tool_num_process_time24" string="刀位1"/>-->
<!-- <field name="tool_num_process_time24" class="o_form_label"/>-->
<!-- </div>-->
<field name="spindle_speed"/>
</group>
<group string='刀位统计' col='8'>
<field name="tool_num_process_time1"/>
<field name="tool_num_process_time2"/>
<field name="tool_num_process_time3"/>
<field name="tool_num_process_time4"/>
<field name="tool_num_process_time5"/>
<field name="tool_num_process_time6"/>
<field name="tool_num_process_time7"/>
<field name="tool_num_process_time8"/>
<field name="tool_num_process_time9"/>
<field name="tool_num_process_time10"/>
<field name="tool_num_process_time11"/>
<field name="tool_num_process_time12"/>
<field name="tool_num_process_time13"/>
<field name="tool_num_process_time14"/>
<field name="tool_num_process_time15"/>
<field name="tool_num_process_time16"/>
<field name="tool_num_process_time17"/>
<field name="tool_num_process_time18"/>
<field name="tool_num_process_time19"/>
<field name="tool_num_process_time20"/>
<field name="tool_num_process_time21"/>
<field name="tool_num_process_time22"/>
<field name="tool_num_process_time23"/>
<field name="tool_num_process_time24"/>
<!-- <div class="o_address_format"> -->
<!-- <label for="tool_num_process_time1" string="刀位1"/> -->
<!-- <field name="tool_num_process_time1" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time2" string="刀位2"/> -->
<!-- <field name="tool_num_process_time2" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time3" string="刀位3"/> -->
<!-- <field name="tool_num_process_time3" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time4" string="刀位4"/> -->
<!-- <field name="tool_num_process_time4" class="o_form_label"/> -->
<!-- <div></div> -->
<!-- <label for="tool_num_process_time5" string="刀位5"/> -->
<!-- <field name="tool_num_process_time5" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time6" string="刀位6"/> -->
<!-- <field name="tool_num_process_time6" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time7" string="刀位7"/> -->
<!-- <field name="tool_num_process_time7" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time8" string="刀位8"/> -->
<!-- <field name="tool_num_process_time8" class="o_form_label"/> -->
<!-- <div></div> -->
<!-- <label for="tool_num_process_time9" string="刀位9"/> -->
<!-- <field name="tool_num_process_time9" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time10" string="刀位10"/> -->
<!-- <field name="tool_num_process_time10" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time11" string="刀位11"/> -->
<!-- <field name="tool_num_process_time11" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time12" string="刀位12"/> -->
<!-- <field name="tool_num_process_time12" class="o_form_label"/> -->
<!-- <div></div> -->
<!-- <label for="tool_num_process_time13" string="刀位13"/> -->
<!-- <field name="tool_num_process_time13" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time14" string="刀位14"/> -->
<!-- <field name="tool_num_process_time14" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time15" string="刀位15"/> -->
<!-- <field name="tool_num_process_time15" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time16" string="刀位16"/> -->
<!-- <field name="tool_num_process_time16" class="o_form_label"/> -->
<!-- <div></div> -->
<!-- <label for="tool_num_process_time17" string="刀位17"/> -->
<!-- <field name="tool_num_process_time17" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time18" string="刀位18"/> -->
<!-- <field name="tool_num_process_time18" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time19" string="刀位19"/> -->
<!-- <field name="tool_num_process_time19" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time20" string="刀位20"/> -->
<!-- <field name="tool_num_process_time20" class="o_form_label"/> -->
<!-- <div></div> -->
<!-- <label for="tool_num_process_time21" string="刀位21"/> -->
<!-- <field name="tool_num_process_time21" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time22" string="刀位22"/> -->
<!-- <field name="tool_num_process_time22" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time23" string="刀位23"/> -->
<!-- <field name="tool_num_process_time23" class="o_form_label"/> -->
<!-- <span>&amp;nbsp;</span> -->
<!-- <label for="tool_num_process_time24" string="刀位24"/> -->
<!-- <field name="tool_num_process_time24" class="o_form_label"/> -->
<!-- </div> -->
</group>
</page>
<page string="机床配置">
@@ -126,14 +155,86 @@
<field name="machine_cut_status"/>
<field name="machine_emg_status"/>
<field name="machine_mode"/>
<field name="machine_spindle_speed"/>
</group>
</group>
</page>
<page string="刀位配置">
<!-- <group string="机床配置">-->
<group>
<field name="tool_num1"/>
<field name="tool_num2"/>
<field name="tool_num3"/>
<field name="tool_num4"/>
<field name="tool_num5"/>
<field name="tool_num6"/>
<field name="tool_num7"/>
<field name="tool_num8"/>
<field name="tool_num9"/>
<field name="tool_num10"/>
<field name="tool_num11"/>
<field name="tool_num12"/>
<field name="tool_num13"/>
<field name="tool_num14"/>
<field name="tool_num15"/>
<field name="tool_num16"/>
<field name="tool_num17"/>
<field name="tool_num18"/>
<field name="tool_num19"/>
<field name="tool_num20"/>
<field name="tool_num21"/>
<field name="tool_num22"/>
<field name="tool_num23"/>
<field name="tool_num24"/>
</group>
</page>
</notebook>
</xpath>
</field>
</record>
<record id="view_cutting_tool_inherited" model="ir.ui.view">
<field name="name">sf_cutting_tool_extension</field>
<field name="model">sf.cutting_tool.type</field>
<field name="inherit_id" ref="sf_base.form_sf_cutting_tool_type"/>
<field name="arch" type="xml">
<xpath expr="//form//group" position="after">
<group string='刀具寿命'>
<group>
<field name="total_cut_time"/>
<field name="tool_position"/>
</group>
<group>
<field name="predict_life_time"/>
</group>
<div>
<div>
<field name='is_connect_tool_position' invisible='1'/>
<button string="绑定刀位" name="tool_connect_machine" type="object" confirm="是否确认绑定此刀位"
class="btn-primary"/>
<!-- attrs='{"invisible": [("is_connect_tool_position","!=", -->
<!-- "False")]}' -->
<span>&#32;</span>
<button string="解绑刀位" name="tool_unconnect_machine" type="object" confirm="是否解绑此刀位"
class="btn-primary"/>
<!-- attrs='{"invisible": [("is_connect_tool_position","!=", -->
<!-- "False")]}' -->
</div>
</div>
</group>
</xpath>
</field>
</record>

View File

@@ -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下发执行超时, 请检查下发状态')