From 72ce003daa99f4e36466e7fc146e6c14bfc6438f Mon Sep 17 00:00:00 2001
From: 1 <1>
Date: 星期一, 27 十月 2025 08:32:42 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SiemensDevpThread.java | 248 ++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 211 insertions(+), 37 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 8624f3f..83db7d4 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -9,14 +9,8 @@
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
-import com.zy.asrs.entity.BasDevp;
-import com.zy.asrs.entity.BasDevpOpt;
-import com.zy.asrs.entity.BasRgvMap;
-import com.zy.asrs.entity.BasRgvOpt;
-import com.zy.asrs.service.BasDevpOptService;
-import com.zy.asrs.service.BasDevpService;
-import com.zy.asrs.service.BasRgvMapService;
-import com.zy.asrs.service.BasRgvOptService;
+import com.zy.asrs.entity.*;
+import com.zy.asrs.service.*;
import com.zy.common.utils.News;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
@@ -62,7 +56,7 @@
add(1022);add(1024);
add(1025);add(1026);add(1028);
add(1029);add(1031);
- add(1032);add(1033);add(1035);
+ add(1032);add(1033);add(1034);add(1035);
add(1036);add(1037);add(1038);
add(1039);add(1040);add(1041);
add(1042);add(1043);add(1044);add(1045);add(1046);add(1047);add(1048);add(1050);add(1051);add(1052);add(1053);add(1054);add(1055);add(1056);add(1057);
@@ -89,7 +83,7 @@
// add(2045);add(2046);add(2047);add(2048);
// add(2101);add(2102);add(2103);add(2104);add(2105);add(2106);add(2107);add(2108);add(2109);add(2110);
// add(2111);add(2112);add(2113);add(2114);add(2115);add(2116);add(2117);add(2118);add(2119);add(2120);
-// add(4001);add(4003);add(4004);add(4006);
+ add(4001);add(4003);add(4004);add(4006);
}};
// 绔欑偣鍋忕Щ閲忔槧灏勮〃
@@ -127,13 +121,13 @@
}};
public static final Map<Integer, Integer> siteErrOffsetMap = new HashMap<Integer, Integer>() {{
- put(1036, 512);put(1103, 476);put(1047, 452);put(2037, 270);
+ put(1036, 512);put(1103, 476);put(1047, 452);put(2037, 270);put(4001,294);
}};
// 鐗规畩绔欑偣闆嗗悎
private static final Set<Integer> specialSites = new HashSet<>(
- Arrays.asList(1001,1005,1008,1011,1015,1019,1022,1025,1029, 1032,1039,2004,2001,2007,2010,2016,2013,2019,2022,2025,4001,4004));
+ Arrays.asList(1001,1005,1008,1011,1015,1019,1022,1025,1029, 1032,1039,2004,2001,2007,2010,2016,2013,2019,2022,2025,2028,4001,4004));
// 鐗规畩绔欑偣闆嗗悎
private static final Set<Integer> specialSites2 = new HashSet<>(
@@ -150,7 +144,7 @@
add(3); add(4); add(5);
}};
public static final ArrayList<Integer> staNosErrList = new ArrayList<Integer>() {{
- add(1103);add(1036);add(1047);
+ add(1103);add(1036);add(1047);add(2037);
}};
private Integer count=0;
@@ -169,9 +163,9 @@
public static int getOffsetBySiteId2(int siteId) {
int offset = 0;
if (specialSites.contains(siteId)) {
- offset = 72; // 鐗规畩绔欑偣鍗� 96
+ offset = 72; // 鐗规畩绔欑偣鍗� 72
} else {
- offset = 60; // 鏅�氱珯鐐瑰崰 72
+ offset = 60; // 鏅�氱珯鐐瑰崰 60
}
return offset;
}
@@ -219,11 +213,61 @@
throw new CoolException("鏈嶅姟鍣ㄥ紓甯�");
}
}
+ private boolean connectDev = false;
@Override
@SuppressWarnings("InfiniteLoopStatement")
public void run() {
- connect();
+ connectDev = connect();
+ while(!connectDev){
+ try {
+ connectDev = this.connect();
+ Thread.sleep(100);
+ } catch (Exception e){
+
+ }
+ }
+
+ // 鍚姩绾跨▼鑷姩閲嶈繛
+ new Thread(this::devConnect).start();
+ new Thread(this::readStatusDev).start();
+ new Thread(this::writeStatusDev).start();
+ }
+ private void readStatusDev() {
+ while (true) {
+ try {
+ Thread.sleep(50);
+ read();
+
+ } catch (Exception e) {
+ log.error("Dev鏁版嵁璇诲彇绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ initSite();
+ }
+
+ }
+
+ }
+ private void devConnect() {
+ while (true) {
+ try {
+ Thread.sleep(1000);
+
+ if(!connectDev){
+ try {
+ connectDev = this.connect();
+ Thread.sleep(100);
+ } catch (Exception e){
+
+ }
+ }
+ } catch (Exception e) {
+ log.info("dev杩炴帴澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ initSite();
+// e.printStackTrace();
+ }
+ }
+ }
+ private void writeStatusDev() {
while (true) {
try {
int step = 1;
@@ -234,7 +278,7 @@
switch (step) {
// 璇绘暟鎹�
case 1:
- read();
+// read();
break;
// 鍐欐暟鎹� ID+鐩爣绔�
case 2:
@@ -246,13 +290,55 @@
}
// 蹇冭烦
// heartbeat();
- Thread.sleep(100);
+ Thread.sleep(400);
} catch (Exception e) {
- e.printStackTrace();
+// e.printStackTrace();
+ try{
+ log.error("dev鍐欑嚎绋嬪紓甯�"+e.getMessage());
+
+ } catch (Exception e1){
+
+ }
+ log.error("DEV鏁版嵁鍐欏叆绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+
}
}
+
}
+// @Override
+// @SuppressWarnings("InfiniteLoopStatement")
+// public void run() {
+// connect();
+// while (true) {
+// try {
+// int step = 1;
+// Task task = MessageQueue.poll(SlaveType.Devp, slave.getId());
+// if (task != null) {
+// step = task.getStep();
+// }
+// switch (step) {
+// // 璇绘暟鎹�
+// case 1:
+// read();
+// break;
+// // 鍐欐暟鎹� ID+鐩爣绔�
+// case 2:
+// write((StaProtocol)task.getData());
+// log.error("杈撻�佺嚎涓嬪彂鍛戒护锛�"+((StaProtocol) task.getData()).getWorkNo()+","+((StaProtocol) task.getData()).getStaNo());
+// break;
+// default:
+// break;
+// }
+// // 蹇冭烦
+//// heartbeat();
+// Thread.sleep(100);
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
+//
+// }
+// }
/**
* 鍒濆鍖栫珯鐐圭姸鎬�
*/
@@ -319,7 +405,7 @@
OperateResultExOne<byte[]> result4 = null;//1054-1079
OperateResultExOne<byte[]> result5 = null;//1080-1110
OperateResultExOne<byte[]> resultErr = null;
- if(staNoSize == 99){
+ if(staNoSize == 100){
result1 = siemensS7Net.Read("DB100.0", (short) (2768));//1001-1028
result2 = siemensS7Net.Read("DB101.0", (short) (1268));//1029-1037
result3 = siemensS7Net.Read("DB104.0", (short) (1268));//1042-1053
@@ -347,7 +433,7 @@
station.put(siteId, staProtocol);
}
staProtocol.setSiteId(siteId);
- if (staNoSize == 99) {
+ if (staNoSize == 100) {
if (siteId < 1029) {
result = result1;
} else if (siteId < 1042) {
@@ -406,18 +492,82 @@
boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, offset + offset3, 1);
staProtocol.setAutoing(!status[0]); // 鑷姩
boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result.Content, offset + offset3 - 4, 3);
-
- staProtocol.setLoading(!status1[0]); // 鏈夌墿
+ boolean[] statusErr = siemensS7Net.getByteTransform().TransBool(result.Content, offset + offset3 - 8, 3);
+ boolean loading = false;
+ if(!status1[0])
+ {
+ loading = true;
+ }
+ staProtocol.setLoading(loading); // 鏈夌墿
staProtocol.setInEnable(status1[2]); // 鍙叆
staProtocol.setOutEnable(status1[2]);// 鍙嚭
staProtocol.setErr(status1[6]);
-// staProtocol.setInEnable(status1[1]); // 鍙叆
-// staProtocol.setOutEnable(status1[3]);// 鍙嚭
-// staProtocol.setEmptyMk(status[4]); // 绌烘澘淇″彿
-// staProtocol.setFullPlt(status[5]); // 婊℃墭鐩�
-// staProtocol.setHigh(status[6]); // 楂樺簱浣�
-// staProtocol.setLow(status[7]); // 浣庡簱浣�
+
+ staProtocol.setPassTimeOut(statusErr[0]);
+ staProtocol.setObjectNoIdError(statusErr[1]);
+ staProtocol.setIdNoObjectError(statusErr[2]);
+ staProtocol.setLmfrError(statusErr[3]);
+ staProtocol.setLiftError(statusErr[4]);
+ staProtocol.setDlfrError(statusErr[5]);
+ staProtocol.setDmfrError(statusErr[6]);
+ staProtocol.setVfdError(statusErr[7]);
+ staProtocol.setSrvError(statusErr[8]);
+ staProtocol.setRes1(statusErr[9]);
+ staProtocol.setRes2(statusErr[10]);
+ staProtocol.setRes3(statusErr[11]);
+ staProtocol.setCommunicationTimeOut(statusErr[12]);
+ staProtocol.setParameterIncompleteError(statusErr[13]);
+ staProtocol.setDataNotClear(statusErr[14]);
+ staProtocol.setSetParameterError(statusErr[15]);
+ staProtocol.setRes4(statusErr[16]);
+ staProtocol.setRes5(statusErr[17]);
+ staProtocol.setDataError(statusErr[18]);
+
+ if( (staProtocol.getPassTimeOut() ||
+ staProtocol.getObjectNoIdError() ||
+ staProtocol.getIdNoObjectError() ||
+ staProtocol.getLmfrError() ||
+ staProtocol.getLiftError() ||
+ staProtocol.getDlfrError() ||
+ staProtocol.getDmfrError() ||
+ staProtocol.getVfdError() ||
+ staProtocol.getSrvError() ||
+ staProtocol.getRes1() ||
+ staProtocol.getRes2() ||
+ staProtocol.getRes3() ||
+ staProtocol.getCommunicationTimeOut() ||
+ staProtocol.getParameterIncompleteError() ||
+ staProtocol.getDataNotClear() ||
+ staProtocol.getSetParameterError() ||
+ staProtocol.getDataError()) && staProtocol.isWriteMk()
+ ){
+ staProtocol.setErrorMk(true);//鑻ュ瓨鍦ㄥ紓甯歌Е鍙戝啓鍏�
+ }
+
+ if( !staProtocol.getPassTimeOut() &&
+ !staProtocol.getObjectNoIdError() &&
+ !staProtocol.getIdNoObjectError() &&
+ !staProtocol.getLmfrError() &&
+ !staProtocol.getLiftError() &&
+ !staProtocol.getDlfrError() &&
+ !staProtocol.getDmfrError() &&
+ !staProtocol.getVfdError() &&
+ !staProtocol.getSrvError() &&
+ !staProtocol.getRes1() &&
+ !staProtocol.getRes2() &&
+ !staProtocol.getRes3() &&
+ !staProtocol.getCommunicationTimeOut() &&
+ !staProtocol.getParameterIncompleteError() &&
+ !staProtocol.getDataNotClear() &&
+ !staProtocol.getSetParameterError() &&
+ !staProtocol.getDataError()
+ ){
+ staProtocol.setWriteMk(true);//鏃犲紓甯稿悗鎵嶈兘缁х画鍐欏叆
+ staProtocol.setErrorMk(false);//鑻ュ瓨鍦ㄥ紓甯歌Е鍙戝啓鍏�
+
+ }
+
if (!staProtocol.isPakMk() && (!staProtocol.isLoading() || staProtocol.getWorkNo()==0)) {
staProtocol.setPakMk(true);
@@ -427,10 +577,12 @@
//鏉$爜鎵弿鍣�
ArrayList<Integer> barcodeList = getBarcodeList();
- OperateResultExOne<byte[]> reasultBarcode1 = siemensS7Net.Read("DB101.780", (short) 8);//1036
- OperateResultExOne<byte[]> reasultBarcode2 = siemensS7Net.Read("DB104.548", (short) 8);//1047
- OperateResultExOne<byte[]> reasultBarcode3 = siemensS7Net.Read("DB102.2780", (short) 8);//1103
- OperateResultExOne<byte[]> reasultBarcode4 = siemensS7Net.Read("DB201.344", (short) 8);
+ OperateResultExOne<byte[]> reasultBarcode1 = siemensS7Net.Read("DB101.780", (short) 4);//1036
+ OperateResultExOne<byte[]> reasultBarcode2 = siemensS7Net.Read("DB104.548", (short) 4);//1047
+ OperateResultExOne<byte[]> reasultBarcode3 = siemensS7Net.Read("DB102.2780", (short) 4);//1103
+ OperateResultExOne<byte[]> reasultBarcode4 = siemensS7Net.Read("DB201.344", (short) 4);//2037
+ OperateResultExOne<byte[]> reasultBarcode5 = siemensS7Net.Read("DB400.112", (short) 4);//4001
+
if(barcodeList.get(0) == 0){
if(reasultBarcode1.IsSuccess){
Integer barcodeId = barcodeList.get(0);
@@ -459,15 +611,22 @@
}
}
- }else{
+ }else if(barcodeList.get(0) == 3){
if(reasultBarcode4.IsSuccess){
Integer barcodeId = barcodeList.get(0);
- String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode3.Content, 0));
+ String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode4.Content, 0));
BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + +1);
if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
barcodeThread.setBarcode(barcode);
}
-
+ }
+ if(reasultBarcode5.IsSuccess){
+ Integer barcodeId = barcodeList.get(1);
+ String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode5.Content, 0));
+ BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + +1);
+ if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
+ barcodeThread.setBarcode(barcode);
+ }
}
}
@@ -482,12 +641,27 @@
for (Integer siteId : staNos) {
StaProtocol staProtocol = station.get(siteId);
basDevps.add(staProtocol.toSqlModel());
- }
+ if(staProtocol.isWriteMk() && staProtocol.isErrorMk()){
+ try {
+ // 鏃ュ織璁板綍寮傚父鎯呭喌
+ BasDevpErrorLog basDevpErrorLogs = new BasDevpErrorLog();
+ basDevpErrorLogs = staProtocol.toSqlModelError();
+ BasDevpErrorLogService basDevpErrorLogService = SpringUtils.getBean(BasDevpErrorLogService.class);
+ basDevpErrorLogService.insert(basDevpErrorLogs);
+ staProtocol.setWriteMk(false);
+ } catch (Exception ignore) {
+ log.error(ignore.getMessage());
+ }
+ }
+ }
BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
+
if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) {
throw new Exception("鏇存柊鏁版嵁搴撴暟鎹け璐�");
}
+
+
} catch (Exception e) {
initSite();
e.printStackTrace();
--
Gitblit v1.9.1