新增1线,是从2线平移过去的。

This commit is contained in:
caixiang 2023-10-24 14:35:28 +08:00
parent 22115af70c
commit 4e10024bc8
28 changed files with 1329 additions and 1991 deletions

View File

@ -38,7 +38,10 @@
<junit.version>4.13.2</junit.version>
<jedis.version>4.2.2</jedis.version>
<druid.version>1.2.9</druid.version>
<mybatisplus.version>3.5.1</mybatisplus.version>
<!-- <mybatisplus.version>3.5.1</mybatisplus.version>-->
<mybatisplus.version>3.5.3</mybatisplus.version>
<sqlserver.version>4.0</sqlserver.version>
<oracle.version>11.2.0.3</oracle.version>
<commons.lang.version>3.12.0</commons.lang.version>

View File

@ -194,9 +194,10 @@
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="EVENT1_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 2线 开始 -->
<appender name="EVENT1_APPENDER_LINE2" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文档的路径及文档名 -->
<file>${logging.eventlog}/event1/kuka-event1-log-info.log</file>
<file>${logging.eventlog}/line2/event1/kuka-event1-log-info.log</file>
<!--日志文档输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
@ -204,7 +205,7 @@
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${logging.eventlog}/kuka-event1-log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>${logging.eventlog}/line2/kuka-event1-log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
<maxFileSize>100MB</maxFileSize>
@ -218,9 +219,9 @@
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="EVENT2_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<appender name="EVENT2_APPENDER_LINE2" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文档的路径及文档名 -->
<file>${logging.eventlog}/event2/kuka-event2-log-info.log</file>
<file>${logging.eventlog}/line2/event2/kuka-event2-log-info.log</file>
<!--日志文档输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
@ -228,7 +229,7 @@
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${logging.eventlog}/kuka-event2-log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>${logging.eventlog}/line2/kuka-event2-log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
<maxFileSize>100MB</maxFileSize>
@ -242,9 +243,9 @@
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="EVENT3_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<appender name="EVENT3_APPENDER_LINE2" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文档的路径及文档名 -->
<file>${logging.eventlog}/event3/kuka-event3-log-info.log</file>
<file>${logging.eventlog}/line2/event3/kuka-event3-log-info.log</file>
<!--日志文档输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
@ -252,7 +253,7 @@
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${logging.eventlog}/kuka-event3-log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>${logging.eventlog}/line2/kuka-event3-log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
<maxFileSize>100MB</maxFileSize>
@ -266,9 +267,82 @@
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 2线 结束 -->
<!-- 1线 开始 -->
<appender name="EVENT1_APPENDER_LINE1" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文档的路径及文档名 -->
<file>${logging.eventlog}/line1/event1/kuka-event1-log-info.log</file>
<!--日志文档输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${logging.eventlog}/line1/kuka-event1-log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
<maxFileSize>100MB</maxFileSize>
<maxHistory>999</maxHistory>
<totalSizeCap>200GB</totalSizeCap>
</rollingPolicy>
<!-- 此日志文档只记录info级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>info</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="EVENT2_APPENDER_LINE1" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文档的路径及文档名 -->
<file>${logging.eventlog}/line1/event2/kuka-event2-log-info.log</file>
<!--日志文档输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${logging.eventlog}/line1/kuka-event2-log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
<maxFileSize>100MB</maxFileSize>
<maxHistory>999</maxHistory>
<totalSizeCap>200GB</totalSizeCap>
</rollingPolicy>
<!-- 此日志文档只记录info级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>info</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="EVENT3_APPENDER_LINE1" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文档的路径及文档名 -->
<file>${logging.eventlog}/line1/event3/kuka-event3-log-info.log</file>
<!--日志文档输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${logging.eventlog}/line1/kuka-event3-log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
<maxFileSize>100MB</maxFileSize>
<maxHistory>999</maxHistory>
<totalSizeCap>200GB</totalSizeCap>
</rollingPolicy>
<!-- 此日志文档只记录info级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>info</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 1线 结束 -->
<!-- 2.3 level为 WARN 日志,时间滚动输出 -->
<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
@ -481,15 +555,30 @@
<appender-ref ref="EQ_COMM_LOG_ERROR_FILE" />
</logger>
<logger name="EVENT1" level="INFO" additivity="false">
<appender-ref ref="EVENT1_APPENDER" />
<!-- LINE2 开始 -->
<logger name="EVENT1Line2" level="INFO" additivity="false">
<appender-ref ref="EVENT1_APPENDER_LINE2" />
</logger>
<logger name="EVENT2" level="INFO" additivity="false">
<appender-ref ref="EVENT2_APPENDER" />
<logger name="EVENT2Line2" level="INFO" additivity="false">
<appender-ref ref="EVENT2_APPENDER_LINE2" />
</logger>
<logger name="EVENT3" level="INFO" additivity="false">
<appender-ref ref="EVENT3_APPENDER" />
<logger name="EVENT3Line2" level="INFO" additivity="false">
<appender-ref ref="EVENT3_APPENDER_LINE2" />
</logger>
<!-- LINE2 结束 -->
<!-- LINE1 开始 -->
<logger name="EVENT1Line1" level="INFO" additivity="false">
<appender-ref ref="EVENT1_APPENDER_LINE1" />
</logger>
<logger name="EVENT2Line1" level="INFO" additivity="false">
<appender-ref ref="EVENT2_APPENDER_LINE1" />
</logger>
<logger name="EVENT3Line1" level="INFO" additivity="false">
<appender-ref ref="EVENT3_APPENDER_LINE1" />
</logger>
<!-- LINE1 结束 -->
<logger name="com.cnbm.packing" additivity="false">
<appender-ref ref="PACKING_LOG_DEBUG_FILE" />

View File

