From b3280d431ea42f46afe020782b677b11d504be31 Mon Sep 17 00:00:00 2001
From: 1 <1>
Date: 星期三, 14 一月 2026 13:32:38 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SiemensDevpThread.java | 296 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 251 insertions(+), 45 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 87c8c2e..b605d29 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -84,12 +84,13 @@
add(2022);add(2024);
add(2028);add(2030);
add(2025);add(2027);
- add(2031);add(2033);
+ add(2031);add(2032);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(2121);add(2122);
add(4001);add(4003);add(4004);add(4006);
}};
@@ -165,17 +166,27 @@
put(2031, 120);put(2032, 124);put(2033, 128);put(2034, 132);put(2035, 136);
put(2037, 144);
- put(4001, 240);put(4002, 244);put(4003, 248);put(4004, 252);put(4005, 256);
- put(4006, 260);
+ put(2101, 160);put(2102, 164);put(2103, 168);put(2104, 172);put(2105, 176);
+ put(2106, 180);put(2107, 184);put(2108, 188);put(2109, 192);put(2110, 196);
+ put(2111, 200);put(2112, 204);put(2113, 208);put(2114, 212);put(2115, 216);
+ put(2116, 220);put(2117, 224);put(2118, 228);put(2119, 232);put(2120, 236);
+ put(2121, 240);put(2122, 244);
+ put(4001, 248);put(4002, 252);put(4003, 256);put(4004, 260);put(4005, 264);
+ put(4006, 268);
// 鍏朵粬绔欑偣鍚岀悊缁х画鍔�
}};
public static final Map<Integer, Integer> siteErrOffsetMap = new HashMap<Integer, Integer>() {{
- put(1036, 512);put(1103, 476);put(1047, 452);put(2037, 270);put(4001,294);
+ put(1036, 512);put(1103, 476);put(1047, 452);put(2037, 278);put(4001,302);
}};
public static final Map<Integer, Integer> siteAgvOffsetMap = new HashMap<Integer, Integer>() {{
put(1037, 0);put(1039, 2);put(1041, 4);put(2033, 0);put(2034,2);put(4003,4);put(4006,6);
+
+ }};
+
+ public static final Map<Integer, Integer> site2lBarcodeOffsetMap = new HashMap<Integer, Integer>() {{//2妤紁da鍐欏叆鏉$爜
+ put(2102, 2280);put(2105, 3048);put(2112, 4840);put(2115, 5608);
}};
@@ -486,12 +497,12 @@
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
- result6 = siemensS7Net.Read("DB202.0", (short) (7400));//2101-2122
- resultErr = siemensS7Net.Read("DB3.0", (short) (354));
+ result6 = siemensS7Net.Read("DB202.0", (short) (2024));//2101-2122
+ resultErr = siemensS7Net.Read("DB3.0", (short) (386));
// resultAgv = siemensS7Net.Read("DB901.0", (short) (7)); //agv鍙栨斁璐ц姹�
// resultPlc = siemensS7Net.Read("DB902.0", (short) (7)); //杈撻�佺嚎纭
- resultArm5 = siemensS7Net.Read("DB202.4328", (short) (254));//2110
- resultArm6 = siemensS7Net.Read("DB202.6888", (short) (254));//2120
+ resultArm5 = siemensS7Net.Read("DB202.4328", (short) (256));//2110
+ resultArm6 = siemensS7Net.Read("DB202.6888", (short) (256));//2120
}
@@ -527,23 +538,13 @@
} else if(siteId<4000){
if (siteId == 2110) {
if (resultArm5.IsSuccess) {
- // 杞崲涓哄瓧绗︿覆
- String resultString = siemensS7Net.getByteTransform().TransString(resultArm5.Content, 2, 252,"UTF-8");
- // 鍘婚櫎鍙兘鐨勭┖瀛楃
-// resultString = resultString.TrimEnd('\0');
-// System.out.println("2110Barcode:"+resultString);
- staProtocol.setBarcode(resultString);
+ staProtocol.setBarcode(parseS7String(resultArm5));
} else {
staProtocol.setBarcode("");
}
} else if (siteId == 2120){
if (resultArm6.IsSuccess) {
- // 杞崲涓哄瓧绗︿覆
- String resultString = siemensS7Net.getByteTransform().TransString(resultArm6.Content, 2, 252,"UTF-8");
- // 鍘婚櫎鍙兘鐨勭┖瀛楃
-// resultString = resultString.TrimEnd('\0');
-// System.out.println("2120Barcode:"+resultString);
- staProtocol.setBarcode(resultString);
+ staProtocol.setBarcode(parseS7String(resultArm6));
} else {
staProtocol.setBarcode("");
}
@@ -611,15 +612,17 @@
staProtocol.setAutoing(!status[0]); // 鑷姩
boolean[] status1 = siemensS7Net.getByteTransform().TransBool(result.Content, offset + offset3 - 4, 3);
boolean[] statusErr = siemensS7Net.getByteTransform().TransBool(result.Content, offset + offset3 - 8, 3);
-// boolean[] statusSign = siemensS7Net.getByteTransform().TransBool(resultErr.Content, offsetSign, 3);
-
+ boolean[] statusSign = siemensS7Net.getByteTransform().TransBool(resultErr.Content, offsetSign, 3);
boolean loading = false;
if(!status1[0])
{
loading = true;
}
staProtocol.setLoading(loading); // 鏈夌墿
+ if(siteId == 2032){
+ staProtocol.setLoading(loading); // 鏈夌墿
+ }
staProtocol.setInEnable(status1[2]); // 鍙叆
staProtocol.setOutEnable(status1[2]);// 鍙嚭
staProtocol.setErr(status1[6]);
@@ -665,28 +668,28 @@
staProtocol.setDataError(statusErr[18]);
//淇″彿
-// staProtocol.setSensorGArrive(statusSign[0]);
-// staProtocol.setSensorGDec(statusSign[1]);
-// staProtocol.setSensorGArrive2(statusSign[2]);
-// staProtocol.setSensorLimit(statusSign[3]);
-// staProtocol.setEmergency(statusSign[4]);
-// staProtocol.setSensorGLeave(statusSign[5]);
-// staProtocol.setSensorGLeave2(statusSign[6]);
-// staProtocol.setSensorCUp(statusSign[7]);
-// staProtocol.setSensorCDown(statusSign[8]);
-// staProtocol.setLiftMotorFr(statusSign[9]);
-// staProtocol.setLineMotorFr(statusSign[10]);
-// staProtocol.setTranMotorFr(statusSign[11]);
-// staProtocol.setRst1(statusSign[12]);
-// staProtocol.setRst2(statusSign[13]);
-// staProtocol.setRst3(statusSign[14]);
-// staProtocol.setRst4(statusSign[15]);
-// staProtocol.setSensorArriveD(statusSign[16]);
-// staProtocol.setSensorDecD(statusSign[17]);
-// staProtocol.setSensorArriveL(statusSign[18]);
-// staProtocol.setSensorDecL(statusSign[19]);
-// staProtocol.setSensorArriveR(statusSign[20]);
-// staProtocol.setSensorDecR(statusSign[21]);
+ staProtocol.setSensorGArrive(statusSign[0]);
+ staProtocol.setSensorGDec(statusSign[1]);
+ staProtocol.setSensorGArrive2(statusSign[2]);
+ staProtocol.setSensorLimit(statusSign[3]);
+ staProtocol.setEmergency(statusSign[4]);
+ staProtocol.setSensorGLeave(statusSign[5]);
+ staProtocol.setSensorGLeave2(statusSign[6]);
+ staProtocol.setSensorCUp(statusSign[7]);
+ staProtocol.setSensorCDown(statusSign[8]);
+ staProtocol.setLiftMotorFr(statusSign[9]);
+ staProtocol.setLineMotorFr(statusSign[10]);
+ staProtocol.setTranMotorFr(statusSign[11]);
+ staProtocol.setRst1(statusSign[12]);
+ staProtocol.setRst2(statusSign[13]);
+ staProtocol.setRst3(statusSign[14]);
+ staProtocol.setRst4(statusSign[15]);
+ staProtocol.setSensorArriveD(statusSign[16]);
+ staProtocol.setSensorDecD(statusSign[17]);
+ staProtocol.setSensorArriveL(statusSign[18]);
+ staProtocol.setSensorDecL(statusSign[19]);
+ staProtocol.setSensorArriveR(statusSign[20]);
+ staProtocol.setSensorDecR(statusSign[21]);
// Integer offsetAgv = siteAgvOffsetMap.get(siteId);
//
@@ -843,6 +846,9 @@
for (Integer siteId : staNos) {
StaProtocol staProtocol = station.get(siteId);
basDevps.add(staProtocol.toSqlModel());
+ if(siteId == 2110){
+ basDevps.add(staProtocol.toSqlModel());
+ }
if(staProtocol.isWriteMk() && staProtocol.isErrorMk()){
try {
// 鏃ュ織璁板綍寮傚父鎯呭喌
@@ -937,7 +943,7 @@
}else{
write1 = siemensS7Net.Write("DB200." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 鐩爣绔�
}
- }else if(siteId < 4000){
+ }else if(siteId < 2121){
write = siemensS7Net.Write("DB201." + (offset + offset2), staProtocol.getWorkNo()); // 宸ヤ綔鍙�
Thread.sleep(200);
if(specialSites2.contains(siteId)){
@@ -945,6 +951,11 @@
}else{
write1 = siemensS7Net.Write("DB201." + (offset + offset2 + 12), staProtocol.getStaNo().intValue()); // 鐩爣绔�
}
+ } else if(siteId < 4000){
+ Integer offsetBarcode = site2lBarcodeOffsetMap.get(siteId);
+ write = siemensS7Net.Write("DB202." + offsetBarcode, staProtocol.getBarcode()); // 鏉$爜
+ write1 = siemensS7Net.Write("DB202." + offsetBarcode, staProtocol.getBarcode());
+ Thread.sleep(200);
}else{
write = siemensS7Net.Write("DB400." + (offset + offset2), staProtocol.getWorkNo()); // 宸ヤ綔鍙�
Thread.sleep(200);
@@ -999,6 +1010,168 @@
News.info("SiemensDevp"+" - 5"+" - 杈撻�佺嚎鍛戒护涓嬪彂 [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}", slave.getId(), JSON.toJSON(staProtocol));
}
}
+// /**
+// * 鍐欏叆 ID + 鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏ワ紙甯﹁鍥炴牎楠� + 閲嶈瘯鏈哄埗锛�
+// */
+// private void write(StaProtocol staProtocol) throws InterruptedException {
+// if (staProtocol == null) {
+// return;
+// }
+//
+// Integer siteId = staProtocol.getSiteId();
+// Integer offset = siteOffsetMap.get(siteId);
+// if (offset == null) {
+// log.warn("绔欑偣 {} 娌℃湁瀹氫箟鍋忕Щ閲忥紝璺宠繃鍐欏叆", siteId);
+// return;
+// }
+//
+// Integer offset2 = getOffsetBySiteId(siteId);
+// Integer offset3 = getOffsetBySiteId2(siteId); // 铏界劧鏈柟娉曚富瑕佺敤涓嶅埌锛屼絾淇濈暀浠ラ槻鍚庣画鎵╁睍
+//
+// // 鍑嗗鏈熸湜鍐欏叆鐨勫�硷紙鐢ㄤ簬鍚庣画姣斿锛�
+// final long expectWorkNo = staProtocol.getWorkNo();
+// final long expectStaNo = staProtocol.getStaNo() != null ? staProtocol.getStaNo().intValue() : 0;
+//
+// boolean isSpecial2 = specialSites2.contains(siteId);
+// final long expectStaNoOffset = isSpecial2 ? (offset + offset2 + 48) : (offset + offset2 + 12);
+//
+// // 纭畾瑕佹搷浣滅殑 DB 鍧�
+// String dbName;
+// if (siteId < 1029) {
+// dbName = "DB100.";
+// } else if (siteId < 1042) {
+// dbName = "DB101.";
+// } else if (siteId < 1054) {
+// dbName = "DB104.";
+// } else if (siteId < 1080) {
+// dbName = "DB103.";
+// } else if (siteId < 1111) {
+// dbName = "DB102.";
+// } else if (siteId < 2031) {
+// dbName = "DB200.";
+// } else if (siteId < 2121) {
+// dbName = "DB201.";
+// } else if (siteId < 4000) {
+// // 2妤糚DA鏉$爜绔欑偣鐗规畩澶勭悊锛堢洰鍓嶄笉鍋氳鍥為噸璇曪級
+// Integer offsetBarcode = site2lBarcodeOffsetMap.get(siteId);
+// if (offsetBarcode == null) {
+// log.warn("绔欑偣 {} 娌℃湁瀹氫箟2妤兼潯鐮佸亸绉婚噺锛岃烦杩囨潯鐮佸啓鍏�", siteId);
+// return;
+// }
+// OperateResult writeBarcode = siemensS7Net.Write("DB202." + offsetBarcode, staProtocol.getBarcode());
+// if (writeBarcode.IsSuccess) {
+// log.info("2妤糚DA鏉$爜鍐欏叆鎴愬姛 site={}, barcode={}", siteId, staProtocol.getBarcode());
+// } else {
+// log.error("2妤糚DA鏉$爜鍐欏叆澶辫触 site={}, barcode={}", siteId, staProtocol.getBarcode());
+// }
+// return;
+// } else {
+// dbName = "DB400.";
+// }
+//
+// String addrWorkNo = dbName + (offset + offset2);
+// String addrStaNo = dbName + expectStaNoOffset;
+//
+// int maxRetry = 5;
+// int tryCount = 0;
+// boolean success = false;
+//
+// while (tryCount < maxRetry && !success) {
+// tryCount++;
+//
+// // 1. 灏濊瘯鍐欏叆
+// OperateResult writeWork = siemensS7Net.Write(addrWorkNo, expectWorkNo);
+// writeWork = siemensS7Net.Write("DB100." + (offset + offset2), staProtocol.getWorkNo()); // 宸ヤ綔鍙�
+//
+// Thread.sleep(80);
+//
+// OperateResult writeSta = siemensS7Net.Write(addrStaNo, expectStaNo);
+// Thread.sleep(120);
+//
+// if (!writeWork.IsSuccess || !writeSta.IsSuccess) {
+// log.warn("绗瑊}娆″啓鍏ュけ璐� site={}, workNo={}, targetSta={}",
+// tryCount, siteId, expectWorkNo, expectStaNo);
+// Thread.sleep(300);
+// continue;
+// }
+//
+// // 2. 璇诲洖鏍¢獙锛堣嚦灏戣64瀛楄妭锛岀‘淇濊鐩栨墍闇�瀛楁锛�
+// OperateResultExOne<byte[]> readResult = siemensS7Net.Read(dbName + (offset + offset2), (short) 64);
+// if (!readResult.IsSuccess || readResult.Content == null || readResult.Content.length < 64) {
+// log.warn("绗瑊}娆¤鍥炲け璐ワ紝鏃犳硶鏍¢獙 site={}", tryCount, siteId);
+// Thread.sleep(300);
+// continue;
+// }
+//
+// byte[] data = readResult.Content;
+//
+// // 璁$畻鐩稿鍋忕Щ杩涜璇诲彇
+// int relativeWorkNoOffset = 0;
+// int relativeStaNoOffset = (int) (expectStaNoOffset - (offset + offset2));
+//
+// int actualWorkNo = siemensS7Net.getByteTransform().TransInt32(data, relativeWorkNoOffset);
+// int actualStaNo = siemensS7Net.getByteTransform().TransInt32(data, relativeStaNoOffset);
+//
+// boolean match = (actualWorkNo == expectWorkNo) && (actualStaNo == expectStaNo);
+//
+// if (match) {
+// success = true;
+// log.info("鍐欏叆骞舵牎楠屾垚鍔� site={}, workNo={}, targetSta={}, 绗瑊}娆″皾璇�",
+// siteId, expectWorkNo, expectStaNo, tryCount);
+// } else {
+// log.warn("绗瑊}娆℃牎楠屽け璐� site={}, 鏈熸湜[workNo={},staNo={}], 瀹為檯[workNo={},staNo={}]",
+// tryCount, siteId, expectWorkNo, expectStaNo, actualWorkNo, actualStaNo);
+// Thread.sleep(300);
+// }
+// }
+//
+// // 鏈�缁堢粨鏋滃鐞�
+// if (success) {
+// log.info("杈撻�佺嚎鍛戒护涓嬪彂骞舵牎楠屾垚鍔� [plc:{}] site:{} workNo:{} target:{}",
+// slave.getId(), siteId, expectWorkNo, expectStaNo);
+//
+// OutputQueue.DEVP.offer(MessageFormat.format(
+// "銆恵0}銆戣緭閫佺嚎鍛戒护涓嬪彂骞舵牎楠屾垚鍔� [id:{1}] >>>>> site:{2} workNo:{3} target:{4}",
+// DateUtils.convert(new Date()), slave.getId(), siteId, expectWorkNo, expectStaNo));
+//
+// News.info("SiemensDevp - 5 - 杈撻�佺嚎鍛戒护涓嬪彂骞舵牎楠屾垚鍔� [id:{}] >>>>> {}",
+// slave.getId(), JSON.toJSON(staProtocol));
+// } else {
+// log.error("缁忚繃{}娆″皾璇曪紝鍐欏叆骞舵牎楠屼粛鐒跺け璐ワ紒plc={} site={} workNo棰勬湡={} target棰勬湡={}",
+// maxRetry, slave.getId(), siteId, expectWorkNo, expectStaNo);
+//
+// OutputQueue.DEVP.offer(MessageFormat.format(
+// "銆恵0}銆戠粡杩噞1}娆″皾璇曪紝杈撻�佺嚎鍐欏叆鏍¢獙澶辫触锛� [id:{2}] site:{3} workNo:{4} target:{5}",
+// DateUtils.convert(new Date()), maxRetry, slave.getId(), siteId, expectWorkNo, expectStaNo));
+//
+// News.error("SiemensDevp - 4 - 澶氭灏濊瘯鍚庡啓鍏ユ牎楠屽け璐ワ紒site={} workNo={} target={}",
+// siteId, expectWorkNo, expectStaNo);
+// }
+//
+// // 鎿嶄綔鏃ュ織璁板綍锛堟棤璁烘垚鍔熷け璐ラ兘璁板綍锛�
+// 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,
+// staProtocol.getErrCode()
+// );
+// bean.insert(basDevpOpt);
+// } catch (Exception e) {
+// log.warn("鍐欏叆鎿嶄綔鏃ュ織澶辫触 site={}", siteId, e);
+// }
+// }
// 鏇存柊鍏ュ嚭搴撴ā寮�
private void updateIoMode() throws InterruptedException {
@@ -1052,6 +1225,39 @@
}
}
+ private String parseS7String(OperateResultExOne<byte[]> result) {
+
+ if (result == null || !result.IsSuccess || result.Content == null) {
+ return "";
+ }
+
+ byte[] buf = result.Content;
+
+ if (buf.length < 2) {
+ return "";
+ }
+
+ // S7 瀛楃涓叉牸寮忥細
+ // buf[0] = 鏈�澶ч暱搴�
+ // buf[1] = 褰撳墠鐪熷疄闀垮害
+ int realLen = buf[1] & 0xFF;
+
+ if (realLen <= 0) {
+ return "";
+ }
+
+ // 闃叉 PLC 鍐欓敊闀垮害瀵艰嚧瓒婄晫
+ if (realLen > buf.length - 2) {
+ realLen = buf.length - 2;
+ }
+
+ String value = siemensS7Net.getByteTransform()
+ .TransString(buf, 2, realLen, "UTF-8");
+
+ return value == null ? "" : value.trim();
+ }
+
+
/**
* 璁剧疆鍏ュ簱鏍囪
*/
--
Gitblit v1.9.1