From 6fcad8a10aab91b9a0825b0465b7e21d37df2332 Mon Sep 17 00:00:00 2001
From: 1 <1>
Date: 星期三, 22 十月 2025 11:53:13 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SiemensDevpThread.java | 353 +++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 285 insertions(+), 68 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index f146152..56b2d9b 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -10,9 +10,13 @@
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.common.utils.News;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
@@ -77,13 +81,14 @@
add(2016);add(2018);
add(2019);add(2021);
add(2022);add(2024);
+ add(2028);add(2030);
add(2025);add(2027);
add(2031);add(2033);
add(2034);add(2035);add(2037);
- add(2041);add(2042);add(2043);add(2044);
- 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(2041);add(2042);add(2043);add(2044);
+// 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);
}};
@@ -107,22 +112,32 @@
put(1101, 2508);put(1102, 2600);put(1103, 2692);put(1104, 2784);put(1105, 2876);
put(1106, 2968);put(1107, 3060);put(1108, 3152);put(1109, 3244);put(1110, 3336);
+ put(2001, 392);put(2002, 116);put(2003, 208);put(2004, 0);put(2005, 300);
+ put(2006, 508);put(2007, 692);put(2008, 600);put(2009, 808);put(2010, 992);
+ put(2011, 900);put(2012, 1108);put(2013, 1500);put(2014, 1292);put(2015, 1200);
+ put(2016, 1384);put(2017, 1616);put(2018, 1708);put(2019, 1800);put(2020, 1916);
+ put(2021, 2008);put(2022, 2100);put(2023, 2216);put(2024, 2308);put(2025, 2400);
+ put(2026, 2516);put(2027, 2608);put(2028, 2792);put(2029, 2700);put(2030, 2908);
+ put(2031, 464);put(2032, 348);put(2033, 556);put(2034, 92);put(2035, 0);
+ put(2037, 256);
+ put(4001, 0);put(4002, 116);put(4003, 508);put(4004, 392);put(4005, 300);
+ put(4006, 208);
// 鍏朵粬绔欑偣鍚岀悊缁х画鍔�
}};
public static final Map<Integer, Integer> siteErrOffsetMap = new HashMap<Integer, Integer>() {{
- put(1036, 512);put(1103, 476);put(1047, 452);
+ 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));
+ 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<>(
- Arrays.asList(1051,1055,1057,1065,1067,1069,1077,1081,1083,1086,1089,1092,1095,1097,1100));
+ Arrays.asList(1051,1055,1057,1065,1067,1069,1077,1081,1083,1086,1089,1092,1095,1097,1100,2034));
private static final Set<Integer> specialSites3 = new HashSet<>(//鏈烘鑷傜珯鐐�
Arrays.asList(1098,1093,1087,1082,1074,1071,1061,1058));
@@ -131,11 +146,11 @@
public static final ArrayList<Integer> BarcodeList = new ArrayList<Integer>() {{
add(0); add(1); add(2);
}};
- public static final ArrayList<Integer> BarcodeListMat = new ArrayList<Integer>() {{
- add(3); add(4);
+ public static final ArrayList<Integer> BarcodeList2 = new ArrayList<Integer>() {{
+ 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;
@@ -154,9 +169,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;
}
@@ -194,10 +209,71 @@
}
}
+ private ArrayList<Integer> getBarcodeList() {
+ switch (slave.getId()) {
+ case 1:
+ return BarcodeList;
+ case 2:
+ return BarcodeList2;
+ default:
+ 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;
@@ -208,7 +284,7 @@
switch (step) {
// 璇绘暟鎹�
case 1:
- read();
+// read();
break;
// 鍐欐暟鎹� ID+鐩爣绔�
case 2:
@@ -220,13 +296,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();
+// }
+//
+// }
+// }
/**
* 鍒濆鍖栫珯鐐圭姸鎬�
*/
@@ -250,7 +368,7 @@
staProtocol.setEmptyMk(false); // 绌烘澘淇″彿
staProtocol.setStaNo((short) 0); // 鐩爣绔�
- if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
+ if (!staProtocol.isPakMk() && staProtocol.isLoading()) {
staProtocol.setPakMk(true);
}
}
@@ -287,12 +405,27 @@
ArrayList<Integer> staNos = getStaNo();
int staNoSize = staNos.size();
OperateResultExOne<byte[]> result = null;
- OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB100.0", (short) (2768));//1001-1028
- OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.0", (short) (1268));//1029-1037
- OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB104.0", (short) (1268));//1042-1053
- OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB103.0", (short) (2824));//1054-1079
- OperateResultExOne<byte[]> result5 = siemensS7Net.Read("DB102.0", (short) (3428));//1080-1110
- OperateResultExOne<byte[]> resultErr = siemensS7Net.Read("DB3.0", (short) (536));//1080-1110
+ OperateResultExOne<byte[]> result1 = null;
+ OperateResultExOne<byte[]> result2 = null;//1029-1037
+ OperateResultExOne<byte[]> result3 = null;//1042-1053
+ OperateResultExOne<byte[]> result4 = null;//1054-1079
+ OperateResultExOne<byte[]> result5 = null;//1080-1110
+ OperateResultExOne<byte[]> resultErr = null;
+ if(staNoSize == 99){
+ 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
+ result4 = siemensS7Net.Read("DB103.0", (short) (2824));//1054-1079
+ result5 = siemensS7Net.Read("DB102.0", (short) (3428));//1080-1110
+ resultErr = siemensS7Net.Read("DB3.0", (short) (536));
+ }else{
+ result1 = siemensS7Net.Read("DB200.0", (short) (3000));//2001-2030
+ result2 = siemensS7Net.Read("DB201.0", (short) (720));//2031-2037
+ result3 = siemensS7Net.Read("DB400.0", (short) (600));//4001-4006
+ resultErr = siemensS7Net.Read("DB3.0", (short) (354));
+
+ }
+
@@ -305,16 +438,27 @@
staProtocol.setSiteId(siteId);
station.put(siteId, staProtocol);
}
- if(siteId < 1029){
- result = result1;
- }else if(siteId < 1042){
- result = result2;
- }else if(siteId < 1054){
- result = result3;
- }else if(siteId < 1080){
- result = result4;
- }else if(siteId < 1111){
- result = result5;
+ staProtocol.setSiteId(siteId);
+ if (staNoSize == 99) {
+ if (siteId < 1029) {
+ result = result1;
+ } else if (siteId < 1042) {
+ result = result2;
+ } else if (siteId < 1054) {
+ result = result3;
+ } else if (siteId < 1080) {
+ result = result4;
+ } else if (siteId < 1111) {
+ result = result5;
+ }
+ }else{
+ if (siteId < 2031) {
+ result = result1;
+ } else if (siteId < 4001) {
+ result = result2;
+ } else {
+ result = result3;
+ }
}
// 鑾峰彇璇ョ珯鐐瑰搴旂殑鍋忕Щ閲�
Integer offset = siteOffsetMap.get(siteId);
@@ -354,8 +498,14 @@
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 + 54, 1);
+ boolean loading = false;
+ if(!status1[0])
+// && statusErr[2])
+ {
+ loading = true;
+ }
+ staProtocol.setLoading(loading); // 鏈夌墿
staProtocol.setInEnable(status1[2]); // 鍙叆
staProtocol.setOutEnable(status1[2]);// 鍙嚭
@@ -367,46 +517,65 @@
// staProtocol.setHigh(status[6]); // 楂樺簱浣�
// staProtocol.setLow(status[7]); // 浣庡簱浣�
- if (!staProtocol.isPakMk() && (!staProtocol.isLoading() || !staProtocol.isInEnable())) {
+ if (!staProtocol.isPakMk() && (!staProtocol.isLoading() || staProtocol.getWorkNo()==0)) {
staProtocol.setPakMk(true);
}
}
}
//鏉$爜鎵弿鍣�
- ArrayList<Integer> barcodeList = BarcodeList;
- 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("DB104.180", (short) 184);
- if(reasultBarcode1.IsSuccess){
- Integer barcodeId = barcodeList.get(0);
- String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode1.Content, 0));
- BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1);
- if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
- barcodeThread.setBarcode(barcode);
- }
-// News.error(JSON.toJSONString(barcode+"绾跨▼"+barcodeId));
- }
- if(reasultBarcode2.IsSuccess){
- Integer barcodeId = barcodeList.get(1);
- String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode2.Content, 0));
- BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1);
- if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
- barcodeThread.setBarcode(barcode);
- }
-// News.error(JSON.toJSONString(barcode+"绾跨▼"+barcodeId));
+ ArrayList<Integer> barcodeList = getBarcodeList();
+ 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(reasultBarcode3.IsSuccess){
- Integer barcodeId = barcodeList.get(2);
- String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode3.Content, 0));
- BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1);
- if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
- barcodeThread.setBarcode(barcode);
- }
-// News.error(JSON.toJSONString(barcode+"绾跨▼"+barcodeId));
+ if(barcodeList.get(0) == 0){
+ if(reasultBarcode1.IsSuccess){
+ Integer barcodeId = barcodeList.get(0);
+ String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode1.Content, 0));
+ BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1);
+ if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
+ barcodeThread.setBarcode(barcode);
+ }
+ }
+ if(reasultBarcode2.IsSuccess){
+ Integer barcodeId = barcodeList.get(1);
+ String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode2.Content, 0));
+ BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1);
+ if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
+ barcodeThread.setBarcode(barcode);
+ }
+
+ }
+ if(reasultBarcode3.IsSuccess){
+ Integer barcodeId = barcodeList.get(2);
+ String barcode = String.valueOf(siemensS7Net.getByteTransform().TransInt32(reasultBarcode3.Content, 0));
+ BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, barcodeId + 1);
+ if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
+ barcodeThread.setBarcode(barcode);
+ }
+
+ }
+ }else if(barcodeList.get(0) == 3){
+ if(reasultBarcode4.IsSuccess){
+ Integer barcodeId = barcodeList.get(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);
+ }
+ }
}
@@ -490,7 +659,32 @@
write1 = siemensS7Net.Write("DB102." + (offset + offset2 + 48), staProtocol.getStaNo().intValue()); // 鐩爣绔�
}else{
write1 = siemensS7Net.Write("DB102." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 鐩爣绔�
- } }
+ }
+ }else if(siteId < 2031){
+ write = siemensS7Net.Write("DB200." + (offset + offset2), staProtocol.getWorkNo()); // 宸ヤ綔鍙�
+ Thread.sleep(200);
+ if(specialSites2.contains(siteId)){
+ write1 = siemensS7Net.Write("DB200." + (offset + offset2 + 48), staProtocol.getStaNo().intValue()); // 鐩爣绔�
+ }else{
+ write1 = siemensS7Net.Write("DB200." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 鐩爣绔�
+ }
+ }else if(siteId < 4000){
+ write = siemensS7Net.Write("DB201." + (offset + offset2), staProtocol.getWorkNo()); // 宸ヤ綔鍙�
+ Thread.sleep(200);
+ if(specialSites2.contains(siteId)){
+ write1 = siemensS7Net.Write("DB201." + (offset + offset2 + 48), staProtocol.getStaNo().intValue()); // 鐩爣绔�
+ }else{
+ write1 = siemensS7Net.Write("DB201." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 鐩爣绔�
+ }
+ }else{
+ write = siemensS7Net.Write("DB400." + (offset + offset2), staProtocol.getWorkNo()); // 宸ヤ綔鍙�
+ Thread.sleep(200);
+ if(specialSites2.contains(siteId)){
+ write1 = siemensS7Net.Write("DB400." + (offset + offset2 + 48), staProtocol.getStaNo().intValue()); // 鐩爣绔�
+ }else{
+ write1 = siemensS7Net.Write("DB400." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 鐩爣绔�
+ }
+ }
if(write.IsSuccess && write1.IsSuccess){
log.error("鍐欏叆杈撻�佺嚎鍛戒护鎴愬姛銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
break;
@@ -500,6 +694,29 @@
log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
}
}while (writeCount<5);
+ try {
+ // 鏃ュ織璁板綍
+ BasDevpOptService bean = SpringUtils.getBean(BasDevpOptService.class);
+ BasDevpOpt basDevpOpt = new BasDevpOpt(
+ staProtocol.getWorkNo(),
+ new Date(),
+ staProtocol.getSiteId(),
+ (int)staProtocol.getStaNo(),
+ new Date(),
+ String.valueOf(staProtocol.isLoading()),
+ staProtocol.getBarcode(),
+ staProtocol.isFrontErr()? 1L:0L,
+ staProtocol.isBackErr()? 1L:0L,
+ staProtocol.isHighErr()? 1L:0L,
+ staProtocol.isLeftErr()? 1L:0L,
+ staProtocol.isRightErr()? 1L:0L,
+ staProtocol.isBarcodeErr()? 1L:0L
+
+ );
+ bean.insert(basDevpOpt);
+ } catch (Exception ignore) {
+ log.error(ignore.getMessage());
+ }
if (!write.IsSuccess) {
staProtocol = station.get(staProtocol.getSiteId());
--
Gitblit v1.9.1