@ -1,601 +0,0 @@
//package com.cnbm.dispatch;
//
//import cn.hutool.core.date.DateUtil;
//import com.cnbm.dispatch.enums.kuka.step1.Step1Mes2PlcVar;
//import com.cnbm.dispatch.enums.kuka.step1.Step1Plc2MesVar;
//import com.cnbm.dispatch.enums.kuka.step2.Step2Mes2PlcVar;
//import com.cnbm.dispatch.enums.kuka.step2.Step2Plc2MesVar;
//import com.cnbm.dispatch.enums.kuka.step3.Step3Mes2PlcVar;
//import com.cnbm.dispatch.enums.kuka.step3.Step3Plc2MesVar;
//import com.cnbm.packing.dto.CamlineExtendArgDTO;
//import com.cnbm.packing.dto.CamlineSubIdDTO;
//import com.cnbm.packing.entity.WoPackagingBox;
//import com.cnbm.packing.entity.WoPackagingBoxSubstrate;
//import com.cnbm.packing.entity.WoPowerLevel;
//import com.cnbm.packing.service.*;
//import com.cnbm.s7.s7connector.enmuc.S7Client;
//import com.cnbm.s7.s7connector.type.PlcVar;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.ApplicationArguments;
//import org.springframework.boot.ApplicationRunner;
//import org.springframework.core.annotation.Order;
//import org.springframework.stereotype.Component;
//
//import java.text.DecimalFormat;
//import java.text.Format;
//import java.time.LocalDateTime;
//import java.util.Arrays;
//import java.util.Date;
//import java.util.concurrent.Executors;
//import java.util.concurrent.ScheduledExecutorService;
//import java.util.concurrent.TimeUnit;
//
///**
// * @Desc: "test 待测试"
// * @Author: caixiang
// * @DATE: 2022/12/23 12:33
// */
//@Component
//@Order(value = 1)
//public class KukaJoinThread implements ApplicationRunner {
// private static final Logger logger = LoggerFactory.getLogger(KukaJoinThread.class);
// private static final Logger loggerEvent1 = LoggerFactory.getLogger("EVENT1");
// private static final Logger loggerEvent2 = LoggerFactory.getLogger("EVENT2");
// private static final Logger loggerEvent3 = LoggerFactory.getLogger("EVENT3");
//
// @Autowired
// DynamicDataSourceService service;
// @Autowired
// WoPowerLevelServiceBiz levelServiceBiz;
//
// @Autowired
// WoCompensationPowerServiceBiz compensationPowerServiceBiz;
//
// @Autowired
// WoPackagingBoxSubstrateServiceBiz substrateServiceBiz;
//
// @Autowired
// WoPackagingBoxServiceBiz boxServiceBiz;
//
// public KukaJoinThread(){
// this.kukaStep1 = Executors.newScheduledThreadPool(1);
// this.kukaStep2 = Executors.newScheduledThreadPool(1);
// this.kukaStep3 = Executors.newScheduledThreadPool(1);
// }
//
// private ScheduledExecutorService kukaStep1;
// private ScheduledExecutorService kukaStep2;
// private ScheduledExecutorService kukaStep3;
//
//
//
//
// /**
// * return
// * 成功 返回相应的object对象
// * 失败 返回null
// * */
// private Object read(S7Client s7Client,Step1Plc2MesVar var) {
// try {
// return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
// }catch (Throwable e){
// logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
// return null;
// }
// }
// private void write(S7Client s7Client, Step1Mes2PlcVar var, Object newValue) {
// if(var.getType().equals(PlcVar.STRING_Array)){
// String[] s = (String[])newValue;
// String[] ss = (String[])newValue;
// if(s.length > var.getLength() ){
// ss = new String[var.getLength()];
// for(int i=0;i< var.getLength();i++){
// ss[i] = s[i];
// }
// }
// s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
// }else {
// s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
// }
// }
//
// private Object read(S7Client s7Client, Step2Plc2MesVar var) {
// try {
// return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
// }catch (Throwable e){
// logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
// return null;
// }
// }
// private void write(S7Client s7Client, Step2Mes2PlcVar var, Object newValue) {
// if(var.getType().equals(PlcVar.STRING_Array)){
// String[] s = (String[])newValue;
// String[] ss = (String[])newValue;
// if(s.length > var.getLength() ){
// ss = new String[var.getLength()];
// for(int i=0;i< var.getLength();i++){
// ss[i] = s[i];
// }
// }
// s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
// }else {
// s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
// }
// }
//
// private Object read(S7Client s7Client, Step3Plc2MesVar var) {
// try {
// return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
// }catch (Throwable e){
// logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
// return null;
// }
// }
// private void write(S7Client s7Client, Step3Mes2PlcVar var, Object newValue) {
// if(var.getType().equals(PlcVar.STRING_Array)){
// String[] s = (String[])newValue;
// String[] ss = (String[])newValue;
// if(s.length > var.getLength() ){
// ss = new String[var.getLength()];
// for(int i=0;i< var.getLength();i++){
// ss[i] = s[i];
// }
// }
// s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
// }else {
// s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
// }
// }
//
//
// public String getBoxId(String sapMaterial){
// Integer todayBoxNum = service.getTodayBoxNum()+1;
// String nowTime = DateUtil.format(new Date(), "yyMMdd");
//
// todayBoxNum+=500;
// logger.info("BOXID生成Event-------现在生成boxId sapMaterial: "+sapMaterial+"nowTime:"+nowTime+"todayBoxNum:"+formateString(todayBoxNum));
// String res = "301"+sapMaterial+nowTime+formateString(todayBoxNum);
// return res;
// }
//
//
// public String getErrorBoxId(String sapMaterial){
//
// String nowTime = DateUtil.format(new Date(), "yyMMdd");
// String mixBoxError = "001";
// String res = "444"+sapMaterial+nowTime+mixBoxError;
// logger.info("BOXID生成Event-------现在生成errBoxId sapMaterial: "+sapMaterial+"nowTime:"+nowTime);
//
// return res;
// }
//
// public String removeKG(String str){
// return str.substring(0,17);
// }
//
// public static void main(String[] args) {
// Integer a = 102;
// Format f1 = new DecimalFormat("000");
// System.out.println(f1.format(a));
// }
// public String formateString(Integer a){
// Format f1 = new DecimalFormat("000");
// return f1.format(a);
// }
//
// //return true 出现混档了return false 没有出现混档
// private boolean isMixLevel(String[] subIds,Integer size){
// String correctLevel = substrateServiceBiz.getBySubId(subIds[0]).getPowerLevel();
// String errMsg = "以下基板ID出现混档";
// boolean res = false;
// for(int i=0;i<size;i++){
// String powerLevel = substrateServiceBiz.getBySubId(subIds[i]).getPowerLevel();
//
// if(!powerLevel.equals(correctLevel)){
// errMsg += "基板ID:"+subIds[i]+" 档位:"+powerLevel+", ";
// res = true;
// }
// }
// if(res){
// logger.error(errMsg);
// }
//
// return res;
// }
//
//
//
//
// @Override
// public void run(ApplicationArguments args) throws Exception {
//
// kukaStep1.scheduleAtFixedRate(new Runnable() {
// @Override
// public void run() {
// try {
//
// //调度开始
// logger.info("");
// logger.info("================================== 现在开始执行 过程一 任务( 开始 ===================================");
// Integer subArrived = waitingForTarget(Step1Plc2MesVar.SubArrivedToMes, true);
// if(subArrived != 1){
// logger.info("标签打印Event--- 失败"+" --- "+" MES监听 Step1Plc2MesVar.SubArrivedToMes 是否 等于 1 失败");
// } else if (subArrived == 2) {
// throw new Exception("MES 监听值出现异常。");
// }
// logger.info("标签打印Event --- 成功 ---- MES监听到 SubArrivedToMes==true");
//
// //. 从plc 中获取 subId lineNum
// String subId = (String) read(S7Client.S7_DDJ1,Step1Plc2MesVar.SubIdToMes);
// Integer lineNum = (Integer) read(S7Client.S7_DDJ1,Step1Plc2MesVar.LineNum);
// //把基板ID字符串的空格去掉因为plc中设置的20位但实际基板ID就是17位因为带空格去数据库查询 有问题的
// if(subId == null || lineNum == null){
// logger.info("标签打印Event--- 失败"+" --- "+" MES采集到null值subId:"+subId+",lineNum:"+lineNum);
// }
// subId = removeKG(subId);
// logger.info("标签打印Event --- 成功 ---- MES 从plu中 read 到基板id:"+subId);
//
// //. MES 业务
// //=============== MES 业务 开始 =================
// logger.info("================= 现在开始执行 过程一 任务 ( MES 业务 ) ( 开始 ) ==================");
// //1. 从comline数据库中获取 实际pmpp
// float pmppActual = service.getPMPPBySubId(subId);
// //2. 匹配和计算补偿功率
// float pmppCompensation = compensationPowerServiceBiz.calculCompensationPMPP(pmppActual,lineNum);
// //3. 依据补偿功率获取工艺参数并且把这些工艺参数传给kuka
// WoPowerLevel argByPMPP = levelServiceBiz.getArgByPMPP(pmppCompensation, lineNum);
// write(S7Client.S7_DDJ1,Step1Mes2PlcVar.dLable_Pnom,Integer.valueOf(argByPMPP.getPowerClass()));
// write(S7Client.S7_DDJ1,Step1Mes2PlcVar.dLable_Voc,argByPMPP.getLableVoc());
// write(S7Client.S7_DDJ1,Step1Mes2PlcVar.dLable_Isc,argByPMPP.getLableIsc());
// write(S7Client.S7_DDJ1,Step1Mes2PlcVar.dLable_Vmpp,argByPMPP.getLableVmpp());
// write(S7Client.S7_DDJ1,Step1Mes2PlcVar.dLable_Impp,argByPMPP.getLableImpp());
// logger.info("标签打印Event--- 采集到 基板ID: "+subId+", 线边号:"+lineNum+"从camline 获取到实际pmpp"+pmppActual+",计算后 补偿功率:"+pmppCompensation+",dLable_Pnom: "+argByPMPP.getPowerClass() +",dLable_Voc: "+argByPMPP.getLableVoc()+",dLable_Isc: "+argByPMPP.getLableIsc()+",dLable_Vmpp: "+argByPMPP.getLableVmpp()+",dLable_Impp: "+argByPMPP.getLableImpp());
//
//
//
// //4. 把基板录到数据库
// WoPackagingBoxSubstrate woPackagingBoxSubstrate = new WoPackagingBoxSubstrate();
// woPackagingBoxSubstrate.setLineBody(lineNum);
// woPackagingBoxSubstrate.setPowerLevel(argByPMPP.getPowerClass());
// woPackagingBoxSubstrate.setSapMaterial(argByPMPP.getSapMaterialNum());
// woPackagingBoxSubstrate.setWoSubstrateId(subId);
// woPackagingBoxSubstrate.setActualPmpp(pmppActual);
// woPackagingBoxSubstrate.setCreateTime(LocalDateTime.now());
// //计算后的补偿功率
// woPackagingBoxSubstrate.setPmpp(pmppCompensation);
//
//
// //5. 从camline那里获取可变字段
// CamlineExtendArgDTO extendArgFromCamline = service.getExtendArgFromCamline(subId);
// logger.info("标签打印Event--- 基板ID: "+subId+", 从camline获取PID16~PID22 的实测数据 成功, 数据内容:"+extendArgFromCamline.toString());
// woPackagingBoxSubstrate.setLastUpdateTime(extendArgFromCamline.getLastUpdateTime());
//
// woPackagingBoxSubstrate.setOrderName(extendArgFromCamline.getOrderName());
// woPackagingBoxSubstrate.setBinclassFl1(extendArgFromCamline.getBinclassFl1());
// woPackagingBoxSubstrate.setBinclassFl2(extendArgFromCamline.getBinclassFl2());
// woPackagingBoxSubstrate.setEtaFl1(extendArgFromCamline.getEtaFl1());
// woPackagingBoxSubstrate.setEtaFl2(extendArgFromCamline.getEtaFl2());
// woPackagingBoxSubstrate.setFfFl1(extendArgFromCamline.getFfFl1());
// woPackagingBoxSubstrate.setFfFl2(extendArgFromCamline.getFfFl2());
// woPackagingBoxSubstrate.setImppFl1(extendArgFromCamline.getImppFl1());
// woPackagingBoxSubstrate.setImppFl2(extendArgFromCamline.getImppFl2());
// woPackagingBoxSubstrate.setInsolflashcontrolFl1(extendArgFromCamline.getInsolflashcontrolFl1());
// woPackagingBoxSubstrate.setInsolflashcontrolFl2(extendArgFromCamline.getInsolflashcontrolFl2());
// woPackagingBoxSubstrate.setInsolmppFl1(extendArgFromCamline.getInsolmppFl1());
// woPackagingBoxSubstrate.setInsolmppFl2(extendArgFromCamline.getInsolmppFl2());
// woPackagingBoxSubstrate.setInsolvocFl1(extendArgFromCamline.getInsolvocFl1());
// woPackagingBoxSubstrate.setInsolvocFl2(extendArgFromCamline.getInsolvocFl2());
// woPackagingBoxSubstrate.setInsolFl1(extendArgFromCamline.getInsolFl1());
// woPackagingBoxSubstrate.setInsolFl2(extendArgFromCamline.getInsolFl2());
// woPackagingBoxSubstrate.setIscFl1(extendArgFromCamline.getIscFl1());
// woPackagingBoxSubstrate.setIscFl2(extendArgFromCamline.getIscFl2());
// woPackagingBoxSubstrate.setMeasTimeFl1(extendArgFromCamline.getMeasTimeFl1());
// woPackagingBoxSubstrate.setMeasTimeFl2(extendArgFromCamline.getMeasTimeFl2());
// woPackagingBoxSubstrate.setPmppFl1(extendArgFromCamline.getPmppFl1());
// woPackagingBoxSubstrate.setPmppFl2(extendArgFromCamline.getPmppFl2());
// woPackagingBoxSubstrate.setTcellFl1(extendArgFromCamline.getTcellFl1());
// woPackagingBoxSubstrate.setTcellFl2(extendArgFromCamline.getTcellFl2());
// woPackagingBoxSubstrate.setTmonicellFl1(extendArgFromCamline.getTmonicellFl1());
// woPackagingBoxSubstrate.setTmonicellFl2(extendArgFromCamline.getTmonicellFl2());
// woPackagingBoxSubstrate.setUmppFl1(extendArgFromCamline.getUmppFl1());
// woPackagingBoxSubstrate.setUmppFl2(extendArgFromCamline.getUmppFl2());
// woPackagingBoxSubstrate.setUocFl1(extendArgFromCamline.getUocFl1());
// woPackagingBoxSubstrate.setUocFl1(extendArgFromCamline.getUocFl2());
//
// substrateServiceBiz.insert(woPackagingBoxSubstrate);
// logger.info("标签打印Event--- 基板ID: "+subId+", 录入数据库成功");
// logger.info("================= 现在开始执行 过程一 任务 ( MES 业务 ) ( 结束 ) ==================");
// //=============== MES 业务 结束 =================
//
// //. 当MES完成任务后把MesToPlc.SubArrivedFinish变量置为true告诉plc我操作完成了
// write(S7Client.S7_DDJ1,Step1Mes2PlcVar.SubArrivedFinish,true);
// logger.info("标签打印Event--- 基板ID: "+subId+", SubArrivedFinish置为true 成功");
// //. mes 监控 到PlcToMes.SubArrived==false就把MesToPlc.SubArrivedFinish置为false
// Integer subArrived2 = waitingForTarget(Step1Plc2MesVar.SubArrivedToMes, false);
// if(subArrived2 != 1){
// logger.info("标签打印Event--- 失败"+" --- "+"MES监听 Step1Plc2MesVar.SubArrivedToMes 是否 等于 1 失败");
// }else if (subArrived2 == 2) {
// throw new Exception("MES 监听值出现异常。");
// }
//
// write(S7Client.S7_DDJ1,Step1Mes2PlcVar.SubArrivedFinish,false);
// logger.info("标签打印Event--- 基板ID: "+subId+", SubArrivedFinish置为 false 成功");
// logger.info("================================== 现在开始执行 过程一 任务( 结束 ===================================");
// logger.info("");
// }catch (Throwable e){
// logger.info("标签打印Event--- 出现异常 : {}",e.getMessage(),e);
// }
// }
// },1,1, TimeUnit.SECONDS);
//
// kukaStep2.scheduleAtFixedRate(new Runnable() {
// @Override
// public void run() {
// try {
//
// logger.info("");
// logger.info("================================== 现在开始执行 过程二 任务( 开始 ===================================");
// //调度开始
// Integer shelfIsFull = waitingForTarget(Step2Plc2MesVar.ShelfIsFull, true);
// if(shelfIsFull != 1){
// logger.info("BOXID生成Event-------失败"+" --- "+"MES监听 Step2Plc2MesVar.ShelfIsFull 是否 等于 1 失败");
// }else if(shelfIsFull == 2){
// throw new Exception("MES 监听值出现异常。");
// }
//
// //. 从plc 中获取 subIdList lineNum
// String[] subIdList = (String[])read(S7Client.S7_DDJ1,Step2Plc2MesVar.SubIdList);
// Integer listSize = (Integer)read(S7Client.S7_DDJ1,Step2Plc2MesVar.PackageNumberSet)-1;
//
//
// //. MES 业务
// //=============== MES 业务 开始 =================
// //1.MES 生成BoxId
// if(subIdList.length<=0){
// logger.info("BOXID生成Event-------失败"+" --- "+"从plc里面获取到的基板列表 为空");
// throw new Exception("BOXID生成Event失败-------kuka机械手 取到了空箱");
// }
// if(listSize == null){
// logger.info("BOXID生成Event-------失败"+" --- "+"从plc里面获取到的listSize 为null");
// throw new Exception("BOXID生成Event失败-------listSize 为null");
// }
//
// //真实的基板ID 就是17位的plc读取过来有空格要把后面3位空格去掉就行了
// for(int i=0;i<subIdList.length;i++){
// subIdList[i] = removeKG(subIdList[i]);
// }
// logger.info("BOXID生成Event-------获取到基板列表:"+ Arrays.toString(subIdList)+",基板数量:"+listSize);
//
// WoPackagingBoxSubstrate bySubId = substrateServiceBiz.getBySubId(subIdList[0]);
// logger.info("BOXID生成Event-------依据subId"+subIdList[0]+"去qgs数据库 查询数据,数据内容:"+bySubId);
//
//
// //如果我们系统中找不到这块基板那么就去camline里面找
// if(bySubId == null){
// logger.info("BOXID生成Event-------数据库中 无subId"+ subIdList[0]+"现在从camline 系统获取这个基板相关信息");
// //todo
// CamlineSubIdDTO subIdByCamline = service.getSubIdByCamline(subIdList[0]);
// bySubId = new WoPackagingBoxSubstrate();
// bySubId.setPowerLevel(subIdByCamline.getPowerLevel());
// bySubId.setSapMaterial(subIdByCamline.getSapMaterial());
// bySubId.setLineBody(2);
// }
//
//
// //校验是否存在混档位情况
// String boxId = "";
// if(isMixLevel(subIdList,listSize)){
// //出现混档
// logger.info("BOXID生成Event-------subIdList :"+subIdList+"出现混档");
// boxId = getErrorBoxId(bySubId.getSapMaterial());
//
// }else {
// //正常情况
// logger.info("BOXID生成Event-------subIdList :"+subIdList+"没有出现混档");
// boxId = getBoxId(bySubId.getSapMaterial());
// }
// logger.info("BOXID生成Event-------subIdList :"+subIdList+"isMixLevel 校验结束");
//
// logger.info("BOXID生成Event-------mes 生成的boxId :"+ boxId);
// //2. 依次update 基板表把boxId 赋予这些基板
// for(int i=0;i<listSize;i++){
// substrateServiceBiz.updatePackagingBoxIdAndSlotByWoSubstrateId(boxId,(i+1),subIdList[i]);
// }
// //3.去camline数据库 查询此基板ID 对应的订单
// String orderNameBySubId = service.getOrderNameBySubId(subIdList[0]);
// //4. box信息录入到box表
// WoPackagingBox woPackagingBox = new WoPackagingBox();
// woPackagingBox.setBoxNo(boxId);
// woPackagingBox.setSubstrateQuantity(listSize);
// woPackagingBox.setPackagingTime(LocalDateTime.now());
// woPackagingBox.setPowerLevel(bySubId.getPowerLevel());
// woPackagingBox.setLineBody(bySubId.getLineBody());
// woPackagingBox.setSapMaterial(bySubId.getSapMaterial());
// woPackagingBox.setOrderNum(orderNameBySubId);
// //1-手动模式2-自动模式
// woPackagingBox.setModel(2);
// woPackagingBox.setCreateTime(LocalDateTime.now());
// woPackagingBox.setPackagingTime(LocalDateTime.now());
// boxServiceBiz.insert(woPackagingBox);
// logger.info("BOXID生成Event-------boxId :"+ boxId+"写入数据库成功");
// //=============== MES 业务 结束 =================
//
// //. 把生成的BoxId 告诉kuka
// write(S7Client.S7_DDJ1,Step2Mes2PlcVar.BoxId,boxId);
// logger.info("BOXID生成Event-------boxId :"+ boxId+"传给PLC 成功");
//
// //. 当MES完成任务后把MesToPlc.ShelfIsFullFinish变量置为true告诉plc我操作完成了
// write(S7Client.S7_DDJ1,Step2Mes2PlcVar.ShelfIsFullFinish,true);
// logger.info("BOXID生成Event-------boxId :"+ boxId+"ShelfIsFullFinish 置为true 成功");
// //. mes 监控 到PlcToMes.SubArrived==false就把MesToPlc.SubArrivedFinish置为false
// Integer subArrived2 = waitingForTarget(Step2Plc2MesVar.ShelfIsFull, false);
// if(subArrived2 != 1){
// logger.info("BOXID生成Event-------失败"+" --- "+"步骤1. MES监听 Step1Plc2MesVar.SubArrivedToMes 是否 等于 1 失败");
// }else if(subArrived2 == 2){
// throw new Exception("MES 监听值出现异常。");
// }
// write(S7Client.S7_DDJ1,Step2Mes2PlcVar.ShelfIsFullFinish,false);
// logger.info("BOXID生成Event-------boxId :"+ boxId+"ShelfIsFullFinish 置为false 成功,Event2 成功结束");
// logger.info("================================== 现在开始执行 过程二 任务( 结束 ===================================");
// logger.info("");
//
// }catch (Throwable e){
//// logger.info("BOXID生成Event------- 出现异常:" + e.toString());
// logger.info("BOXID生成Event--- 出现异常 : {}",e.getMessage(),e);
// }
// }
// },1,1, TimeUnit.SECONDS);
//
// kukaStep3.scheduleAtFixedRate(new Runnable() {
// @Override
// public void run() {
// try {
// logger.info("");
// logger.info("================================== 现在开始执行 过程三 任务( 开始 ===================================");
// //调度开始
// Integer shelfIsFull = waitingForTarget(Step3Plc2MesVar.ShelfIsFullArrived, true);
// if(shelfIsFull != 1){
// logger.info("装箱单打印Event------失败"+" --- "+"MES监听 Step3Plc2MesVar.ShelfIsFullArrived 是否 等于 1 失败");
// }else if(shelfIsFull == 2){
// throw new Exception("MES 监听值出现异常。");
// }
//
// //. 从plc 中获取 subIdList lineNum
// String boxId = (String)read(S7Client.S7_DDJ1,Step3Plc2MesVar.BoxId);
// Integer lineNum = (Integer) read(S7Client.S7_DDJ1,Step3Plc2MesVar.LineNum);
// if(boxId == null){
// logger.info("装箱单打印Event-------失败"+" --- "+"从plc里面获取到的boxId 为null");
// throw new Exception("装箱单打印Event-------boxId 为null");
// }
// logger.info("装箱单打印Event------到达站台的boxId :"+boxId);
//
// //. MES 业务
// //=============== MES 业务 开始 =================
// //1. box信息录入到box表
// boxServiceBiz.updateIsArrivedByBoxNo(1,boxId);
// logger.info("装箱单打印Event------boxId :"+boxId+"更新数据库成功");
// //=============== MES 业务 结束 =================
//
//
// //. 当MES完成任务后把MesToPlc.ShelfIsFullArrivedFinish变量置为true告诉plc我操作完成了
// write(S7Client.S7_DDJ1,Step3Mes2PlcVar.ShelfIsFullArrivedFinish,true);
// logger.info("装箱单打印Event------boxId :"+boxId+" ShelfIsFullArrivedFinish置为true 成功");
// //. mes 监控 到PlcToMes.SubArrived==false就把MesToPlc.SubArrivedFinish置为false
// Integer subArrived2 = waitingForTarget(Step3Plc2MesVar.ShelfIsFullArrived, false);
// if(subArrived2 != 1){
// logger.info("装箱单打印Event------失败"+" --- "+"步骤1. MES监听 Step3Plc2MesVar.ShelfIsFullArrived 是否 等于 1 失败");
// }else if(subArrived2 == 2){
// throw new Exception("MES 监听值出现异常。");
// }
// logger.info("装箱单打印Event------boxId :"+boxId+" 监听到subArrived=false 成功");
// write(S7Client.S7_DDJ1,Step3Mes2PlcVar.ShelfIsFullArrivedFinish,false);
// logger.info("装箱单打印Event------boxId :"+boxId+" Even3 成功");
//
// logger.info("================================== 现在开始执行 过程三 任务( 结束 ===================================");
// logger.info("");
// }catch (Throwable e){
//// e.printStackTrace();
//// logger.info("装箱单打印Event 出现异常------"+e.toString());
// logger.info("装箱单打印Event--- 出现异常 : {}",e.getMessage(),e);
// }
//
// }
// },1,1, TimeUnit.SECONDS);
//
// }
//
// /**
// *
// * arg:
// * Step1Plc2MesVar 参数类型
// * targetValue 目的值
// * return:
// * 2 s7 访问异常;
// * 1 成功;
// * */
// private Integer waitingForTarget(Step1Plc2MesVar var, Boolean targetValue) {
// Integer res = 0;
// while (true){
// try {
//
// Boolean now = (Boolean) read(S7Client.S7_DDJ1,var);
// //注意即使now为null 这里也不会抛出异常这里很容易产生 空轮询
// if(now == null){
// throw new Exception("");
// }
// if(targetValue.equals(now)){
// res = 1;
// break;
// }
// Thread.sleep(200);
// }catch (Throwable e){
// logger.info("S7 数据采集 异常. 监听 变量 "+var.getName()+" 为目标值:"+targetValue+"失败");
// res = 2;
// break;
// }
// }
// return res;
// }
// /**
// *
// * arg:
// * Step2Plc2MesVar 参数类型
// * targetValue 目的值
// * return:
// * 2 s7 访问异常;
// * 1 成功;
// * */
// private Integer waitingForTarget(Step2Plc2MesVar var, Boolean targetValue) {
// Integer res = 0;
// while (true){
// try {
// Boolean now = (Boolean) read(S7Client.S7_DDJ1,var);
// if(now == null){
// throw new Exception("");
// }
// if(targetValue.equals(now)){
// res = 1;
// break;
// }
// Thread.sleep(200);
// }catch (Throwable e){
// logger.info("S7 数据采集 异常. 监听 变量 "+var.getName()+" 为目标值:"+targetValue+"失败");
// res = 2;
// break;
// }
// }
// return res;
// }
// /**
// *
// * arg:
// * Step3Plc2MesVar 参数类型
// * targetValue 目的值
// * return:
// * 2 s7 访问异常;
// * 1 成功;
// * */
// private Integer waitingForTarget(Step3Plc2MesVar var, Boolean targetValue) {
// Integer res = 0;
// while (true){
// try {
// Boolean now = (Boolean) read(S7Client.S7_DDJ1,var);
// if(now == null){
// throw new Exception("");
// }
// if(targetValue.equals(now)){
// res = 1;
// break;
// }
// Thread.sleep(200);
// }catch (Throwable e){
// logger.info("S7 数据采集 异常. 监听 变量 "+var.getName()+" 为目标值:"+targetValue+"失败");
// res = 2;
// break;
// }
// }
// return res;
// }
//}

