优化代码,恢复屏蔽代码,准备去测试新的NC下发

This commit is contained in:
mgw
2023-02-27 09:43:24 +08:00
parent 6ae0abac94
commit 8247acb79a
2 changed files with 72 additions and 201 deletions

View File

@@ -41,20 +41,6 @@ class FtpButton(models.Model):
else:
workorder.user_permissions = False
def pri(self):
"""
一个测试函数用于检测能否从”获取cnc程序“处获得NC代码文件
:return:
"""
s = self.cnc_id
s1 = self.cnc_id._filestore()
print(s1)
v = self.cnc_id.display_name
a = self.cnc_id.datas
print(v)
print(a)
ftp_operate.FtpController.prin(self)
def up(self):
"""
此函数用于将NC代码下发到机床
@@ -63,37 +49,34 @@ class FtpButton(models.Model):
# 点击下发按钮自动补偿三元检测偏差值
try:
# try:
# if self.sequence_number == '1':
# self.check_compensation_before_up()
# 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
# remote_path = self.workorder_id.workcenter_id.machine_tool_id.ftp_remote_path
# print(host, port, username, pwd, remote_path)
# ftp = ftp_operate.FtpController(host, port, username, pwd)
# # ftp.delAllfile('C://Users//马广威//Desktop//ftp')
try:
if self.sequence_number == '1':
self.check_compensation_before_up()
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
remote_path = self.workorder_id.workcenter_id.machine_tool_id.ftp_remote_path
print(host, port, username, pwd, remote_path)
ftp = ftp_operate.FtpController(host, port, username, pwd)
# ftp.delAllfile('C://Users//马广威//Desktop//ftp')
a = self.cnc_id
# _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_remote = '{}\{}'.format('//M80(192,168,2,142)//DS', a.display_name)
# file_path_remote = '{}\{}'.format(remote_path, 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================")
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_remote = '{}\{}'.format('//M80(192,168,2,142)//DS', a.display_name)
file_path_remote = '{}\{}'.format(remote_path, a.display_name)
with open(file_path_local, mode='wb+') as file:
file.write(datas)
# 存在本地的文件下发到机床
ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
_logger.info("======%s下发成功======" % a.display_name)
up_time = str(datetime.now())
self.env['delivery.record'].create({
@@ -274,6 +257,7 @@ class WorkCenterBarcode(models.Model):
此函数用于将NC代码全部下发到机床
:return:
"""
# 一键下发前删除机床上的全部程序
# try:
# filepath = '/nc2machine'
# del_list = os.listdir(filepath)
@@ -285,41 +269,36 @@ class WorkCenterBarcode(models.Model):
# except Exception as e:
# _logger.info("=====================================", e)
# raise UserError('程序删除失败,请重试')
# # host="192.168.2.158", port=8080, username="MITSUBISHI", password="CNC"
# host="192.168.2.158", port=8080, username="MITSUBISHI", password="CNC"
sequence_collect = []
# 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
# remote_path = self.workcenter_id.machine_tool_id.ftp_remote_path
# print(host, port, username, pwd, remote_path)
# ftp = ftp_operate.FtpController(host, port, username, pwd)
# # ftp.delAllfile('C://Users//马广威//Desktop//ftp')
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
remote_path = self.workcenter_id.machine_tool_id.ftp_remote_path
print(host, port, username, pwd, remote_path)
ftp = ftp_operate.FtpController(host, port, username, pwd)
try:
for item in self.cnc_ids:
a = item.cnc_id
print(a.display_name)
sequence_collect.append(item.sequence_number)
# _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)
# file_path_remote = '{}\{}'.format(remote_path, 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)
# item.button_state = True
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)
file_path_remote = '{}\{}'.format(remote_path, a.display_name)
with open(file_path_local, mode='wb+') as file:
file.write(datas)
# 存在本地的文件下发到机床
ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
_logger.info("======%s下发成功======" % a.display_name)
item.button_state = True
# 增加一键下发记录
up_time = str(datetime.now())
sequence_str = ','.join(sequence_collect)
self.delivery_records.create({
'delivery_type': '一键下发',
'delivery_time': up_time,
@@ -329,8 +308,6 @@ class WorkCenterBarcode(models.Model):
except Exception as e:
_logger.info("=====================================", e)
raise UserError('NC下发执行超时, 请检查下发状态')
# # 下发都执行完毕后按钮标志位变为true
# self.cnc_ids.button_state = True
def get__state(self):
pay_time = str(datetime.now())
@@ -342,34 +319,17 @@ class WorkCenterBarcode(models.Model):
'state': '待付款',
# 'pay_time': pay_time,
# 'get_order_sf': 21,
},
}
# res_str = json.dumps(vals)
url = 'https://bfm.cs.jikimo.com/api/get/state'
requests.post(url, json=json, data=None)
def process_control(self):
if self.routing_type == '获取CNC加工程序' and self.state == '进行中':
json = {
'params': {
'model_name': 'jikimo.process.order',
'field_name': 'name',
'default_code': 'PO-2022-1123-0014',
'state': '加工中',
},
}
url = 'https://bfm.cs.jikimo.com/api/get/state'
requests.post(url, json=json, data=None)
class DeliveryRecord(models.Model):
"""
扫码托盘码可查到制造订单,由制造订单查工单
"""
# _inherit = "mrp.workorder"
_name = "delivery.record"
delivery_type = fields.Char(string='下发方式', readonly=True)
@@ -378,7 +338,6 @@ class DeliveryRecord(models.Model):
workorder_id = fields.Many2one('mrp.workorder', string='工单')
sf_cnc_processing_id = fields.Many2one('sf.cnc.processing', string='NC')
# @api.model
# def create(self, values):
# try:
@@ -391,4 +350,3 @@ class DeliveryRecord(models.Model):
# return super().create(values)
# except:
# raise Exception('b_purchase_order.py:create()')