|
|
@ -1,16 +1,21 @@ |
|
|
|
package org.nl.acs.device_driver.hailiang.hailiang_lettering; |
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import lombok.Data; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.nl.acs.config.AcsConfig; |
|
|
|
import org.nl.acs.config.server.AcsConfigService; |
|
|
|
import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; |
|
|
|
import org.nl.acs.device_driver.DeviceDriver; |
|
|
|
import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; |
|
|
|
import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; |
|
|
|
import org.nl.acs.log.service.LogServer; |
|
|
|
import org.nl.acs.opc.Device; |
|
|
|
import org.nl.acs.order.service.ProduceshiftorderService; |
|
|
|
import org.nl.acs.order.service.ProduceshiftorderdetailService; |
|
|
|
import org.nl.acs.order.service.dto.ProduceshiftorderdetailDto; |
|
|
|
import org.nl.exception.BadRequestException; |
|
|
|
import org.nl.utils.SpringContextHolder; |
|
|
|
import org.openscada.opc.lib.da.Server; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -34,21 +39,38 @@ public class HaiLiangLetteringDeviceDriver extends AbstractOpcDeviceDriver imple |
|
|
|
@Autowired |
|
|
|
ProduceshiftorderdetailService produceshiftorderdetailService = SpringContextHolder.getBean(ProduceshiftorderdetailService.class); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
LogServer logServer = SpringContextHolder.getBean(LogServer.class); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigService.class); |
|
|
|
|
|
|
|
String device_code; |
|
|
|
int mode = 0; |
|
|
|
int last_mode = 0; |
|
|
|
int error = 0; |
|
|
|
int last_error = 0; |
|
|
|
int move = 0; |
|
|
|
int order = 0; |
|
|
|
int last_order = 0; |
|
|
|
int order_detail = 0; |
|
|
|
int last_order_detail = 0; |
|
|
|
int detail_qty = 0; |
|
|
|
int last_detail_qty = 0; |
|
|
|
int detail_qualified_qty = 0; |
|
|
|
int last_detail_qualified_qty = 0; |
|
|
|
|
|
|
|
|
|
|
|
boolean requireSucess = false; |
|
|
|
|
|
|
|
private Date detail_time = new Date(); |
|
|
|
private int detail_time_out = 3000; |
|
|
|
|
|
|
|
Process printProcess; |
|
|
|
String printName = "HP LaserJet Pro MFP M225-M226 PCL 6"; |
|
|
|
String printurl = ""; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Device getDevice() { |
|
|
|
return this.device; |
|
|
@ -68,8 +90,30 @@ public class HaiLiangLetteringDeviceDriver extends AbstractOpcDeviceDriver imple |
|
|
|
//当前工单明细号上料合格数量
|
|
|
|
detail_qualified_qty = this.itemProtocol.getDetail_qualified_qty(); |
|
|
|
if (mode != last_mode) { |
|
|
|
logServer.deviceLog(this.device_code,"mode" ,String.valueOf(mode)); |
|
|
|
logServer.deviceLogToacs(this.device_code,"","","信号mode:" + last_mode + "->" + mode); |
|
|
|
this.setRequireSucess(false); |
|
|
|
} |
|
|
|
if (error != last_error) { |
|
|
|
logServer.deviceLog(this.device_code,"error" ,String.valueOf(error)); |
|
|
|
logServer.deviceLogToacs(this.device_code,"","","信号error:" + last_error + "->" + error); |
|
|
|
} |
|
|
|
if (order != last_order) { |
|
|
|
logServer.deviceLog(this.device_code,"order" ,String.valueOf(order)); |
|
|
|
logServer.deviceLogToacs(this.device_code,"","","信号order:" + last_order + "->" + order); |
|
|
|
} |
|
|
|
if (order_detail != last_order_detail) { |
|
|
|
logServer.deviceLog(this.device_code,"order_detail" ,String.valueOf(order_detail)); |
|
|
|
logServer.deviceLogToacs(this.device_code,"","","信号mode:" + last_order_detail + "->" + order_detail); |
|
|
|
} |
|
|
|
if (detail_qty != last_detail_qty) { |
|
|
|
logServer.deviceLog(this.device_code,"detail_qty" ,String.valueOf(detail_qty)); |
|
|
|
logServer.deviceLogToacs(this.device_code,"","","信号detail_qty:" + last_detail_qty + "->" + detail_qty); |
|
|
|
} |
|
|
|
if (detail_qualified_qty != last_detail_qualified_qty) { |
|
|
|
logServer.deviceLog(this.device_code,"detail_qualified_qty" ,String.valueOf(detail_qualified_qty)); |
|
|
|
logServer.deviceLogToacs(this.device_code,"","","信号detail_qualified_qty:" + last_detail_qualified_qty + "->" + detail_qualified_qty); |
|
|
|
} |
|
|
|
} catch (Exception var17) { |
|
|
|
return; |
|
|
|
} |
|
|
@ -92,14 +136,20 @@ public class HaiLiangLetteringDeviceDriver extends AbstractOpcDeviceDriver imple |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
//申请贴标
|
|
|
|
if(!requireSucess && order > 0 && order_detail > 0 && detail_qty>0 && detail_qualified_qty>0){ |
|
|
|
printMessage(String.valueOf(order),String.valueOf(order_detail),String.valueOf(detail_qualified_qty)); |
|
|
|
} |
|
|
|
break; |
|
|
|
case 4: |
|
|
|
//上料完成
|
|
|
|
//贴标完成
|
|
|
|
if(!requireSucess && order > 0 && order_detail > 0 && detail_qty>0 && detail_qualified_qty>0){ |
|
|
|
update_detail(String.valueOf(order),String.valueOf(order_detail),"01"); |
|
|
|
} |
|
|
|
break; |
|
|
|
case 5: |
|
|
|
//强制上料完成
|
|
|
|
//强制贴标完成
|
|
|
|
if(!requireSucess && order > 0 && order_detail > 0 && detail_qty>0 && detail_qualified_qty>0 ) { |
|
|
|
update_detail(String.valueOf(order),String.valueOf(order_detail),"02"); |
|
|
|
} |
|
|
@ -107,6 +157,12 @@ public class HaiLiangLetteringDeviceDriver extends AbstractOpcDeviceDriver imple |
|
|
|
} |
|
|
|
} |
|
|
|
last_mode = mode; |
|
|
|
last_mode = mode; |
|
|
|
last_error = error; |
|
|
|
last_order = order; |
|
|
|
last_order_detail = order_detail; |
|
|
|
last_detail_qty = detail_qty; |
|
|
|
last_detail_qualified_qty = detail_qualified_qty; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -125,6 +181,37 @@ public class HaiLiangLetteringDeviceDriver extends AbstractOpcDeviceDriver imple |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
public synchronized boolean printMessage(String order, String order_detail,String qty) { |
|
|
|
Date date = new Date(); |
|
|
|
if (date.getTime() - this.detail_time_out < (long) this.detail_time_out) { |
|
|
|
log.trace("触发时间因为小于{}毫秒,而被无视", this.detail_time_out); |
|
|
|
return false; |
|
|
|
} else { |
|
|
|
this.detail_time = date; |
|
|
|
ProduceshiftorderdetailDto dto = produceshiftorderdetailService.findOrderDetailFromCache(String.valueOf(order), String.valueOf(order_detail)); |
|
|
|
if(ObjectUtil.isEmpty(dto)){ |
|
|
|
throw new BadRequestException("未找到可下发工单明细!"); |
|
|
|
} |
|
|
|
String template = dto.getLabeling_template(); |
|
|
|
printName = acsConfigService.findConfigFromCache().get(AcsConfig.PRINTNAME); |
|
|
|
printurl = acsConfigService.findConfigFromCache().get(AcsConfig.PRINTURL); |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
printProcess = Runtime |
|
|
|
.getRuntime() |
|
|
|
.exec(new String[] { |
|
|
|
printurl, "PrinterName=" + printName, |
|
|
|
"LabelName=Label.ct", "Text5="+ "111","Text6="+"222","Text7="+"333","Text8="+"444"}); |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
System.out.println("aaa"); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void writing(String param, String value) { |
|
|
|
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() |
|
|
|