View File

@ -1,4 +1,4 @@
package com.cnbm.dispatch;
package com.cnbm.dispatch.line1;
import cn.hutool.core.date.DateUtil;
import com.cnbm.dispatch.enums.kuka.step1.Step1Mes2PlcVar;
@ -8,8 +8,6 @@ import com.cnbm.dispatch.enums.kuka.step2.Step2Plc2MesVar;
import com.cnbm.dispatch.enums.kuka.step3.Step3Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step3.Step3Plc2MesVar;
import com.cnbm.packing.dto.CamlineExtendArgDTO;
import com.cnbm.packing.dto.CamlineSubIdDTO;
import com.cnbm.packing.entity.WoPackagingBox;
import com.cnbm.packing.entity.WoPackagingBoxSubstrate;
import com.cnbm.packing.entity.WoPowerLevel;
import com.cnbm.packing.service.*;
@ -26,7 +24,6 @@ import org.springframework.stereotype.Component;
import java.text.DecimalFormat;
import java.text.Format;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@ -39,8 +36,8 @@ import java.util.concurrent.TimeUnit;
*/
@Component
@Order(value = 1)
public class KukaEvent1Thread implements ApplicationRunner {
private static final Logger logger = LoggerFactory.getLogger("EVENT1");
public class KukaEvent1ThreadLine1 implements ApplicationRunner {
private static final Logger logger = LoggerFactory.getLogger("EVENT1Line1");
@Autowired
DynamicDataSourceService service;
@ -56,7 +53,7 @@ public class KukaEvent1Thread implements ApplicationRunner {
@Autowired
WoPackagingBoxServiceBiz boxServiceBiz;
public KukaEvent1Thread(){
public KukaEvent1ThreadLine1(){
this.kukaStep1 = Executors.newScheduledThreadPool(1);
}
@ -210,9 +207,9 @@ public class KukaEvent1Thread implements ApplicationRunner {
try {
//调度开始
Integer subArrived = waitingForTarget(Step1Plc2MesVar.SubArrivedToMes, true);
logger.info("");
logger.info("================================== 现在开始执行 过程一 任务( 开始 ===================================");
Integer subArrived = waitingForTarget(Step1Plc2MesVar.SubArrivedToMes, true);
if(subArrived != 1){
logger.info("标签打印Event--- 失败"+" --- "+" MES监听 Step1Plc2MesVar.SubArrivedToMes 是否 等于 1 失败");
} else if (subArrived == 2) {
@ -298,6 +295,7 @@ public class KukaEvent1Thread implements ApplicationRunner {
woPackagingBoxSubstrate.setUocFl1(extendArgFromCamline.getUocFl2());
substrateServiceBiz.insert(woPackagingBoxSubstrate);
logger.info("标签打印Event--- 基板ID: "+subId+", 录入数据库成功");
logger.info("================= 现在开始执行 过程一 任务 ( MES 业务 ) ( 结束 ) ==================");
//=============== MES 业务 结束 =================

View File

@ -0,0 +1,423 @@
package com.cnbm.dispatch.line1;
import cn.hutool.core.date.DateUtil;
import com.cnbm.dispatch.enums.kuka.step1.Step1Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step1.Step1Plc2MesVar;
import com.cnbm.dispatch.enums.kuka.step2.Step2Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step2.Step2Plc2MesVar;
import com.cnbm.dispatch.enums.kuka.step3.Step3Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step3.Step3Plc2MesVar;
import com.cnbm.packing.dto.CamlineSubIdDTO;
import com.cnbm.packing.entity.WoPackagingBox;
import com.cnbm.packing.entity.WoPackagingBoxSubstrate;
import com.cnbm.packing.service.*;
import com.cnbm.s7.s7connector.enmuc.S7Client;
import com.cnbm.s7.s7connector.type.PlcVar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.text.DecimalFormat;
import java.text.Format;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/12/23 12:33
*/
@Component
@Order(value = 1)
public class KukaEvent2ThreadLine1 implements ApplicationRunner {
private static final Logger logger = LoggerFactory.getLogger("EVENT2Line1");
@Autowired
DynamicDataSourceService service;
@Autowired
WoPowerLevelServiceBiz levelServiceBiz;
@Autowired
WoCompensationPowerServiceBiz compensationPowerServiceBiz;
@Autowired
WoPackagingBoxSubstrateServiceBiz substrateServiceBiz;
@Autowired
WoPackagingBoxServiceBiz boxServiceBiz;
public KukaEvent2ThreadLine1(){
this.kukaStep2 = Executors.newScheduledThreadPool(1);
}
private ScheduledExecutorService kukaStep2;
/**
* return
* 成功 返回相应的object对象
* 失败 返回null
* */
private Object read(S7Client s7Client,Step1Plc2MesVar var) {
try {
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
}catch (Throwable e){
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
return null;
}
}
private void write(S7Client s7Client, Step1Mes2PlcVar var, Object newValue) {
if(var.getType().equals(PlcVar.STRING_Array)){
String[] s = (String[])newValue;
String[] ss = (String[])newValue;
if(s.length > var.getLength() ){
ss = new String[var.getLength()];
for(int i=0;i< var.getLength();i++){
ss[i] = s[i];
}
}
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
}else {
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
}
}
private Object read(S7Client s7Client, Step2Plc2MesVar var) {
try {
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
}catch (Throwable e){
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
return null;
}
}
private void write(S7Client s7Client, Step2Mes2PlcVar var, Object newValue) {
if(var.getType().equals(PlcVar.STRING_Array)){
String[] s = (String[])newValue;
String[] ss = (String[])newValue;
if(s.length > var.getLength() ){
ss = new String[var.getLength()];
for(int i=0;i< var.getLength();i++){
ss[i] = s[i];
}
}
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
}else {
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
}
}
private Object read(S7Client s7Client, Step3Plc2MesVar var) {
try {
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
}catch (Throwable e){
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
return null;
}
}
private void write(S7Client s7Client, Step3Mes2PlcVar var, Object newValue) {
if(var.getType().equals(PlcVar.STRING_Array)){
String[] s = (String[])newValue;
String[] ss = (String[])newValue;
if(s.length > var.getLength() ){
ss = new String[var.getLength()];
for(int i=0;i< var.getLength();i++){
ss[i] = s[i];
}
}
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
}else {
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
}
}
public String getBoxId(String sapMaterial){
Integer todayBoxNum = service.getTodayBoxNum()+1;
String nowTime = DateUtil.format(new Date(), "yyMMdd");
todayBoxNum+=500;
logger.info("BOXID生成Event-------现在生成boxId sapMaterial: "+sapMaterial+"nowTime:"+nowTime+"todayBoxNum:"+formateString(todayBoxNum));
String res = "301"+sapMaterial+nowTime+formateString(todayBoxNum);
return res;
}
public String getErrorBoxId(String sapMaterial){
String nowTime = DateUtil.format(new Date(), "yyMMdd");
String mixBoxError = "001";
String res = "444"+sapMaterial+nowTime+mixBoxError;
logger.info("BOXID生成Event-------现在生成errBoxId sapMaterial: "+sapMaterial+"nowTime:"+nowTime);
return res;
}
public String removeKG(String str){
return str.substring(0,17);
}
public static void main(String[] args) {
Integer a = 102;
Format f1 = new DecimalFormat("000");
System.out.println(f1.format(a));
}
public String formateString(Integer a){
Format f1 = new DecimalFormat("000");
return f1.format(a);
}
//return true 出现混档了return false 没有出现混档
private boolean isMixLevel(String[] subIds,Integer size){
String correctLevel = substrateServiceBiz.getBySubId(subIds[0]).getPowerLevel();
String errMsg = "以下基板ID出现混档";
boolean res = false;
for(int i=0;i<size;i++){
String powerLevel = substrateServiceBiz.getBySubId(subIds[i]).getPowerLevel();
if(!powerLevel.equals(correctLevel)){
errMsg += "基板ID:"+subIds[i]+" 档位:"+powerLevel+", ";
res = true;
}
}
if(res){
logger.error(errMsg);
}
return res;
}
@Override
public void run(ApplicationArguments args) throws Exception {
kukaStep2.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
//调度开始
Integer shelfIsFull = waitingForTarget(Step2Plc2MesVar.ShelfIsFull, true);
logger.info("");
logger.info("================================== 现在开始执行 过程二 任务( 开始 ===================================");
if(shelfIsFull != 1){
logger.info("BOXID生成Event-------失败"+" --- "+"MES监听 Step2Plc2MesVar.ShelfIsFull 是否 等于 1 失败");
}else if(shelfIsFull == 2){
throw new Exception("MES 监听值出现异常。");
}
//. 从plc 中获取 subIdList lineNum
String[] subIdList = (String[])read(S7Client.S7_DDJ1,Step2Plc2MesVar.SubIdList);
Integer listSize = (Integer)read(S7Client.S7_DDJ1,Step2Plc2MesVar.PackageNumberSet)-1;
//. MES 业务
//=============== MES 业务 开始 =================
//1.MES 生成BoxId
if(subIdList.length<=0){
logger.info("BOXID生成Event-------失败"+" --- "+"从plc里面获取到的基板列表 为空");
throw new Exception("BOXID生成Event失败-------kuka机械手 取到了空箱");
}
if(listSize == null){
logger.info("BOXID生成Event-------失败"+" --- "+"从plc里面获取到的listSize 为null");
throw new Exception("BOXID生成Event失败-------listSize 为null");
}
//真实的基板ID 就是17位的plc读取过来有空格要把后面3位空格去掉就行了
for(int i=0;i<subIdList.length;i++){
subIdList[i] = removeKG(subIdList[i]);
}
logger.info("BOXID生成Event-------获取到基板列表:"+ Arrays.toString(subIdList)+",基板数量:"+listSize);
WoPackagingBoxSubstrate bySubId = substrateServiceBiz.getBySubId(subIdList[0]);
logger.info("BOXID生成Event-------依据subId"+subIdList[0]+"去qgs数据库 查询数据,数据内容:"+bySubId);
//如果我们系统中找不到这块基板那么就去camline里面找
if(bySubId == null){
logger.info("BOXID生成Event-------数据库中 无subId"+ subIdList[0]+"现在从camline 系统获取这个基板相关信息");
//todo
CamlineSubIdDTO subIdByCamline = service.getSubIdByCamline(subIdList[0]);
bySubId = new WoPackagingBoxSubstrate();
bySubId.setPowerLevel(subIdByCamline.getPowerLevel());
bySubId.setSapMaterial(subIdByCamline.getSapMaterial());
bySubId.setLineBody(1);
}
//校验是否存在混档位情况
String boxId = "";
if(isMixLevel(subIdList,listSize)){
//出现混档
logger.info("BOXID生成Event-------subIdList :"+subIdList+"出现混档");
boxId = getErrorBoxId(bySubId.getSapMaterial());
}else {
//正常情况
logger.info("BOXID生成Event-------subIdList :"+subIdList+"没有出现混档");
boxId = getBoxId(bySubId.getSapMaterial());
}
logger.info("BOXID生成Event-------subIdList :"+subIdList+"isMixLevel 校验结束");
logger.info("BOXID生成Event-------mes 生成的boxId :"+ boxId);
//2. 依次update 基板表把boxId 赋予这些基板
for(int i=0;i<listSize;i++){
substrateServiceBiz.updatePackagingBoxIdAndSlotByWoSubstrateId(boxId,(i+1),subIdList[i]);
}
//3.去camline数据库 查询此基板ID 对应的订单
String orderNameBySubId = service.getOrderNameBySubId(subIdList[0]);
//4. box信息录入到box表
WoPackagingBox woPackagingBox = new WoPackagingBox();
woPackagingBox.setBoxNo(boxId);
woPackagingBox.setSubstrateQuantity(listSize);
woPackagingBox.setPackagingTime(LocalDateTime.now());
woPackagingBox.setPowerLevel(bySubId.getPowerLevel());
woPackagingBox.setLineBody(bySubId.getLineBody());
woPackagingBox.setSapMaterial(bySubId.getSapMaterial());
woPackagingBox.setOrderNum(orderNameBySubId);
//1-手动模式2-自动模式
woPackagingBox.setModel(2);
woPackagingBox.setCreateTime(LocalDateTime.now());
woPackagingBox.setPackagingTime(LocalDateTime.now());
boxServiceBiz.insert(woPackagingBox);
logger.info("BOXID生成Event-------boxId :"+ boxId+"写入数据库成功");
//=============== MES 业务 结束 =================
//. 把生成的BoxId 告诉kuka
write(S7Client.S7_DDJ1,Step2Mes2PlcVar.BoxId,boxId);
logger.info("BOXID生成Event-------boxId :"+ boxId+"传给PLC 成功");
//. 当MES完成任务后把MesToPlc.ShelfIsFullFinish变量置为true告诉plc我操作完成了
write(S7Client.S7_DDJ1,Step2Mes2PlcVar.ShelfIsFullFinish,true);
logger.info("BOXID生成Event-------boxId :"+ boxId+"ShelfIsFullFinish 置为true 成功");
//. mes 监控 到PlcToMes.SubArrived==false就把MesToPlc.SubArrivedFinish置为false
Integer subArrived2 = waitingForTarget(Step2Plc2MesVar.ShelfIsFull, false);
if(subArrived2 != 1){
logger.info("BOXID生成Event-------失败"+" --- "+"步骤1. MES监听 Step1Plc2MesVar.SubArrivedToMes 是否 等于 1 失败");
}else if(subArrived2 == 2){
throw new Exception("MES 监听值出现异常。");
}
write(S7Client.S7_DDJ1,Step2Mes2PlcVar.ShelfIsFullFinish,false);
logger.info("BOXID生成Event-------boxId :"+ boxId+"ShelfIsFullFinish 置为false 成功,Event2 成功结束");
logger.info("================================== 现在开始执行 过程二 任务( 结束 ===================================");
logger.info("");
}catch (Throwable e){
// logger.info("BOXID生成Event------- 出现异常:" + e.toString());
logger.info("BOXID生成Event--- 出现异常 : {}",e.getMessage(),e);
}
}
},1,1, TimeUnit.SECONDS);
}
/**
*
* arg:
* Step1Plc2MesVar 参数类型
* targetValue 目的值
* return:
* 2 s7 访问异常;
* 1 成功;
* */
private Integer waitingForTarget(Step1Plc2MesVar var, Boolean targetValue) {
Integer res = 0;
while (true){
try {
Boolean now = (Boolean) read(S7Client.S7_DDJ1,var);
//注意即使now为null 这里也不会抛出异常这里很容易产生 空轮询
if(now == null){
throw new Exception("");
}
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Throwable e){
logger.info("S7 数据采集 异常. 监听 变量 "+var.getName()+" 为目标值:"+targetValue+"失败");
res = 2;
break;
}
}
return res;
}
/**
*
* arg:
* Step2Plc2MesVar 参数类型
* targetValue 目的值
* return:
* 2 s7 访问异常;
* 1 成功;
* */
private Integer waitingForTarget(Step2Plc2MesVar var, Boolean targetValue) {
Integer res = 0;
while (true){
try {
Boolean now = (Boolean) read(S7Client.S7_DDJ1,var);
if(now == null){
throw new Exception("");
}
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Throwable e){
logger.info("S7 数据采集 异常. 监听 变量 "+var.getName()+" 为目标值:"+targetValue+"失败");
res = 2;
break;
}
}
return res;
}
/**
*
* arg:
* Step3Plc2MesVar 参数类型
* targetValue 目的值
* return:
* 2 s7 访问异常;
* 1 成功;
* */
private Integer waitingForTarget(Step3Plc2MesVar var, Boolean targetValue) {
Integer res = 0;
while (true){
try {
Boolean now = (Boolean) read(S7Client.S7_DDJ1,var);
if(now == null){
throw new Exception("");
}
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Throwable e){
logger.info("S7 数据采集 异常. 监听 变量 "+var.getName()+" 为目标值:"+targetValue+"失败");
res = 2;
break;
}
}
return res;
}
}

View File

@ -1,4 +1,4 @@
package com.cnbm.dispatch;
package com.cnbm.dispatch.line1;
import cn.hutool.core.date.DateUtil;
import com.cnbm.dispatch.enums.kuka.step1.Step1Mes2PlcVar;
@ -7,11 +7,6 @@ import com.cnbm.dispatch.enums.kuka.step2.Step2Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step2.Step2Plc2MesVar;
import com.cnbm.dispatch.enums.kuka.step3.Step3Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step3.Step3Plc2MesVar;
import com.cnbm.packing.dto.CamlineExtendArgDTO;
import com.cnbm.packing.dto.CamlineSubIdDTO;
import com.cnbm.packing.entity.WoPackagingBox;
import com.cnbm.packing.entity.WoPackagingBoxSubstrate;
import com.cnbm.packing.entity.WoPowerLevel;
import com.cnbm.packing.service.*;
import com.cnbm.s7.s7connector.enmuc.S7Client;
import com.cnbm.s7.s7connector.type.PlcVar;
@ -25,8 +20,6 @@ import org.springframework.stereotype.Component;
import java.text.DecimalFormat;
import java.text.Format;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@ -39,9 +32,9 @@ import java.util.concurrent.TimeUnit;
*/
@Component
@Order(value = 1)
public class KukaEvent3Thread implements ApplicationRunner {
public class KukaEvent3ThreadLine1 implements ApplicationRunner {
private static final Logger logger = LoggerFactory.getLogger("EVENT3");
private static final Logger logger = LoggerFactory.getLogger("EVENT3Line1");
@Autowired
DynamicDataSourceService service;
@ -57,7 +50,7 @@ public class KukaEvent3Thread implements ApplicationRunner {
@Autowired
WoPackagingBoxServiceBiz boxServiceBiz;
public KukaEvent3Thread(){
public KukaEvent3ThreadLine1(){
this.kukaStep3 = Executors.newScheduledThreadPool(1);
}
@ -211,10 +204,11 @@ public class KukaEvent3Thread implements ApplicationRunner {
@Override
public void run() {
try {
logger.info("");
logger.info("================================== 现在开始执行 过程三 任务( 开始 ===================================");
//调度开始
Integer shelfIsFull = waitingForTarget(Step3Plc2MesVar.ShelfIsFullArrived, true);
logger.info("");
logger.info("================================== 现在开始执行 过程三 任务( 开始 ===================================");
if(shelfIsFull != 1){
logger.info("装箱单打印Event------失败"+" --- "+"MES监听 Step3Plc2MesVar.ShelfIsFullArrived 是否 等于 1 失败");
}else if(shelfIsFull == 2){

View File

@ -0,0 +1,418 @@
package com.cnbm.dispatch.line2;
import cn.hutool.core.date.DateUtil;
import com.cnbm.dispatch.enums.kuka.step1.Step1Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step1.Step1Plc2MesVar;
import com.cnbm.dispatch.enums.kuka.step2.Step2Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step2.Step2Plc2MesVar;
import com.cnbm.dispatch.enums.kuka.step3.Step3Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step3.Step3Plc2MesVar;
import com.cnbm.packing.dto.CamlineExtendArgDTO;
import com.cnbm.packing.entity.WoPackagingBoxSubstrate;
import com.cnbm.packing.entity.WoPowerLevel;
import com.cnbm.packing.service.*;
import com.cnbm.s7.s7connector.enmuc.S7Client;
import com.cnbm.s7.s7connector.type.PlcVar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.text.DecimalFormat;
import java.text.Format;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/12/23 12:33
*/
@Component
@Order(value = 1)
public class KukaEvent1ThreadLine2 implements ApplicationRunner {
private static final Logger logger = LoggerFactory.getLogger("EVENT1Line2");
@Autowired
DynamicDataSourceService service;
@Autowired
WoPowerLevelServiceBiz levelServiceBiz;
@Autowired
WoCompensationPowerServiceBiz compensationPowerServiceBiz;
@Autowired
WoPackagingBoxSubstrateServiceBiz substrateServiceBiz;
@Autowired
WoPackagingBoxServiceBiz boxServiceBiz;
public KukaEvent1ThreadLine2(){
this.kukaStep1 = Executors.newScheduledThreadPool(1);
}
private ScheduledExecutorService kukaStep1;
/**
* return
* 成功 返回相应的object对象
* 失败 返回null
* */
private Object read(S7Client s7Client,Step1Plc2MesVar var) {
try {
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
}catch (Throwable e){
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
return null;
}
}
private void write(S7Client s7Client, Step1Mes2PlcVar var, Object newValue) {
if(var.getType().equals(PlcVar.STRING_Array)){
String[] s = (String[])newValue;
String[] ss = (String[])newValue;
if(s.length > var.getLength() ){
ss = new String[var.getLength()];
for(int i=0;i< var.getLength();i++){
ss[i] = s[i];
}
}
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
}else {
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
}
}
private Object read(S7Client s7Client, Step2Plc2MesVar var) {
try {
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
}catch (Throwable e){
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
return null;
}
}
private void write(S7Client s7Client, Step2Mes2PlcVar var, Object newValue) {
if(var.getType().equals(PlcVar.STRING_Array)){
String[] s = (String[])newValue;
String[] ss = (String[])newValue;
if(s.length > var.getLength() ){
ss = new String[var.getLength()];
for(int i=0;i< var.getLength();i++){
ss[i] = s[i];
}
}
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
}else {
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
}
}
private Object read(S7Client s7Client, Step3Plc2MesVar var) {
try {
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
}catch (Throwable e){
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
return null;
}
}
private void write(S7Client s7Client, Step3Mes2PlcVar var, Object newValue) {
if(var.getType().equals(PlcVar.STRING_Array)){
String[] s = (String[])newValue;
String[] ss = (String[])newValue;
if(s.length > var.getLength() ){
ss = new String[var.getLength()];
for(int i=0;i< var.getLength();i++){
ss[i] = s[i];
}
}
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
}else {
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
}
}
public String getBoxId(String sapMaterial){
Integer todayBoxNum = service.getTodayBoxNum()+1;
String nowTime = DateUtil.format(new Date(), "yyMMdd");
todayBoxNum+=500;
logger.info("BOXID生成Event-------现在生成boxId sapMaterial: "+sapMaterial+"nowTime:"+nowTime+"todayBoxNum:"+formateString(todayBoxNum));
String res = "301"+sapMaterial+nowTime+formateString(todayBoxNum);
return res;
}
public String getErrorBoxId(String sapMaterial){
String nowTime = DateUtil.format(new Date(), "yyMMdd");
String mixBoxError = "001";
String res = "444"+sapMaterial+nowTime+mixBoxError;
logger.info("BOXID生成Event-------现在生成errBoxId sapMaterial: "+sapMaterial+"nowTime:"+nowTime);
return res;
}
public String removeKG(String str){
return str.substring(0,17);
}
public static void main(String[] args) {
Integer a = 102;
Format f1 = new DecimalFormat("000");
System.out.println(f1.format(a));
}
public String formateString(Integer a){
Format f1 = new DecimalFormat("000");
return f1.format(a);
}
//return true 出现混档了return false 没有出现混档
private boolean isMixLevel(String[] subIds,Integer size){
String correctLevel = substrateServiceBiz.getBySubId(subIds[0]).getPowerLevel();
String errMsg = "以下基板ID出现混档";
boolean res = false;
for(int i=0;i<size;i++){
String powerLevel = substrateServiceBiz.getBySubId(subIds[i]).getPowerLevel();
if(!powerLevel.equals(correctLevel)){
errMsg += "基板ID:"+subIds[i]+" 档位:"+powerLevel+", ";
res = true;
}
}
if(res){
logger.error(errMsg);
}
return res;
}
@Override
public void run(ApplicationArguments args) throws Exception {
kukaStep1.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
//调度开始
Integer subArrived = waitingForTarget(Step1Plc2MesVar.SubArrivedToMes, true);
logger.info("");
logger.info("================================== 现在开始执行 过程一 任务( 开始 ===================================");
if(subArrived != 1){
logger.info("标签打印Event--- 失败"+" --- "+" MES监听 Step1Plc2MesVar.SubArrivedToMes 是否 等于 1 失败");
} else if (subArrived == 2) {
throw new Exception("MES 监听值出现异常。");
}
logger.info("标签打印Event --- 成功 ---- MES监听到 SubArrivedToMes==true");
//. 从plc 中获取 subId lineNum
String subId = (String) read(S7Client.S7_DDJ2,Step1Plc2MesVar.SubIdToMes);
Integer lineNum = (Integer) read(S7Client.S7_DDJ2,Step1Plc2MesVar.LineNum);
//把基板ID字符串的空格去掉因为plc中设置的20位但实际基板ID就是17位因为带空格去数据库查询 有问题的
if(subId == null || lineNum == null){
logger.info("标签打印Event--- 失败"+" --- "+" MES采集到null值subId:"+subId+",lineNum:"+lineNum);
}
subId = removeKG(subId);
logger.info("标签打印Event --- 成功 ---- MES 从plu中 read 到基板id:"+subId);
//. MES 业务
//=============== MES 业务 开始 =================
logger.info("================= 现在开始执行 过程一 任务 ( MES 业务 ) ( 开始 ) ==================");
//1. 从comline数据库中获取 实际pmpp
float pmppActual = service.getPMPPBySubId(subId);
//2. 匹配和计算补偿功率
float pmppCompensation = compensationPowerServiceBiz.calculCompensationPMPP(pmppActual,lineNum);
//3. 依据补偿功率获取工艺参数并且把这些工艺参数传给kuka
WoPowerLevel argByPMPP = levelServiceBiz.getArgByPMPP(pmppCompensation, lineNum);
write(S7Client.S7_DDJ2,Step1Mes2PlcVar.dLable_Pnom,Integer.valueOf(argByPMPP.getPowerClass()));
write(S7Client.S7_DDJ2,Step1Mes2PlcVar.dLable_Voc,argByPMPP.getLableVoc());
write(S7Client.S7_DDJ2,Step1Mes2PlcVar.dLable_Isc,argByPMPP.getLableIsc());
write(S7Client.S7_DDJ2,Step1Mes2PlcVar.dLable_Vmpp,argByPMPP.getLableVmpp());
write(S7Client.S7_DDJ2,Step1Mes2PlcVar.dLable_Impp,argByPMPP.getLableImpp());
logger.info("标签打印Event--- 采集到 基板ID: "+subId+", 线边号:"+lineNum+"从camline 获取到实际pmpp"+pmppActual+",计算后 补偿功率:"+pmppCompensation+",dLable_Pnom: "+argByPMPP.getPowerClass() +",dLable_Voc: "+argByPMPP.getLableVoc()+",dLable_Isc: "+argByPMPP.getLableIsc()+",dLable_Vmpp: "+argByPMPP.getLableVmpp()+",dLable_Impp: "+argByPMPP.getLableImpp());
//4. 把基板录到数据库
WoPackagingBoxSubstrate woPackagingBoxSubstrate = new WoPackagingBoxSubstrate();
woPackagingBoxSubstrate.setLineBody(lineNum);
woPackagingBoxSubstrate.setPowerLevel(argByPMPP.getPowerClass());
woPackagingBoxSubstrate.setSapMaterial(argByPMPP.getSapMaterialNum());
woPackagingBoxSubstrate.setWoSubstrateId(subId);
woPackagingBoxSubstrate.setActualPmpp(pmppActual);
woPackagingBoxSubstrate.setCreateTime(LocalDateTime.now());
//计算后的补偿功率
woPackagingBoxSubstrate.setPmpp(pmppCompensation);
//5. 从camline那里获取可变字段
CamlineExtendArgDTO extendArgFromCamline = service.getExtendArgFromCamline(subId);
logger.info("标签打印Event--- 基板ID: "+subId+", 从camline获取PID16~PID22 的实测数据 成功, 数据内容:"+extendArgFromCamline.toString());
woPackagingBoxSubstrate.setLastUpdateTime(extendArgFromCamline.getLastUpdateTime());
woPackagingBoxSubstrate.setOrderName(extendArgFromCamline.getOrderName());
woPackagingBoxSubstrate.setBinclassFl1(extendArgFromCamline.getBinclassFl1());
woPackagingBoxSubstrate.setBinclassFl2(extendArgFromCamline.getBinclassFl2());
woPackagingBoxSubstrate.setEtaFl1(extendArgFromCamline.getEtaFl1());
woPackagingBoxSubstrate.setEtaFl2(extendArgFromCamline.getEtaFl2());
woPackagingBoxSubstrate.setFfFl1(extendArgFromCamline.getFfFl1());
woPackagingBoxSubstrate.setFfFl2(extendArgFromCamline.getFfFl2());
woPackagingBoxSubstrate.setImppFl1(extendArgFromCamline.getImppFl1());
woPackagingBoxSubstrate.setImppFl2(extendArgFromCamline.getImppFl2());
woPackagingBoxSubstrate.setInsolflashcontrolFl1(extendArgFromCamline.getInsolflashcontrolFl1());
woPackagingBoxSubstrate.setInsolflashcontrolFl2(extendArgFromCamline.getInsolflashcontrolFl2());
woPackagingBoxSubstrate.setInsolmppFl1(extendArgFromCamline.getInsolmppFl1());
woPackagingBoxSubstrate.setInsolmppFl2(extendArgFromCamline.getInsolmppFl2());
woPackagingBoxSubstrate.setInsolvocFl1(extendArgFromCamline.getInsolvocFl1());
woPackagingBoxSubstrate.setInsolvocFl2(extendArgFromCamline.getInsolvocFl2());
woPackagingBoxSubstrate.setInsolFl1(extendArgFromCamline.getInsolFl1());
woPackagingBoxSubstrate.setInsolFl2(extendArgFromCamline.getInsolFl2());
woPackagingBoxSubstrate.setIscFl1(extendArgFromCamline.getIscFl1());
woPackagingBoxSubstrate.setIscFl2(extendArgFromCamline.getIscFl2());
woPackagingBoxSubstrate.setMeasTimeFl1(extendArgFromCamline.getMeasTimeFl1());
woPackagingBoxSubstrate.setMeasTimeFl2(extendArgFromCamline.getMeasTimeFl2 ());
woPackagingBoxSubstrate.setPmppFl1(extendArgFromCamline.getPmppFl1());
woPackagingBoxSubstrate.setPmppFl2(extendArgFromCamline.getPmppFl2());
woPackagingBoxSubstrate.setTcellFl1(extendArgFromCamline.getTcellFl1());
woPackagingBoxSubstrate.setTcellFl2(extendArgFromCamline.getTcellFl2());
woPackagingBoxSubstrate.setTmonicellFl1(extendArgFromCamline.getTmonicellFl1());
woPackagingBoxSubstrate.setTmonicellFl2(extendArgFromCamline.getTmonicellFl2());
woPackagingBoxSubstrate.setUmppFl1(extendArgFromCamline.getUmppFl1());
woPackagingBoxSubstrate.setUmppFl2(extendArgFromCamline.getUmppFl2());
woPackagingBoxSubstrate.setUocFl1(extendArgFromCamline.getUocFl1());
woPackagingBoxSubstrate.setUocFl1(extendArgFromCamline.getUocFl2());
substrateServiceBiz.insert(woPackagingBoxSubstrate);
logger.info("标签打印Event--- 基板ID: "+subId+", 录入数据库成功");
logger.info("================= 现在开始执行 过程一 任务 ( MES 业务 ) ( 结束 ) ==================");
//=============== MES 业务 结束 =================
//. 当MES完成任务后把MesToPlc.SubArrivedFinish变量置为true告诉plc我操作完成了
write(S7Client.S7_DDJ2,Step1Mes2PlcVar.SubArrivedFinish,true);
logger.info("标签打印Event--- 基板ID: "+subId+", SubArrivedFinish置为true 成功");
//. mes 监控 到PlcToMes.SubArrived==false就把MesToPlc.SubArrivedFinish置为false
Integer subArrived2 = waitingForTarget(Step1Plc2MesVar.SubArrivedToMes, false);
if(subArrived2 != 1){
logger.info("标签打印Event--- 失败"+" --- "+"MES监听 Step1Plc2MesVar.SubArrivedToMes 是否 等于 1 失败");
}else if (subArrived2 == 2) {
throw new Exception("MES 监听值出现异常。");
}
write(S7Client.S7_DDJ2,Step1Mes2PlcVar.SubArrivedFinish,false);
logger.info("标签打印Event--- 基板ID: "+subId+", SubArrivedFinish置为 false 成功");
logger.info("================================== 现在开始执行 过程一 任务( 结束 ===================================");
logger.info("");
}catch (Throwable e){
logger.info("标签打印Event--- 出现异常 : {}",e.getMessage(),e);
}
}
},1,1, TimeUnit.SECONDS);
}
/**
*
* arg:
* Step1Plc2MesVar 参数类型
* targetValue 目的值
* return:
* 2 s7 访问异常;
* 1 成功;
* */
private Integer waitingForTarget(Step1Plc2MesVar var, Boolean targetValue) {
Integer res = 0;
while (true){
try {
Boolean now = (Boolean) read(S7Client.S7_DDJ2,var);
//注意即使now为null 这里也不会抛出异常这里很容易产生 空轮询
if(now == null){
throw new Exception("");
}
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Throwable e){
logger.info("S7 数据采集 异常. 监听 变量 "+var.getName()+" 为目标值:"+targetValue+"失败");
res = 2;
break;
}
}
return res;
}
/**
*
* arg:
* Step2Plc2MesVar 参数类型
* targetValue 目的值
* return:
* 2 s7 访问异常;
* 1 成功;
* */
private Integer waitingForTarget(Step2Plc2MesVar var, Boolean targetValue) {
Integer res = 0;
while (true){
try {
Boolean now = (Boolean) read(S7Client.S7_DDJ2,var);
if(now == null){
throw new Exception("");
}
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Throwable e){
logger.info("S7 数据采集 异常. 监听 变量 "+var.getName()+" 为目标值:"+targetValue+"失败");
res = 2;
break;
}
}
return res;
}
/**
*
* arg:
* Step3Plc2MesVar 参数类型
* targetValue 目的值
* return:
* 2 s7 访问异常;
* 1 成功;
* */
private Integer waitingForTarget(Step3Plc2MesVar var, Boolean targetValue) {
Integer res = 0;
while (true){
try {
Boolean now = (Boolean) read(S7Client.S7_DDJ2,var);
if(now == null){
throw new Exception("");
}
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Throwable e){
logger.info("S7 数据采集 异常. 监听 变量 "+var.getName()+" 为目标值:"+targetValue+"失败");
res = 2;
break;
}
}
return res;
}
}

View File

@ -1,4 +1,4 @@
package com.cnbm.dispatch;
package com.cnbm.dispatch.line2;
import cn.hutool.core.date.DateUtil;
import com.cnbm.dispatch.enums.kuka.step1.Step1Mes2PlcVar;
@ -7,11 +7,9 @@ import com.cnbm.dispatch.enums.kuka.step2.Step2Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step2.Step2Plc2MesVar;
import com.cnbm.dispatch.enums.kuka.step3.Step3Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step3.Step3Plc2MesVar;
import com.cnbm.packing.dto.CamlineExtendArgDTO;
import com.cnbm.packing.dto.CamlineSubIdDTO;
import com.cnbm.packing.entity.WoPackagingBox;
import com.cnbm.packing.entity.WoPackagingBoxSubstrate;
import com.cnbm.packing.entity.WoPowerLevel;
import com.cnbm.packing.service.*;
import com.cnbm.s7.s7connector.enmuc.S7Client;
import com.cnbm.s7.s7connector.type.PlcVar;
@ -39,9 +37,9 @@ import java.util.concurrent.TimeUnit;
*/
@Component
@Order(value = 1)
public class KukaEvent2Thread implements ApplicationRunner {
public class KukaEvent2ThreadLine2 implements ApplicationRunner {
private static final Logger logger = LoggerFactory.getLogger("EVENT2");
private static final Logger logger = LoggerFactory.getLogger("EVENT2Line2");
@Autowired
@ -58,7 +56,7 @@ public class KukaEvent2Thread implements ApplicationRunner {
@Autowired
WoPackagingBoxServiceBiz boxServiceBiz;
public KukaEvent2Thread(){
public KukaEvent2ThreadLine2(){
this.kukaStep2 = Executors.newScheduledThreadPool(1);
@ -214,10 +212,11 @@ public class KukaEvent2Thread implements ApplicationRunner {
public void run() {
try {
logger.info("");
logger.info("================================== 现在开始执行 过程二 任务( 开始 ===================================");
//调度开始
Integer shelfIsFull = waitingForTarget(Step2Plc2MesVar.ShelfIsFull, true);
logger.info("");
logger.info("================================== 现在开始执行 过程二 任务( 开始 ===================================");
if(shelfIsFull != 1){
logger.info("BOXID生成Event-------失败"+" --- "+"MES监听 Step2Plc2MesVar.ShelfIsFull 是否 等于 1 失败");
}else if(shelfIsFull == 2){

View File

@ -0,0 +1,354 @@
package com.cnbm.dispatch.line2;
import cn.hutool.core.date.DateUtil;
import com.cnbm.dispatch.enums.kuka.step1.Step1Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step1.Step1Plc2MesVar;
import com.cnbm.dispatch.enums.kuka.step2.Step2Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step2.Step2Plc2MesVar;
import com.cnbm.dispatch.enums.kuka.step3.Step3Mes2PlcVar;
import com.cnbm.dispatch.enums.kuka.step3.Step3Plc2MesVar;
import com.cnbm.packing.service.*;
import com.cnbm.s7.s7connector.enmuc.S7Client;
import com.cnbm.s7.s7connector.type.PlcVar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.text.DecimalFormat;
import java.text.Format;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/12/23 12:33
*/
@Component
@Order(value = 1)
public class KukaEvent3ThreadLine2 implements ApplicationRunner {
private static final Logger logger = LoggerFactory.getLogger("EVENT3Line2");
@Autowired
DynamicDataSourceService service;
@Autowired
WoPowerLevelServiceBiz levelServiceBiz;
@Autowired
WoCompensationPowerServiceBiz compensationPowerServiceBiz;
@Autowired
WoPackagingBoxSubstrateServiceBiz substrateServiceBiz;
@Autowired
WoPackagingBoxServiceBiz boxServiceBiz;
public KukaEvent3ThreadLine2(){
this.kukaStep3 = Executors.newScheduledThreadPool(1);
}
private ScheduledExecutorService kukaStep3;
/**
* return
* 成功 返回相应的object对象
* 失败 返回null
* */
private Object read(S7Client s7Client,Step1Plc2MesVar var) {
try {
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
}catch (Throwable e){
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
return null;
}
}
private void write(S7Client s7Client, Step1Mes2PlcVar var, Object newValue) {
if(var.getType().equals(PlcVar.STRING_Array)){
String[] s = (String[])newValue;
String[] ss = (String[])newValue;
if(s.length > var.getLength() ){
ss = new String[var.getLength()];
for(int i=0;i< var.getLength();i++){
ss[i] = s[i];
}
}
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
}else {
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
}
}
private Object read(S7Client s7Client, Step2Plc2MesVar var) {
try {
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
}catch (Throwable e){
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
return null;
}
}
private void write(S7Client s7Client, Step2Mes2PlcVar var, Object newValue) {
if(var.getType().equals(PlcVar.STRING_Array)){
String[] s = (String[])newValue;
String[] ss = (String[])newValue;
if(s.length > var.getLength() ){
ss = new String[var.getLength()];
for(int i=0;i< var.getLength();i++){
ss[i] = s[i];
}
}
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
}else {
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
}
}
private Object read(S7Client s7Client, Step3Plc2MesVar var) {
try {
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
}catch (Throwable e){
logger.info("host:"+s7Client.getHost()+" ; read 操作出现问题: {}",e.getMessage(),e);
return null;
}
}
private void write(S7Client s7Client, Step3Mes2PlcVar var, Object newValue) {
if(var.getType().equals(PlcVar.STRING_Array)){
String[] s = (String[])newValue;
String[] ss = (String[])newValue;
if(s.length > var.getLength() ){
ss = new String[var.getLength()];
for(int i=0;i< var.getLength();i++){
ss[i] = s[i];
}
}
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
}else {
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
}
}
public String getBoxId(String sapMaterial){
Integer todayBoxNum = service.getTodayBoxNum()+1;
String nowTime = DateUtil.format(new Date(), "yyMMdd");
todayBoxNum+=500;
logger.info("BOXID生成Event-------现在生成boxId sapMaterial: "+sapMaterial+"nowTime:"+nowTime+"todayBoxNum:"+formateString(todayBoxNum));
String res = "301"+sapMaterial+nowTime+formateString(todayBoxNum);
return res;
}
public String getErrorBoxId(String sapMaterial){
String nowTime = DateUtil.format(new Date(), "yyMMdd");
String mixBoxError = "001";
String res = "444"+sapMaterial+nowTime+mixBoxError;
logger.info("BOXID生成Event-------现在生成errBoxId sapMaterial: "+sapMaterial+"nowTime:"+nowTime);
return res;
}
public String removeKG(String str){
return str.substring(0,17);
}
public static void main(String[] args) {
Integer a = 102;
Format f1 = new DecimalFormat("000");
System.out.println(f1.format(a));
}
public String formateString(Integer a){
Format f1 = new DecimalFormat("000");
return f1.format(a);
}
//return true 出现混档了return false 没有出现混档
private boolean isMixLevel(String[] subIds,Integer size){
String correctLevel = substrateServiceBiz.getBySubId(subIds[0]).getPowerLevel();
String errMsg = "以下基板ID出现混档";
boolean res = false;
for(int i=0;i<size;i++){
String powerLevel = substrateServiceBiz.getBySubId(subIds[i]).getPowerLevel();
if(!powerLevel.equals(correctLevel)){
errMsg += "基板ID:"+subIds[i]+" 档位:"+powerLevel+", ";
res = true;
}
}
if(res){
logger.error(errMsg);
}
return res;
}
@Override
public void run(ApplicationArguments args) throws Exception {
kukaStep3.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
//调度开始
Integer shelfIsFull = waitingForTarget(Step3Plc2MesVar.ShelfIsFullArrived, true);
logger.info("");
logger.info("================================== 现在开始执行 过程三 任务( 开始 ===================================");
if(shelfIsFull != 1){
logger.info("装箱单打印Event------失败"+" --- "+"MES监听 Step3Plc2MesVar.ShelfIsFullArrived 是否 等于 1 失败");
}else if(shelfIsFull == 2){
throw new Exception("MES 监听值出现异常。");
}
//. 从plc 中获取 subIdList lineNum
String boxId = (String)read(S7Client.S7_DDJ1,Step3Plc2MesVar.BoxId);
Integer lineNum = (Integer) read(S7Client.S7_DDJ1,Step3Plc2MesVar.LineNum);
if(boxId == null){
logger.info("装箱单打印Event-------失败"+" --- "+"从plc里面获取到的boxId 为null");
throw new Exception("装箱单打印Event-------boxId 为null");
}
logger.info("装箱单打印Event------到达站台的boxId :"+boxId);
//. MES 业务
//=============== MES 业务 开始 =================
//1. box信息录入到box表
boxServiceBiz.updateIsArrivedByBoxNo(1,boxId);
logger.info("装箱单打印Event------boxId :"+boxId+"更新数据库成功");
//=============== MES 业务 结束 =================
//. 当MES完成任务后把MesToPlc.ShelfIsFullArrivedFinish变量置为true告诉plc我操作完成了
write(S7Client.S7_DDJ1,Step3Mes2PlcVar.ShelfIsFullArrivedFinish,true);
logger.info("装箱单打印Event------boxId :"+boxId+" ShelfIsFullArrivedFinish置为true 成功");
//. mes 监控 到PlcToMes.SubArrived==false就把MesToPlc.SubArrivedFinish置为false
Integer subArrived2 = waitingForTarget(Step3Plc2MesVar.ShelfIsFullArrived, false);
if(subArrived2 != 1){
logger.info("装箱单打印Event------失败"+" --- "+"步骤1. MES监听 Step3Plc2MesVar.ShelfIsFullArrived 是否 等于 1 失败");
}else if(subArrived2 == 2){
throw new Exception("MES 监听值出现异常。");
}
logger.info("装箱单打印Event------boxId :"+boxId+" 监听到subArrived=false 成功");
write(S7Client.S7_DDJ1,Step3Mes2PlcVar.ShelfIsFullArrivedFinish,false);
logger.info("装箱单打印Event------boxId :"+boxId+" Even3 成功");
logger.info("================================== 现在开始执行 过程三 任务( 结束 ===================================");
logger.info("");
}catch (Throwable e){
// e.printStackTrace();
// logger.info("装箱单打印Event 出现异常------"+e.toString());
logger.info("装箱单打印Event--- 出现异常 : {}",e.getMessage(),e);
}
}
},1,1, TimeUnit.SECONDS);
}
/**
*
* arg:
* Step1Plc2MesVar 参数类型
* targetValue 目的值
* return:
* 2 s7 访问异常;
* 1 成功;
* */
private Integer waitingForTarget(Step1Plc2MesVar var, Boolean targetValue) {
Integer res = 0;
while (true){
try {
Boolean now = (Boolean) read(S7Client.S7_DDJ1,var);
//注意即使now为null 这里也不会抛出异常这里很容易产生 空轮询
if(now == null){
throw new Exception("");
}
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Throwable e){
logger.info("S7 数据采集 异常. 监听 变量 "+var.getName()+" 为目标值:"+targetValue+"失败");
res = 2;
break;
}
}
return res;
}
/**
*
* arg:
* Step2Plc2MesVar 参数类型
* targetValue 目的值
* return:
* 2 s7 访问异常;
* 1 成功;
* */
private Integer waitingForTarget(Step2Plc2MesVar var, Boolean targetValue) {
Integer res = 0;
while (true){
try {
Boolean now = (Boolean) read(S7Client.S7_DDJ1,var);
if(now == null){
throw new Exception("");
}
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Throwable e){
logger.info("S7 数据采集 异常. 监听 变量 "+var.getName()+" 为目标值:"+targetValue+"失败");
res = 2;
break;
}
}
return res;
}
/**
*
* arg:
* Step3Plc2MesVar 参数类型
* targetValue 目的值
* return:
* 2 s7 访问异常;
* 1 成功;
* */
private Integer waitingForTarget(Step3Plc2MesVar var, Boolean targetValue) {
Integer res = 0;
while (true){
try {
Boolean now = (Boolean) read(S7Client.S7_DDJ1,var);
if(now == null){
throw new Exception("");
}
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Throwable e){
logger.info("S7 数据采集 异常. 监听 变量 "+var.getName()+" 为目标值:"+targetValue+"失败");
res = 2;
break;
}
}
return res;
}
}

View File

@ -1,294 +0,0 @@
package com.cnbm.dispatchDDJ;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.cnbm.dispatchDDJ.constant.QGSConstant;
import com.cnbm.dispatchDDJ.entity.DDJInfoCallBack;
import com.cnbm.dispatchDDJ.entity.TaskDTO;
import com.cnbm.dispatchDDJ.enums.ddj.ddj1.DDJPlc2WcsVar;
import com.cnbm.dispatchDDJ.enums.ddj.ddj1.DDJWcs2PlcVar;
import com.cnbm.dispatchDDJ.interfaces.Listener;
import com.cnbm.dispatchDDJ.interfaces.RuntimeEQErrListener;
import com.cnbm.dispatchDDJ.taskPool.QGSThreadPool;
import com.cnbm.s7.s7connector.enmuc.S7Client;
import com.cnbm.s7.s7connector.type.PlcVar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
import java.util.function.BiConsumer;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/6/8 15:16
*/
public class DDJ1Task implements Listener {
private static final Logger logger = LoggerFactory.getLogger(DDJ1Task.class);
private TaskDTO taskDTO;
private S7Client s7Client;
public DDJ1Task(TaskDTO taskDTO, S7Client s7Client){
this.taskDTO = taskDTO;
this.s7Client = s7Client;
}
public DDJ1Task(){
}
public final Collection<RuntimeEQErrListener> linkTestRecvListeners = new CopyOnWriteArrayList<>();
@Override
public void addRuntimeEQErrListener(RuntimeEQErrListener lstnr) {
linkTestRecvListeners.add(lstnr);
}
public void executeLinktestRecvTask(Integer errCode) {
for (RuntimeEQErrListener listener : linkTestRecvListeners) {
listener.received(errCode);
}
}
// public void run() {
// CompletableFuture.supplyAsync(() -> {
// System.out.println("");
// System.out.println("开始执行 ddj1 调度任务 开始 "+ Thread.currentThread().hashCode());
// executeLinktestRecvTask(1);
//
// System.out.println("开始执行 ddj1 调度任务 结束"+ Thread.currentThread().hashCode());
// return 1;
// }, QGSThreadPool.ddj1ExecutorService).whenComplete((data, error) -> {
// System.out.println("data:" + data+ Thread.currentThread().hashCode());
// if (error != null) {
// System.out.println(error);
// }
// });
// }
/* *
*
* status
* 10 初始值
* -2 s7 数据采集失败
* 100 任务成功完成
* 101 任务被人为取消取消的原因看 content
* */
public void run(){
CompletableFuture.supplyAsync(() -> {
logger.info("");
logger.info("================= 现在开始执行 DDJ1 任务 : "+ taskDTO.toString()+" ==================");
//构建结果类
DDJInfoCallBack build = new DDJInfoCallBack();
build.setStatus(10);
build.setTaskId(taskDTO.getMissionID());
//调度逻辑 ------------------------------------- 开始 -------------------------------------
//todo 这里待定当出现脱机或者 故障的时候 怎么的一个形式告知 wms
//步骤1 WCS监听 PlcToWcs.Operate_Mode 是否为 1 , ( 1 = 联机 )
Integer operateMode = waitingForTarget(DDJPlc2WcsVar.Operate_Mode, 1);
if(operateMode!=1){
logger.info("失败"+" --- "+"步骤1. WCS监听 DDJPlc2WcsVar.Operate_Mode 是否 等于 1 失败");
build.setContent("失败步骤1监听数据异常");
build.setStatus(-2);
return build;
}
logger.info("成功"+" --- "+"步骤1. WCS监听 DDJPlc2WcsVar.Operate_Mode 等于 1 ");
//步骤2 WCS监听 PlcToWcs.Mission_State 是否为 0 , ( 0 = 空闲 )
Integer missionState = waitingForTarget(DDJPlc2WcsVar.Mission_State, 0);
if(missionState!=1){
logger.info("失败"+" --- "+"步骤2. WCS监听 PlcToWcs.Mission_State 是否 等于 0 失败");
build.setContent("失败步骤2监听数据异常");
build.setStatus(-2);
return build;
}
logger.info("成功"+" --- "+"步骤2. WCS监听 PlcToWcs.Mission_State 等于 0 ");
//步骤3 WCS下发任务
issueTask();
logger.info("成功"+" --- "+"步骤3. WCS 下发任务 ");
//步骤4 WCS启动任务WcsToPlc.Command_No 置为 1
write(s7Client,DDJWcs2PlcVar.Command_No,1);
logger.info("成功"+" --- "+"步骤4. WCS启动任务WcsToPlc.Command_No 置为 1 )成功 ");
//步骤5 WCS 监控PlcToWcs.Mission_State ==2 监控任务是否完成
Integer missionState2 = waitingForTargetAndLoggerError(DDJPlc2WcsVar.Mission_State,DDJPlc2WcsVar.Operate_Mode, 2);
if(missionState2!=1){
logger.info("失败"+" --- "+"步骤5. WCS 监控PlcToWcs.Mission_State ==2 监控任务是否完成");
build.setContent("失败步骤5监听数据异常");
build.setStatus(-2);
return build;
}
logger.info("成功"+" --- "+"步骤5. WCS 监控PlcToWcs.Mission_State ==2 ");
//步骤6 WCS Command_No 置为 2重置操作
write(s7Client,DDJWcs2PlcVar.Command_No,2);
logger.info("成功"+" --- "+"步骤6. WCS 把 Command_No 置为 2重置操作 ");
build.setStatus(100);
build.setContent("任务成功完成");
//调度逻辑 ------------------------------------- 结束
return build;
}, QGSThreadPool.ddj1ExecutorService).whenComplete(new BiConsumer<DDJInfoCallBack, Throwable>() {
//任务完成以后把结果返回给 第调用者
@Override
public void accept(DDJInfoCallBack agvInfoCallBack, Throwable throwable) {
if(throwable!=null){
logger.info("whenComplete throwable is " + throwable.getMessage());
}else {
logger.info("任务执行完成现在wcs把 结果:"+agvInfoCallBack.toString()+", 推送给wms");
HttpUtil.post(QGSConstant.wmsUrl, JSONObject.toJSONString(agvInfoCallBack));
logger.info("================= 任务结束 : "+ taskDTO.toString()+" ==================");
logger.info("");
}
}
});
}
/**
* desc: 下发任务给电控
* return
* true 成功
* false 失败
* */
private void issueTask() {
write(s7Client,DDJWcs2PlcVar.Mission_Type, taskDTO.getMissionType());
write(s7Client,DDJWcs2PlcVar.From_Row, taskDTO.getFromRow());
write(s7Client,DDJWcs2PlcVar.From_Layer, taskDTO.getFromLayer());
write(s7Client,DDJWcs2PlcVar.From_List, taskDTO.getFromList());
write(s7Client,DDJWcs2PlcVar.To_Row, taskDTO.getToRow());
write(s7Client,DDJWcs2PlcVar.To_List, taskDTO.getToList());
write(s7Client,DDJWcs2PlcVar.To_Layer, taskDTO.getToLayer());
write(s7Client,DDJWcs2PlcVar.Goods_Size, taskDTO.getGoodsSiZe());
write(s7Client,DDJWcs2PlcVar.Coordinate_conversion, taskDTO.getCoordinateConversion());
write(s7Client,DDJWcs2PlcVar.Mission_ID, taskDTO.getMissionID());
write(s7Client,DDJWcs2PlcVar.Pallet_Num, taskDTO.getPalletNum());
}
/**
*
* arg:
* RGV1Plc2WcsVarEnum 参数类型
* targetValue 目的值
* return:
* 2 opc 访问异常;
* 1 成功;
* */
private Integer waitingForTarget(DDJPlc2WcsVar var, Integer targetValue) {
Integer res = 0;
while (true){
try {
Integer now = (Integer) read(s7Client,var);
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Exception e){
logger.info("S7 数据采集 异常。");
res = 2;
break;
}
}
return res;
}
private Integer waitingForTargetAndOperaMode(DDJPlc2WcsVar var, Integer targetValue) {
Integer res = 0;
while (true){
try {
Integer now = (Integer) read(s7Client,var);
if(targetValue.equals(now)){
res = 1;
break;
}
Thread.sleep(200);
}catch (Exception e){
logger.info("S7 数据采集 异常。");
res = 2;
break;
}
}
return res;
}
private Integer waitingForTargetAndLoggerError(DDJPlc2WcsVar var,DDJPlc2WcsVar var2, Integer targetValue) {
Integer res = 0;
while (true){
try {
Integer now = (Integer) read(s7Client,var);
Integer operateMode = (Integer) read(s7Client,var2);
if(targetValue.equals(now)){
res = 1;
break;
}
if(operateMode.equals(2)){
Integer faultNo = (Integer) read(s7Client,DDJPlc2WcsVar.Fault_No);
logger.info("步骤5 DDJ在运行的时候出现 fault, fault no = "+faultNo);
//调用上层的 回调方法 开始
executeLinktestRecvTask(faultNo);
//调用上层的 回调方法 结束
Thread.sleep(10000);
}
Thread.sleep(200);
}catch (Exception e){
logger.info("S7 数据采集 异常。");
res = 2;
break;
}
}
return res;
}
/**
* return
* 成功 返回相应的object对象
* 失败 返回null
* */
private Object read(S7Client s7Client, DDJPlc2WcsVar var) {
try {
return s7Client.read(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getLength(), var.getStrSize(), var.getType());
}catch (Exception e){
logger.error("host:"+s7Client.getHost()+" ; read 操作出现问题: "+e.getMessage());
e.printStackTrace();
return null;
}
}
private void write(S7Client s7Client, DDJWcs2PlcVar var, Object newValue) {
if(var.getType().equals(PlcVar.STRING_Array)){
String[] s = (String[])newValue;
String[] ss = (String[])newValue;
if(s.length > var.getLength() ){
ss = new String[var.getLength()];
for(int i=0;i< var.getLength();i++){
ss[i] = s[i];
}
}
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),ss);
}else {
s7Client.write(var.getArea(), var.getAreaNumber(), var.getByteOffset(), var.getBitOffset(), var.getStrSize(), var.getType(),newValue);
}
}
}

View File

@ -1,16 +0,0 @@
package com.cnbm.dispatchDDJ.constant;
/**
* @Author: 蔡翔
* @Date: 2019/11/3 11:30
* @Version 1.0
*/
public class QGSConstant {
public static final Object LOCK = new Object();
public static final Long deadLineTime = 300000L;
//wms 需提供 post 接口
public static final String wmsUrl = "http://localhost:8089/wms-qy/work/wcs2wms/taskcallback";
}

View File

@ -1,24 +0,0 @@
package com.cnbm.dispatchDDJ.entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @author caixiang
* @since 2022-05-31
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class DDJInfoCallBack implements Serializable {
private static final long serialVersionUID = 1L;
private Integer status;
private String content;
private Integer taskId;
}

View File

@ -1,39 +0,0 @@
package com.cnbm.dispatchDDJ.entity;
import lombok.Data;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2021/11/9 20:50
*/
@Data
public class TaskDTO {
//任务类型
private Integer missionType;
//起点-
private Integer fromRow;
//起点-
private Integer fromList;
//起点-
private Integer fromLayer;
//终点-
private Integer toRow;
//终点-
private Integer toList;
//终点-
private Integer toLayer;
//货物尺寸
private Integer goodsSiZe;
//坐标转换
private Integer coordinateConversion;
//任务号
private Integer missionID;
//条码值
private Integer palletNum;
}

View File

@ -1,15 +0,0 @@
package com.cnbm.dispatchDDJ.enums;
/**
* @Author: 蔡翔
* @Date: 2019/10/14 10:07
* @Version 1.0
*/
public interface CodeEnum {
Integer getNamespace();
String getIdentity();
String getType();
String getName();
String getDesc();
void set(String name,Integer nameSpace,String identity);
}

View File

@ -1,110 +0,0 @@
package com.cnbm.dispatchDDJ.enums.ddj.ddj1;
import com.cnbm.s7.s7connector.api.DaveArea;
import com.cnbm.s7.s7connector.type.PlcVar;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023/2/21 19:35
*/
public enum DDJPlc2WcsVar {
Operate_Mode("Operate_Mode", PlcVar.INT,1, DaveArea.DB,2,0,0),
Mission_State("Mission_State",PlcVar.INT,1,DaveArea.DB,2,2,0),
From_Row("From_Row",PlcVar.INT,1,DaveArea.DB,2,4,0),
From_List("From_List",PlcVar.INT,1,DaveArea.DB,2,6,0),
From_Layer("From_Layer",PlcVar.INT,1,DaveArea.DB,2,8,0),
To_Row("To_Row",PlcVar.INT,1,DaveArea.DB,2,10,0),
To_List("To_List",PlcVar.INT,1,DaveArea.DB,2,12,0),
To_Layer("To_Layer",PlcVar.INT,1,DaveArea.DB,2,14,0),
Mission_Type("Mission_Type",PlcVar.INT,1,DaveArea.DB,2,16,0),
Act_Pos_X("Act_Pos_X", PlcVar.DINT,1, DaveArea.DB,2,18,0),
Act_Pos_Y("Act_Pos_Y", PlcVar.DINT,1, DaveArea.DB,2,22,0),
Act_Speed_X("Act_Speed_X", PlcVar.DINT,1, DaveArea.DB,2,26,0),
Act_Speed_Y("Act_Speed_Y", PlcVar.DINT,1, DaveArea.DB,2,30,0),
Status_bit1("Status_bit1", PlcVar.BOOL_Array,8, DaveArea.DB,2,34,0),
Status_bit2("Status_bit2", PlcVar.BOOL_Array,8, DaveArea.DB,2,35,0),
Fault_No("Fault_No", PlcVar.INT,1, DaveArea.DB,2,36,0),
Now_List("Now_List", PlcVar.INT,1, DaveArea.DB,2,38,0),
Now_Layer("Now_Layer", PlcVar.INT,1, DaveArea.DB,2,40,0),
Mission_ID("Act_Pos_X", PlcVar.INT,1, DaveArea.DB,2,42,0),
Pallet_Num("Pallet_Num", PlcVar.STRING,1, DaveArea.DB,2,44,0),
;
private String name;
private DaveArea area;
private Integer areaNumber;
private Integer byteOffset;
private Integer bitOffset;
private PlcVar type;
//length = 1代表 非数组;;; length > 1 代表数组 ;; 注意 length这个参数 是实际plc中 数组的长度和read操作相关
//如果是String 类型不用填length 只需要填string类型的起始位置就行了我会自己去取数据长度也就是说这里的length并不是string 的长度
private Integer length;
//这个字段只是给 字符串变量 字符串数组 , 这个字段是plc中设置的最大String长度
private Integer strSize;
DDJPlc2WcsVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = 0;
}
DDJPlc2WcsVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset, Integer strSize){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = strSize;
}
public Integer getStrSize() {
return strSize;
}
public void setStrSize(Integer strSize) {
this.strSize = strSize;
}
public String getName() {
return name;
}
public DaveArea getArea() {
return area;
}
public Integer getAreaNumber() {
return areaNumber;
}
public Integer getBitOffset() {
return bitOffset;
}
public Integer getByteOffset() {
return byteOffset;
}
public PlcVar getType() {
return type;
}
public Integer getLength() {
return length;
}
}

View File

@ -1,101 +0,0 @@
package com.cnbm.dispatchDDJ.enums.ddj.ddj1;
import com.cnbm.s7.s7connector.api.DaveArea;
import com.cnbm.s7.s7connector.type.PlcVar;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023/2/21 19:35
*/
public enum DDJWcs2PlcVar {
Mission_Count("Mission_Count", PlcVar.INT,1, DaveArea.DB,1,0,0),
Command_No("Command_No", PlcVar.INT,1, DaveArea.DB,1,2,0),
Mission_Type("Mission_Type",PlcVar.INT,1,DaveArea.DB,1,4,0),
From_Row("From_Row",PlcVar.INT,1,DaveArea.DB,1,6,0),
From_List("From_List",PlcVar.INT,1,DaveArea.DB,1,8,0),
From_Layer("From_Layer",PlcVar.INT,1,DaveArea.DB,1,10,0),
To_Row("To_Row",PlcVar.INT,1,DaveArea.DB,1,12,0),
To_List("To_List",PlcVar.INT,1,DaveArea.DB,1,14,0),
To_Layer("To_Layer",PlcVar.INT,1,DaveArea.DB,1,16,0),
Control_bit1("Status_bit1", PlcVar.BOOL_Array,8, DaveArea.DB,1,18,0),
Control_bit2("Status_bit2", PlcVar.BOOL_Array,8, DaveArea.DB,1,19,0),
Goods_Size("Goods_Size", PlcVar.INT,1, DaveArea.DB,1,20,0),
Coordinate_conversion("Coordinate_conversion", PlcVar.INT,1, DaveArea.DB,1,22,0),
Mission_ID("Mission_ID", PlcVar.INT,1, DaveArea.DB,1,24,0),
//todo 条码值 要写长度
Pallet_Num("Pallet_Num", PlcVar.STRING,1, DaveArea.DB,1,26,0),
;
private String name;
private DaveArea area;
private Integer areaNumber;
private Integer byteOffset;
private Integer bitOffset;
private PlcVar type;
//length = 1代表 非数组;;; length > 1 代表数组 ;; 注意 length这个参数 是实际plc中 数组的长度和read操作相关
//如果是String 类型不用填length 只需要填string类型的起始位置就行了我会自己去取数据长度也就是说这里的length并不是string 的长度
private Integer length;
//这个字段只是给 字符串变量 字符串数组 , 这个字段是plc中设置的最大String长度
private Integer strSize;
DDJWcs2PlcVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = 0;
}
DDJWcs2PlcVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset, Integer strSize){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = strSize;
}
public Integer getStrSize() {
return strSize;
}
public void setStrSize(Integer strSize) {
this.strSize = strSize;
}
public String getName() {
return name;
}
public DaveArea getArea() {
return area;
}
public Integer getAreaNumber() {
return areaNumber;
}
public Integer getBitOffset() {
return bitOffset;
}
public Integer getByteOffset() {
return byteOffset;
}
public PlcVar getType() {
return type;
}
public Integer getLength() {
return length;
}
}

View File

@ -1,110 +0,0 @@
package com.cnbm.dispatchDDJ.enums.ddj.ddj2;
import com.cnbm.s7.s7connector.api.DaveArea;
import com.cnbm.s7.s7connector.type.PlcVar;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023/2/21 19:35
*/
public enum DDJPlc2WcsVar {
Operate_Mode("Operate_Mode", PlcVar.INT,1, DaveArea.DB,2,0,0),
Mission_State("Mission_State",PlcVar.INT,1,DaveArea.DB,2,2,0),
From_Row("From_Row",PlcVar.INT,1,DaveArea.DB,2,4,0),
From_List("From_List",PlcVar.INT,1,DaveArea.DB,2,6,0),
From_Layer("From_Layer",PlcVar.INT,1,DaveArea.DB,2,8,0),
To_Row("To_Row",PlcVar.INT,1,DaveArea.DB,2,10,0),
To_List("To_List",PlcVar.INT,1,DaveArea.DB,2,12,0),
To_Layer("To_Layer",PlcVar.INT,1,DaveArea.DB,2,14,0),
Mission_Type("Mission_Type",PlcVar.INT,1,DaveArea.DB,2,16,0),
Act_Pos_X("Act_Pos_X", PlcVar.DINT,1, DaveArea.DB,2,18,0),
Act_Pos_Y("Act_Pos_Y", PlcVar.DINT,1, DaveArea.DB,2,22,0),
Act_Speed_X("Act_Speed_X", PlcVar.DINT,1, DaveArea.DB,2,26,0),
Act_Speed_Y("Act_Speed_Y", PlcVar.DINT,1, DaveArea.DB,2,30,0),
Status_bit1("Status_bit1", PlcVar.BOOL_Array,8, DaveArea.DB,2,34,0),
Status_bit2("Status_bit2", PlcVar.BOOL_Array,8, DaveArea.DB,2,35,0),
Fault_No("Fault_No", PlcVar.INT,1, DaveArea.DB,2,36,0),
Now_List("Now_List", PlcVar.INT,1, DaveArea.DB,2,38,0),
Now_Layer("Now_Layer", PlcVar.INT,1, DaveArea.DB,2,40,0),
Mission_ID("Act_Pos_X", PlcVar.INT,1, DaveArea.DB,2,42,0),
Pallet_Num("Pallet_Num", PlcVar.STRING,1, DaveArea.DB,2,44,0),
;
private String name;
private DaveArea area;
private Integer areaNumber;
private Integer byteOffset;
private Integer bitOffset;
private PlcVar type;
//length = 1代表 非数组;;; length > 1 代表数组 ;; 注意 length这个参数 是实际plc中 数组的长度和read操作相关
//如果是String 类型不用填length 只需要填string类型的起始位置就行了我会自己去取数据长度也就是说这里的length并不是string 的长度
private Integer length;
//这个字段只是给 字符串变量 字符串数组 , 这个字段是plc中设置的最大String长度
private Integer strSize;
DDJPlc2WcsVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = 0;
}
DDJPlc2WcsVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset, Integer strSize){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = strSize;
}
public Integer getStrSize() {
return strSize;
}
public void setStrSize(Integer strSize) {
this.strSize = strSize;
}
public String getName() {
return name;
}
public DaveArea getArea() {
return area;
}
public Integer getAreaNumber() {
return areaNumber;
}
public Integer getBitOffset() {
return bitOffset;
}
public Integer getByteOffset() {
return byteOffset;
}
public PlcVar getType() {
return type;
}
public Integer getLength() {
return length;
}
}

View File

@ -1,101 +0,0 @@
package com.cnbm.dispatchDDJ.enums.ddj.ddj2;
import com.cnbm.s7.s7connector.api.DaveArea;
import com.cnbm.s7.s7connector.type.PlcVar;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023/2/21 19:35
*/
public enum DDJWcs2PlcVar {
Mission_Count("Mission_Count", PlcVar.INT,1, DaveArea.DB,1,0,0),
Command_No("Command_No", PlcVar.INT,1, DaveArea.DB,1,2,0),
Mission_Type("Mission_Type",PlcVar.INT,1,DaveArea.DB,1,4,0),
From_Row("From_Row",PlcVar.INT,1,DaveArea.DB,1,6,0),
From_List("From_List",PlcVar.INT,1,DaveArea.DB,1,8,0),
From_Layer("From_Layer",PlcVar.INT,1,DaveArea.DB,1,10,0),
To_Row("To_Row",PlcVar.INT,1,DaveArea.DB,1,12,0),
To_List("To_List",PlcVar.INT,1,DaveArea.DB,1,14,0),
To_Layer("To_Layer",PlcVar.INT,1,DaveArea.DB,1,16,0),
Control_bit1("Status_bit1", PlcVar.BOOL_Array,8, DaveArea.DB,1,18,0),
Control_bit2("Status_bit2", PlcVar.BOOL_Array,8, DaveArea.DB,1,19,0),
Goods_Size("Goods_Size", PlcVar.INT,1, DaveArea.DB,1,20,0),
Coordinate_conversion("Coordinate_conversion", PlcVar.INT,1, DaveArea.DB,1,22,0),
Mission_ID("Mission_ID", PlcVar.INT,1, DaveArea.DB,1,24,0),
//todo 条码值 要写长度
Pallet_Num("Pallet_Num", PlcVar.STRING,1, DaveArea.DB,1,26,0),
;
private String name;
private DaveArea area;
private Integer areaNumber;
private Integer byteOffset;
private Integer bitOffset;
private PlcVar type;
//length = 1代表 非数组;;; length > 1 代表数组 ;; 注意 length这个参数 是实际plc中 数组的长度和read操作相关
//如果是String 类型不用填length 只需要填string类型的起始位置就行了我会自己去取数据长度也就是说这里的length并不是string 的长度
private Integer length;
//这个字段只是给 字符串变量 字符串数组 , 这个字段是plc中设置的最大String长度
private Integer strSize;
DDJWcs2PlcVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = 0;
}
DDJWcs2PlcVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset, Integer strSize){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = strSize;
}
public Integer getStrSize() {
return strSize;
}
public void setStrSize(Integer strSize) {
this.strSize = strSize;
}
public String getName() {
return name;
}
public DaveArea getArea() {
return area;
}
public Integer getAreaNumber() {
return areaNumber;
}
public Integer getBitOffset() {
return bitOffset;
}
public Integer getByteOffset() {
return byteOffset;
}
public PlcVar getType() {
return type;
}
public Integer getLength() {
return length;
}
}

View File

@ -1,110 +0,0 @@
package com.cnbm.dispatchDDJ.enums.ddj.ddj3;
import com.cnbm.s7.s7connector.api.DaveArea;
import com.cnbm.s7.s7connector.type.PlcVar;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023/2/21 19:35
*/
public enum DDJPlc2WcsVar {
Operate_Mode("Operate_Mode", PlcVar.INT,1, DaveArea.DB,2,0,0),
Mission_State("Mission_State",PlcVar.INT,1,DaveArea.DB,2,2,0),
From_Row("From_Row",PlcVar.INT,1,DaveArea.DB,2,4,0),
From_List("From_List",PlcVar.INT,1,DaveArea.DB,2,6,0),
From_Layer("From_Layer",PlcVar.INT,1,DaveArea.DB,2,8,0),
To_Row("To_Row",PlcVar.INT,1,DaveArea.DB,2,10,0),
To_List("To_List",PlcVar.INT,1,DaveArea.DB,2,12,0),
To_Layer("To_Layer",PlcVar.INT,1,DaveArea.DB,2,14,0),
Mission_Type("Mission_Type",PlcVar.INT,1,DaveArea.DB,2,16,0),
Act_Pos_X("Act_Pos_X", PlcVar.DINT,1, DaveArea.DB,2,18,0),
Act_Pos_Y("Act_Pos_Y", PlcVar.DINT,1, DaveArea.DB,2,22,0),
Act_Speed_X("Act_Speed_X", PlcVar.DINT,1, DaveArea.DB,2,26,0),
Act_Speed_Y("Act_Speed_Y", PlcVar.DINT,1, DaveArea.DB,2,30,0),
Status_bit1("Status_bit1", PlcVar.BOOL_Array,8, DaveArea.DB,2,34,0),
Status_bit2("Status_bit2", PlcVar.BOOL_Array,8, DaveArea.DB,2,35,0),
Fault_No("Fault_No", PlcVar.INT,1, DaveArea.DB,2,36,0),
Now_List("Now_List", PlcVar.INT,1, DaveArea.DB,2,38,0),
Now_Layer("Now_Layer", PlcVar.INT,1, DaveArea.DB,2,40,0),
Mission_ID("Act_Pos_X", PlcVar.INT,1, DaveArea.DB,2,42,0),
Pallet_Num("Pallet_Num", PlcVar.STRING,1, DaveArea.DB,2,44,0),
;
private String name;
private DaveArea area;
private Integer areaNumber;
private Integer byteOffset;
private Integer bitOffset;
private PlcVar type;
//length = 1代表 非数组;;; length > 1 代表数组 ;; 注意 length这个参数 是实际plc中 数组的长度和read操作相关
//如果是String 类型不用填length 只需要填string类型的起始位置就行了我会自己去取数据长度也就是说这里的length并不是string 的长度
private Integer length;
//这个字段只是给 字符串变量 字符串数组 , 这个字段是plc中设置的最大String长度
private Integer strSize;
DDJPlc2WcsVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = 0;
}
DDJPlc2WcsVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset, Integer strSize){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = strSize;
}
public Integer getStrSize() {
return strSize;
}
public void setStrSize(Integer strSize) {
this.strSize = strSize;
}
public String getName() {
return name;
}
public DaveArea getArea() {
return area;
}
public Integer getAreaNumber() {
return areaNumber;
}
public Integer getBitOffset() {
return bitOffset;
}
public Integer getByteOffset() {
return byteOffset;
}
public PlcVar getType() {
return type;
}
public Integer getLength() {
return length;
}
}

View File

@ -1,101 +0,0 @@
package com.cnbm.dispatchDDJ.enums.ddj.ddj3;
import com.cnbm.s7.s7connector.api.DaveArea;
import com.cnbm.s7.s7connector.type.PlcVar;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023/2/21 19:35
*/
public enum DDJWcs2PlcVar {
Mission_Count("Mission_Count", PlcVar.INT,1, DaveArea.DB,1,0,0),
Command_No("Command_No", PlcVar.INT,1, DaveArea.DB,1,2,0),
Mission_Type("Mission_Type",PlcVar.INT,1,DaveArea.DB,1,4,0),
From_Row("From_Row",PlcVar.INT,1,DaveArea.DB,1,6,0),
From_List("From_List",PlcVar.INT,1,DaveArea.DB,1,8,0),
From_Layer("From_Layer",PlcVar.INT,1,DaveArea.DB,1,10,0),
To_Row("To_Row",PlcVar.INT,1,DaveArea.DB,1,12,0),
To_List("To_List",PlcVar.INT,1,DaveArea.DB,1,14,0),
To_Layer("To_Layer",PlcVar.INT,1,DaveArea.DB,1,16,0),
Control_bit1("Status_bit1", PlcVar.BOOL_Array,8, DaveArea.DB,1,18,0),
Control_bit2("Status_bit2", PlcVar.BOOL_Array,8, DaveArea.DB,1,19,0),
Goods_Size("Goods_Size", PlcVar.INT,1, DaveArea.DB,1,20,0),
Coordinate_conversion("Coordinate_conversion", PlcVar.INT,1, DaveArea.DB,1,22,0),
Mission_ID("Mission_ID", PlcVar.INT,1, DaveArea.DB,1,24,0),
//todo 条码值 要写长度
Pallet_Num("Pallet_Num", PlcVar.STRING,1, DaveArea.DB,1,26,0),
;
private String name;
private DaveArea area;
private Integer areaNumber;
private Integer byteOffset;
private Integer bitOffset;
private PlcVar type;
//length = 1代表 非数组;;; length > 1 代表数组 ;; 注意 length这个参数 是实际plc中 数组的长度和read操作相关
//如果是String 类型不用填length 只需要填string类型的起始位置就行了我会自己去取数据长度也就是说这里的length并不是string 的长度
private Integer length;
//这个字段只是给 字符串变量 字符串数组 , 这个字段是plc中设置的最大String长度
private Integer strSize;
DDJWcs2PlcVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = 0;
}
DDJWcs2PlcVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset, Integer strSize){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = strSize;
}
public Integer getStrSize() {
return strSize;
}
public void setStrSize(Integer strSize) {
this.strSize = strSize;
}
public String getName() {
return name;
}
public DaveArea getArea() {
return area;
}
public Integer getAreaNumber() {
return areaNumber;
}
public Integer getBitOffset() {
return bitOffset;
}
public Integer getByteOffset() {
return byteOffset;
}
public PlcVar getType() {
return type;
}
public Integer getLength() {
return length;
}
}

