恢复代码
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
{
|
||||
'name': '机企猫智能工厂 对接机床',
|
||||
'version': '2.0',
|
||||
'summary': 'sf_machine_connect',
|
||||
'name': 'sf_machine_connect',
|
||||
'version': '1.0',
|
||||
'summary': '智能工厂机床连接模块',
|
||||
'sequence': 10,
|
||||
'description': """
|
||||
这是一个模块
|
||||
@@ -20,7 +20,6 @@
|
||||
'views/WorkCenterBarcodes.xml',
|
||||
'views/Stock_picking_Barcodes.xml',
|
||||
'views/machine_monitor.xml',
|
||||
# 'views/machine_info_present.xml',
|
||||
],
|
||||
|
||||
'assets': {
|
||||
|
||||
@@ -24,23 +24,6 @@ class FtpButton(models.Model):
|
||||
_inherit = 'sf.cnc.processing'
|
||||
|
||||
button_state = fields.Boolean(string='是否已经下发')
|
||||
user_permissions = fields.Boolean(string='权限', related='workorder_id.user_permissions')
|
||||
state = fields.Selection(string='状态', related='workorder_id.state')
|
||||
|
||||
@api.onchange('users_ids')
|
||||
def get_user_permissions(self):
|
||||
uid = self.env.uid
|
||||
for workorder in self:
|
||||
if workorder.users_ids:
|
||||
list_user_id = []
|
||||
for item in workorder.users_ids:
|
||||
list_user_id.append(item.id)
|
||||
if uid in list_user_id:
|
||||
workorder.user_permissions = True
|
||||
else:
|
||||
workorder.user_permissions = False
|
||||
else:
|
||||
workorder.user_permissions = False
|
||||
|
||||
def pri(self):
|
||||
"""
|
||||
@@ -70,13 +53,7 @@ class FtpButton(models.Model):
|
||||
except Exception:
|
||||
raise UserError("补偿值写入执行超时,请检查机床状态或者写入状态")
|
||||
|
||||
# host="192.168.2.158", port=8080, username="MITSUBISHI", password="CNC"
|
||||
host = self.workorder_id.workcenter_id.machine_tool_id.ftp_host
|
||||
port = self.workorder_id.workcenter_id.machine_tool_id.ftp_port
|
||||
username = self.workorder_id.workcenter_id.machine_tool_id.ftp_num
|
||||
pwd = self.workorder_id.workcenter_id.machine_tool_id.ftp_pwd
|
||||
|
||||
ftp = ftp_operate.FtpController(host, port, username, pwd)
|
||||
ftp = ftp_operate.FtpController()
|
||||
# ftp.delAllfile('C://Users//马广威//Desktop//ftp')
|
||||
a = self.cnc_id
|
||||
_logger.info(a.public)
|
||||
@@ -85,14 +62,12 @@ class FtpButton(models.Model):
|
||||
|
||||
# file_path = '{}\{}\{}'.format(a._filestore(), a.store_fname.split('/'[0]), a.display_name)
|
||||
file_path_local = '{}/{}'.format('/nc2machine', a.display_name)
|
||||
file_path_remote = '{}\{}'.format('//M80(192,168,2,142)//DS', a.display_name)
|
||||
file_path_remote = '{}\{}'.format('//(192,168,2,141)//DS', a.display_name)
|
||||
|
||||
with open(file_path_local, mode='wb+') as file:
|
||||
file.write(datas)
|
||||
# 存在本地的文件下发到机床
|
||||
_logger.info("=====================11================")
|
||||
ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
|
||||
_logger.info("=====================22================")
|
||||
except Exception as e:
|
||||
_logger.info("=====================================", e)
|
||||
raise UserError('NC下发执行超时, 请检查下发状态')
|
||||
@@ -109,41 +84,6 @@ class FtpButton(models.Model):
|
||||
# 'type': 'ir.actions.act_window',
|
||||
# 'target': 'new'
|
||||
# }
|
||||
# def up_all(self):
|
||||
# """
|
||||
# 此函数用于将NC代码全部下发到机床
|
||||
# :return:
|
||||
# """
|
||||
# # host="192.168.2.158", port=8080, username="MITSUBISHI", password="CNC"
|
||||
# host = self.workorder_id.workcenter_id.machine_tool_id.ftp_host
|
||||
# port = self.workorder_id.workcenter_id.machine_tool_id.ftp_port
|
||||
# username = self.workorder_id.workcenter_id.machine_tool_id.ftp_num
|
||||
# pwd = self.workorder_id.workcenter_id.machine_tool_id.ftp_pwd
|
||||
#
|
||||
# ftp = ftp_operate.FtpController(host, port, username, pwd)
|
||||
# # ftp.delAllfile('C://Users//马广威//Desktop//ftp')
|
||||
# for item in self.cnc_ids:
|
||||
# a = item.cnc_id
|
||||
# print(a.display_name)
|
||||
# # _logger.info(a.public)
|
||||
# # _logger.info(a.display_name)
|
||||
# # datas = base64.standard_b64decode(a.datas)
|
||||
# #
|
||||
# # # file_path = '{}\{}\{}'.format(a._filestore(), a.store_fname.split('/'[0]), a.display_name)
|
||||
# # # file_path_local = '{}/{}'.format('/nc2machine', a.display_name)
|
||||
# # file_path_local = '{}/{}'.format('D:\\jikimo', a.display_name)
|
||||
# # # file_path_remote = '{}\{}'.format('//M80(192,168,2,142)//DS', a.display_name)
|
||||
# #
|
||||
# # with open(file_path_local, mode='wb+') as file:
|
||||
# # file.write(datas)
|
||||
# # 存在本地的文件下发到机床
|
||||
# # _logger.info("=====================11================")
|
||||
# # ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
|
||||
# # _logger.info("=====================22================")
|
||||
# # except Exception as e:
|
||||
# # _logger.info("=====================================", e)
|
||||
# # raise UserError('NC下发执行超时, 请检查下发状态')
|
||||
|
||||
|
||||
def check_compensation_before_up(self):
|
||||
"""
|
||||
@@ -153,9 +93,9 @@ class FtpButton(models.Model):
|
||||
try:
|
||||
temp_dict = {}
|
||||
temp_dict[
|
||||
'ns=1;s=Project_Default.Group1.Mitsubishi_NC.hongbianliang550'] = self.workorder_id.compensation_value_x
|
||||
'ns=1;s=Project_Default.Group1.Mitsubishi_NC2.hongbianliang550'] = self.workorder_id.compensation_value_x
|
||||
temp_dict[
|
||||
'ns=1;s=Project_Default.Group1.Mitsubishi_NC.hongbianliang551'] = self.workorder_id.compensation_value_y
|
||||
'ns=1;s=Project_Default.Group1.Mitsubishi_NC2.hongbianliang551'] = self.workorder_id.compensation_value_y
|
||||
temp = py2opcua.Py2opcua()
|
||||
# temp.connect()
|
||||
temp.write(temp_dict)
|
||||
@@ -171,21 +111,6 @@ class Machine_ftp(models.Model):
|
||||
"""
|
||||
_inherit = 'sf.machine_tool'
|
||||
|
||||
workorder_ids = fields.One2many('mrp.workorder', 'machine_tool_id', string='工单')
|
||||
|
||||
# 机床配置项目
|
||||
# ftp相关
|
||||
ftp_num = fields.Char('ftp账号')
|
||||
ftp_pwd = fields.Char('ftp密码')
|
||||
ftp_host = fields.Char('ftp地址')
|
||||
ftp_port = fields.Integer('ftp端口')
|
||||
# 补偿值写入相关
|
||||
x_compensation_node = fields.Char('x补偿值节点')
|
||||
y_compensation_node = fields.Char('y补偿值节点')
|
||||
# 数采配置相关
|
||||
machine_ip = fields.Char('机床IP')
|
||||
|
||||
# 机床采集项目
|
||||
timestamp = fields.Datetime('时间戳', readonly=True)
|
||||
signed = fields.Integer('刷新间隔', readonly=True)
|
||||
status = fields.Boolean('在线状态', readonly=True)
|
||||
@@ -235,63 +160,25 @@ class WorkCenterBarcode(models.Model):
|
||||
compensation_value_x = fields.Float(string='X轴补偿值')
|
||||
compensation_value_y = fields.Float(string='Y轴补偿值')
|
||||
button_compensation_state = fields.Boolean(string='是否已经补偿')
|
||||
machine_tool_id = fields.Many2one('sf.machine_tool', string='机床')
|
||||
|
||||
def compensation(self):
|
||||
|
||||
hongbianliang550 = self.workcenter_id.machine_tool_id.x_compensation_node
|
||||
hongbianliang551 = self.workcenter_id.machine_tool_id.y_compensation_node
|
||||
|
||||
"""
|
||||
将节点与其值放入字典,字典作为参数传入
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
temp_dict = {}
|
||||
temp_dict[hongbianliang550] = self.compensation_value_x
|
||||
temp_dict[hongbianliang551] = self.compensation_value_y
|
||||
print("=================================")
|
||||
print(temp_dict)
|
||||
# temp = py2opcua.Py2opcua()
|
||||
# # temp.connect()
|
||||
# temp.write(temp_dict)
|
||||
# self.button_compensation_state = True
|
||||
temp_dict['ns=1;s=Project_Default.Group1.Mitsubishi_NC2.hongbianliang550'] = self.compensation_value_x
|
||||
temp_dict['ns=1;s=Project_Default.Group1.Mitsubishi_NC2.hongbianliang551'] = self.compensation_value_y
|
||||
temp = py2opcua.Py2opcua()
|
||||
# temp.connect()
|
||||
temp.write(temp_dict)
|
||||
self.button_compensation_state = True
|
||||
# temp.disconnect()
|
||||
except Exception as e:
|
||||
_logger.info("=====================================", e)
|
||||
raise UserError('补偿值获取失败,或机床未连接,请检查')
|
||||
|
||||
def up_all(self):
|
||||
"""
|
||||
此函数用于将NC代码全部下发到机床
|
||||
:return:
|
||||
"""
|
||||
# host="192.168.2.158", port=8080, username="MITSUBISHI", password="CNC"
|
||||
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
|
||||
pwd = self.workcenter_id.machine_tool_id.ftp_pwd
|
||||
print(host, port, username, pwd)
|
||||
# ftp = ftp_operate.FtpController(host, port, username, pwd)
|
||||
# ftp.delAllfile('C://Users//马广威//Desktop//ftp')
|
||||
for item in self.cnc_ids:
|
||||
a = item.cnc_id
|
||||
print(a.display_name)
|
||||
_logger.info(a.public)
|
||||
_logger.info(a.display_name)
|
||||
datas = base64.standard_b64decode(a.datas)
|
||||
|
||||
# file_path = '{}\{}\{}'.format(a._filestore(), a.store_fname.split('/'[0]), a.display_name)
|
||||
# file_path_local = '{}/{}'.format('/nc2machine', a.display_name)
|
||||
file_path_local = '{}/{}'.format('D:\\jikimo', a.display_name)
|
||||
# file_path_remote = '{}\{}'.format('//M80(192,168,2,142)//DS', a.display_name)
|
||||
|
||||
with open(file_path_local, mode='wb+') as file:
|
||||
file.write(datas)
|
||||
# 存在本地的文件下发到机床
|
||||
# _logger.info("=====================11================")
|
||||
# ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
|
||||
# _logger.info("=====================22================")
|
||||
# except Exception as e:
|
||||
# _logger.info("=====================================", e)
|
||||
# raise UserError('NC下发执行超时, 请检查下发状态')
|
||||
|
||||
def get__state(self):
|
||||
pay_time = str(datetime.now())
|
||||
json = {
|
||||
|
||||
@@ -45,9 +45,6 @@ class FtpController:
|
||||
self.port = port
|
||||
self.username = username
|
||||
self.password = password
|
||||
# 测试
|
||||
print("==============================================")
|
||||
print(self.username, self.port, self.host, self.password)
|
||||
ftp = FTP_P()
|
||||
# self.ftp.set_debuglevel(2) #打开调试级别2,显示详细信息
|
||||
ftp.set_pasv(0) # 0主动模式 1 #被动模式
|
||||
@@ -71,7 +68,7 @@ class FtpController:
|
||||
:param localpath:
|
||||
:return:
|
||||
"""
|
||||
bufsize = 8192
|
||||
bufsize = 1024
|
||||
# fp = open(localpath, 'rb')
|
||||
# self.ftp.storbinary('STOR ' + remotepath, fp, bufsize)
|
||||
# fp.close()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<record id="sf_install_the_tray_workorder_form_view__scan_barcode" model="ir.ui.view">
|
||||
<field name="name">sf.install.the.tray.workorder.form.scan.barcode</field>
|
||||
@@ -8,6 +8,7 @@
|
||||
<xpath expr="//page//field[@name='tray_code']" position="before">
|
||||
<!-- invisible="1" -->
|
||||
<field name="_barcode_scanned" widget="barcode_handler"/>
|
||||
<field name="tray_code" widget="code"/>
|
||||
</xpath>
|
||||
|
||||
</field>
|
||||
|
||||
@@ -11,26 +11,12 @@
|
||||
<field name="compensation_value_y"/>
|
||||
</group>
|
||||
<div>
|
||||
<div>
|
||||
<field name="button_compensation_state"/>
|
||||
<button string="一键补偿" name="compensation" type="object" confirm="是否确认下发补偿"
|
||||
class="btn-primary" attrs='{"invisible": ["|",
|
||||
("state","!=","progress"),("user_permissions","=",False)]}'/>
|
||||
<button string="一键下发" name="up_all" type="object" style="text-align: right;" confirm="是否确认一键下发"
|
||||
class="btn-primary" attrs='{"invisible": ["|",
|
||||
("state","!=","progress"),("user_permissions","=",False)]}'/>
|
||||
</div>
|
||||
|
||||
|
||||
<field name="button_compensation_state"/>
|
||||
<button string="一键补偿" name="compensation" type="object" confirm="是否确认下发补偿" class="btn-primary"/>
|
||||
<!-- <button string="显示补偿" name="compensation1" type="object" confirm="是否确认下发补偿" class="btn-primary"/>-->
|
||||
<!-- <button string="修改状态" name="get__state" type="object" class="btn-primary"/>-->
|
||||
|
||||
</div>
|
||||
<!-- <div>-->
|
||||
<!-- <button string="一键下发" name="up_all" type="object" confirm="是否确认一键下发"-->
|
||||
<!-- class="btn-primary" attrs='{"invisible": ["|",-->
|
||||
<!-- ("state","!=","progress"),("user_permissions","=",False)]}'/>-->
|
||||
<!-- </div>-->
|
||||
</xpath>
|
||||
|
||||
</field>
|
||||
|
||||
@@ -10,17 +10,8 @@
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='remark']" position="after">
|
||||
<!-- <button string="测试按钮" name="pri" type="object" class="btn-primary"/>-->
|
||||
<!-- <field name="workorder_id" invisible="1"/>-->
|
||||
<field name="button_state"/>
|
||||
<field name="user_permissions" invisible="1"/>
|
||||
<field name="state" invisible="1"/>
|
||||
<button string="下发" name="up" type="object" class="btn-primary" confirm="是否确认下发此程序"
|
||||
attrs='{"invisible": ["|",("state","!=","progress"),
|
||||
("user_permissions","!=",True)]}'/>
|
||||
<!-- <button string="下发" name="up" type="object" class="btn-primary" confirm="是否确认下发此程序"/>-->
|
||||
<!-- <button string="下发" name="up" type="object" class="btn-primary" confirm="是否确认下发此程序"-->
|
||||
<!-- />-->
|
||||
|
||||
<button string="下发按钮" name="up" type="object" class="btn-primary" confirm="是否确认下发此程序"/>
|
||||
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
@@ -9,10 +9,7 @@
|
||||
<!-- <xpath expr="//field[@name='knife_type']" position="before">-->
|
||||
<xpath expr="//form//notebook//page[1]" position="inside">
|
||||
<!-- <xpath expr="//page[@name='other']" position="before">-->
|
||||
<notebook>
|
||||
<page string="机床监控">
|
||||
<!-- <group string="监控">-->
|
||||
<group>
|
||||
<group string="监控">
|
||||
<field name="timestamp"/>
|
||||
<field name="signed"/>
|
||||
<field name="status"/>
|
||||
@@ -98,29 +95,6 @@
|
||||
<!-- <field name="tool_num_process_time24" class="o_form_label"/>-->
|
||||
<!-- </div>-->
|
||||
</group>
|
||||
</page>
|
||||
<page string="机床配置">
|
||||
<!-- <group string="机床配置">-->
|
||||
<group>
|
||||
<group string="ftp相关">
|
||||
<field name="ftp_num"/>
|
||||
<field name="ftp_pwd"/>
|
||||
<field name="ftp_host"/>
|
||||
<field name="ftp_port"/>
|
||||
</group>
|
||||
<group string="补偿值相关">
|
||||
<field name="x_compensation_node"/>
|
||||
<field name="y_compensation_node"/>
|
||||
</group>
|
||||
<group string="数采相关">
|
||||
<field name="machine_ip"/>
|
||||
</group>
|
||||
|
||||
</group>
|
||||
</page>
|
||||
</notebook>
|
||||
|
||||
|
||||
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user