View File

@ -1,110 +0,0 @@
package com.cnbm.dispatchDDJ.enums.ddj.ddj4;
import com.cnbm.s7.s7connector.api.DaveArea;
import com.cnbm.s7.s7connector.type.PlcVar;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023/2/21 19:35
*/
public enum DDJPlc2WcsVar {
Operate_Mode("Operate_Mode", PlcVar.INT,1, DaveArea.DB,2,0,0),
Mission_State("Mission_State",PlcVar.INT,1,DaveArea.DB,2,2,0),
From_Row("From_Row",PlcVar.INT,1,DaveArea.DB,2,4,0),
From_List("From_List",PlcVar.INT,1,DaveArea.DB,2,6,0),
From_Layer("From_Layer",PlcVar.INT,1,DaveArea.DB,2,8,0),
To_Row("To_Row",PlcVar.INT,1,DaveArea.DB,2,10,0),
To_List("To_List",PlcVar.INT,1,DaveArea.DB,2,12,0),
To_Layer("To_Layer",PlcVar.INT,1,DaveArea.DB,2,14,0),
Mission_Type("Mission_Type",PlcVar.INT,1,DaveArea.DB,2,16,0),
Act_Pos_X("Act_Pos_X", PlcVar.DINT,1, DaveArea.DB,2,18,0),
Act_Pos_Y("Act_Pos_Y", PlcVar.DINT,1, DaveArea.DB,2,22,0),
Act_Speed_X("Act_Speed_X", PlcVar.DINT,1, DaveArea.DB,2,26,0),
Act_Speed_Y("Act_Speed_Y", PlcVar.DINT,1, DaveArea.DB,2,30,0),
Status_bit1("Status_bit1", PlcVar.BOOL_Array,8, DaveArea.DB,2,34,0),
Status_bit2("Status_bit2", PlcVar.BOOL_Array,8, DaveArea.DB,2,35,0),
Fault_No("Fault_No", PlcVar.INT,1, DaveArea.DB,2,36,0),
Now_List("Now_List", PlcVar.INT,1, DaveArea.DB,2,38,0),
Now_Layer("Now_Layer", PlcVar.INT,1, DaveArea.DB,2,40,0),
Mission_ID("Act_Pos_X", PlcVar.INT,1, DaveArea.DB,2,42,0),
Pallet_Num("Pallet_Num", PlcVar.STRING,1, DaveArea.DB,2,44,0),
;
private String name;
private DaveArea area;
private Integer areaNumber;
private Integer byteOffset;
private Integer bitOffset;
private PlcVar type;
//length = 1代表 非数组;;; length > 1 代表数组 ;; 注意 length这个参数 是实际plc中 数组的长度和read操作相关
//如果是String 类型不用填length 只需要填string类型的起始位置就行了我会自己去取数据长度也就是说这里的length并不是string 的长度
private Integer length;
//这个字段只是给 字符串变量 字符串数组 , 这个字段是plc中设置的最大String长度
private Integer strSize;
DDJPlc2WcsVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = 0;
}
DDJPlc2WcsVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset, Integer strSize){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = strSize;
}
public Integer getStrSize() {
return strSize;
}
public void setStrSize(Integer strSize) {
this.strSize = strSize;
}
public String getName() {
return name;
}
public DaveArea getArea() {
return area;
}
public Integer getAreaNumber() {
return areaNumber;
}
public Integer getBitOffset() {
return bitOffset;
}
public Integer getByteOffset() {
return byteOffset;
}
public PlcVar getType() {
return type;
}
public Integer getLength() {
return length;
}
}

View File

@ -1,101 +0,0 @@
package com.cnbm.dispatchDDJ.enums.ddj.ddj4;
import com.cnbm.s7.s7connector.api.DaveArea;
import com.cnbm.s7.s7connector.type.PlcVar;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023/2/21 19:35
*/
public enum DDJWcs2PlcVar {
Mission_Count("Mission_Count", PlcVar.INT,1, DaveArea.DB,1,0,0),
Command_No("Command_No", PlcVar.INT,1, DaveArea.DB,1,2,0),
Mission_Type("Mission_Type",PlcVar.INT,1,DaveArea.DB,1,4,0),
From_Row("From_Row",PlcVar.INT,1,DaveArea.DB,1,6,0),
From_List("From_List",PlcVar.INT,1,DaveArea.DB,1,8,0),
From_Layer("From_Layer",PlcVar.INT,1,DaveArea.DB,1,10,0),
To_Row("To_Row",PlcVar.INT,1,DaveArea.DB,1,12,0),
To_List("To_List",PlcVar.INT,1,DaveArea.DB,1,14,0),
To_Layer("To_Layer",PlcVar.INT,1,DaveArea.DB,1,16,0),
Control_bit1("Status_bit1", PlcVar.BOOL_Array,8, DaveArea.DB,1,18,0),
Control_bit2("Status_bit2", PlcVar.BOOL_Array,8, DaveArea.DB,1,19,0),
Goods_Size("Goods_Size", PlcVar.INT,1, DaveArea.DB,1,20,0),
Coordinate_conversion("Coordinate_conversion", PlcVar.INT,1, DaveArea.DB,1,22,0),
Mission_ID("Mission_ID", PlcVar.INT,1, DaveArea.DB,1,24,0),
//todo 条码值 要写长度
Pallet_Num("Pallet_Num", PlcVar.STRING,1, DaveArea.DB,1,26,0),
;
private String name;
private DaveArea area;
private Integer areaNumber;
private Integer byteOffset;
private Integer bitOffset;
private PlcVar type;
//length = 1代表 非数组;;; length > 1 代表数组 ;; 注意 length这个参数 是实际plc中 数组的长度和read操作相关
//如果是String 类型不用填length 只需要填string类型的起始位置就行了我会自己去取数据长度也就是说这里的length并不是string 的长度
private Integer length;
//这个字段只是给 字符串变量 字符串数组 , 这个字段是plc中设置的最大String长度
private Integer strSize;
DDJWcs2PlcVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = 0;
}
DDJWcs2PlcVar(String name, PlcVar type, Integer length, DaveArea area, Integer areaNumber, Integer byteOffset, Integer bitOffset, Integer strSize){
this.name = name;
this.type = type;
this.length = length;
this.area = area;
this.areaNumber = areaNumber;
this.byteOffset = byteOffset;
this.bitOffset = bitOffset;
this.strSize = strSize;
}
public Integer getStrSize() {
return strSize;
}
public void setStrSize(Integer strSize) {
this.strSize = strSize;
}
public String getName() {
return name;
}
public DaveArea getArea() {
return area;
}
public Integer getAreaNumber() {
return areaNumber;
}
public Integer getBitOffset() {
return bitOffset;
}
public Integer getByteOffset() {
return byteOffset;
}
public PlcVar getType() {
return type;
}
public Integer getLength() {
return length;
}
}

View File

@ -1,10 +0,0 @@
package com.cnbm.dispatchDDJ.interfaces;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023-07-28 14:54
*/
public interface Listener {
public void addRuntimeEQErrListener(RuntimeEQErrListener errCode);
}

View File

@ -1,31 +0,0 @@
package com.cnbm.dispatchDDJ.interfaces;
import java.util.EventListener;
/**
* SecsMessage receive Listener.
*
* <p>
* This interface is used in {@link #()}<br />
* Receive-Message is only Primary-Message.<br />
* </p>
*
* @author kenta-shimizu
*/
public interface RuntimeEQErrListener extends EventListener {
/**
* Putter Received Primary-Message.
*
* <p>
* Not accept {@code null}.<br />
* </p>
*
* @param only Primary-Message
*/
public void received(Integer errCode);
}

View File

@ -1,25 +0,0 @@
package com.cnbm.dispatchDDJ.main;
import com.cnbm.dispatchDDJ.DDJ1Task;
import com.cnbm.dispatchDDJ.entity.TaskDTO;
import com.cnbm.s7.s7connector.enmuc.S7Client;
import io.lettuce.core.ScriptOutputType;
import java.util.concurrent.ExecutionException;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2023-07-28 15:08
*/
public class main {
public static void main(String[] args) throws ExecutionException, InterruptedException {
DDJ1Task ddj1Task = new DDJ1Task();
ddj1Task.addRuntimeEQErrListener(errCode -> {
//当设备运行过程中出现告警了会调用这个函数可能会重复调用
//调度程序不会因为 出现告警 就终止此次任务会等待人工解决告警然后设备返回给我successCode
System.out.println("errCode : "+errCode);
});
ddj1Task.run();
}
}

View File

@ -1,42 +0,0 @@
package com.cnbm.dispatchDDJ.taskPool;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @Author: 蔡翔
* @Date: 2019/9/23 9:32
* @Version 1.0
*/
public class QGSThreadPool {
public static AtomicInteger threadCount = new AtomicInteger();
public static ThreadPoolExecutor executor = new ThreadPoolExecutor(
200, //核心线程数
400, //最大线程数
1L, // 空闲线程存活时间 这里是一分钟
TimeUnit.MINUTES, // 空闲线程存货的时间单位
new ArrayBlockingQueue<>(200), //一个指定上限的的阻塞队列这个队列中存放着待执行的任务
new ThreadFactory() {
// 自定义一个线程工厂来给线程池里面的线程取名字
@Override
public Thread newThread(Runnable r) {
return new Thread(r, "threadPool-opc-" + threadCount.incrementAndGet());
}
},
new RejectedExecutionHandler() {
// 自定义一个拒绝处理策略安慰被线程池拒之门外的任务
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
System.out.println("opc read err"+r);
}
}
);
public static ExecutorService ddj1ExecutorService = Executors.newSingleThreadExecutor();
public static ExecutorService ddj2ExecutorService = Executors.newSingleThreadExecutor();
public static ExecutorService ddj3ExecutorService = Executors.newSingleThreadExecutor();
public static ExecutorService ddj4ExecutorService = Executors.newSingleThreadExecutor();
/*public ExecutorService getExecutor(){
return this.executor;
}*/
}

View File

@ -52,7 +52,6 @@ public class WoPowerLevelController {
@PreAuthorize("@ex.hasAuthority('packing:woPowerLevel:page')")
public Result<PageData<WoPowerLevelDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
PageData<WoPowerLevelDTO> page = woPowerLevelService.page(params);
return new Result<PageData<WoPowerLevelDTO>>().ok(page);
}
@ -61,7 +60,6 @@ public class WoPowerLevelController {
@PreAuthorize("@ex.hasAuthority('packing:woPowerLevel:info')")
public Result<WoPowerLevelDTO> get(@PathVariable("id") Long id){
WoPowerLevelDTO data = woPowerLevelService.get(id);
return new Result<WoPowerLevelDTO>().ok(data);
}

View File

@ -27,10 +27,13 @@ public enum S7Client {
// S7_1200("192.168.0.52",0,1,1,PlcVarActual.HeartBeatFor1200),
// S7_15001("192.168.0.51",0,1,1),
// S7_1500("192.168.0.51",0,1,1),
//1线
S7_DDJ1("10.10.3.158",0,1,2),
//2线
S7_DDJ2("10.10.3.158",0,1,2),
S7_DDJ3("10.10.3.158",0,1,2),
S7_DDJ4("10.10.3.158",0,1,2),
//1500 机架-0 插槽-1
//后续 在这里扩展 多PLC应用
;