From 0c5db9c4a128999d58e1a300b21a757b04908ada Mon Sep 17 00:00:00 2001
From: yxFwq <1>
Date: 星期一, 21 十月 2024 09:34:56 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SiemensDevpThread.java | 168 +++++++++++++++++++++++++++++++++++--------------------
1 files changed, 106 insertions(+), 62 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 089e61e..1d2f54c 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -133,7 +133,7 @@
/**
* 鏉$爜鏁伴噺
*/
- private int barcodeSize = 9;
+ private int barcodeSize = 5;
/**
* 鍏ュ嚭搴撴ā寮�
@@ -207,6 +207,8 @@
case 11:
write11((StaProtocol)task.getData());
break;
+ case 99:
+ write99((Integer) task.getData());
default:
break;
}
@@ -316,6 +318,7 @@
staProtocol.setEndRow(siemensS7Net.getByteTransform().TransInt16(resultRgv2.Content, 0)); // 灏忚溅鐩爣浣�
staProtocol.setNowRow(siemensS7Net.getByteTransform().TransInt16(resultRgv.Content, 2)); // 褰撳墠浣嶇疆
+// staProtocol.setNowRow((short)2); // 褰撳墠浣嶇疆
boolean[] status = siemensS7Net.getByteTransform().TransBool(resultRgv.Content, 4, 1);
staProtocol.setRGV1(status[0]); // 灏忚溅鏃犺揣绌洪棽
@@ -351,11 +354,15 @@
Thread.sleep(200);
OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.2440",(short)(barcodeSize*8));
if (result2.IsSuccess) {
- int[] staNosRgv = {281,292,173,214,120,100,101,102,103};
-
- for (int i = 0; i < barcodeSize; i++) { //1:281 2:292 3:174(173) 4:214 5:120
+ int[] staNosRgv = new int[]{281,292,173,214,120};
+ if (slave.getId()==2){
+ staNosRgv = new int[]{453,460,518,532,607};
+ }
+ for (int i = 0; i < barcodeSize; i++) {
+ //1:281 2:292 3:174(173) 4:214 5:120
+ //6:453 7:460 8:508 9:534 10:611
String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8");
- BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
+ BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, (i + 1+((slave.getId()-1)*5)));
if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
Integer siteId = staNosRgv[i]; // 绔欑偣缂栧彿
StaProtocol staProtocol = station.get(siteId);
@@ -368,19 +375,34 @@
}
}
- //RGV灏忚溅
- Thread.sleep(200);
- OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB100.160",(short)2);
- if (result3.IsSuccess) {
- Integer siteId = 2000;
- StaProtocol staProtocol = station.get(siteId);
- if (null == staProtocol) {
- staProtocol = new StaProtocol();
- staProtocol.setSiteId(siteId);
- station.put(siteId, staProtocol);
+ if (slave.getId()==2){
+ OperateResultExOne<byte[]> result464 = siemensS7Net.Read("DB101.3720",(short)(8));
+ if (result464.IsSuccess) {
+ String barcode = siemensS7Net.getByteTransform().TransString(result464.Content,0,8, "UTF-8");
+ BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 11);
+ if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
+ StaProtocol staProtocol = station.get(464);
+ if (null != staProtocol) {
+ staProtocol.setBarcode(barcode);
+ barcodeThread.setBarcode(barcode);
+ }
+ }
}
- staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result3.Content, 0)));
}
+
+// //RGV灏忚溅
+// Thread.sleep(200);
+// OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB100.160",(short)2);
+// if (result3.IsSuccess) {
+// Integer siteId = 2000;
+// StaProtocol staProtocol = station.get(siteId);
+// if (null == staProtocol) {
+// staProtocol = new StaProtocol();
+// staProtocol.setSiteId(siteId);
+// station.put(siteId, staProtocol);
+// }
+// staProtocol.setNearbySta(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result3.Content, 0)));
+// }
if (result.IsSuccess) {
@@ -394,9 +416,13 @@
basDevps.add(staProtocol.toSqlModel());
}
- BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
- if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) {
- throw new Exception("鏇存柊鏁版嵁搴撴暟鎹け璐�");
+ try{
+ BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
+ if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) {
+ throw new Exception("鏇存柊鏁版嵁搴撴暟鎹け璐�");
+ }
+ } catch (Exception e){
+ log.error("鏇存柊鏁版嵁搴撴暟鎹け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
}
} catch (Exception e) {
e.printStackTrace();
@@ -464,26 +490,8 @@
Integer siteId = staProtocol.getSiteId();
Integer index =0;
switch (siteId){
- case 118:
+ case 607:
index=0;
- break;
- case 119:
- index=1;
- break;
- case 120:
- index=2;
- break;
- case 121:
- index=3;
- break;
- case 131:
- index=4;
- break;
- case 135:
- index=5;
- break;
- case 147:
- index=6;
break;
default:
return;
@@ -493,7 +501,7 @@
//浠诲姟涓嬪彂娆℃暟
int writeCount = 0;
do {
- write = siemensS7Net.Write("DB100.600." + index, true); // 浠诲姟瀹屾垚
+ write = siemensS7Net.Write("DB100.1872", (short) 1); // 浠诲姟瀹屾垚
if(write.IsSuccess){
writeCount=6;
}else {
@@ -522,26 +530,8 @@
Integer siteId = staProtocol.getSiteId();
Integer index =0;
switch (siteId){
- case 118:
+ case 607:
index=0;
- break;
- case 119:
- index=1;
- break;
- case 120:
- index=2;
- break;
- case 121:
- index=3;
- break;
- case 131:
- index=4;
- break;
- case 135:
- index=5;
- break;
- case 147:
- index=6;
break;
default:
return;
@@ -551,10 +541,10 @@
//浠诲姟涓嬪彂娆℃暟
int writeCount = 0;
do {
- write = siemensS7Net.Write("DB100.600." + index, false); // 浠诲姟瀹屾垚澶嶄綅
+ write = siemensS7Net.Write("DB100.1872", (short) 0); // 浠诲姟瀹屾垚澶嶄綅
if(write.IsSuccess){
writeCount=6;
- }else {
+ } else {
writeCount++;
log.error("鍐欏叆杈撻�佺嚎鍛戒护鍚庤鍙栧け璐ャ�傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
}
@@ -968,7 +958,60 @@
}
}
- // 鏇存柊鍏ュ嚭搴撴ā寮�
+ private void write99(Integer devNo) throws InterruptedException {
+ String resultV1 = "";
+ switch (devNo){
+ case 1:
+ resultV1 = "DB500.0.0";
+ break;
+ case 2:
+ resultV1 = "DB500.0.1";
+ break;
+ case 3:
+ resultV1 = "DB500.0.2";
+ break;
+ default:
+ return;
+ }
+ OperateResult result = siemensS7Net.Write(resultV1, true);
+ Integer writeCount = 0;
+ do {
+ try{
+ if(!result.IsSuccess){
+ log.error("鍐欏叆RGV鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔� 鍐欏叆鐩存帴澶辫触 ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSONString(devNo),writeCount);
+ result = siemensS7Net.Write(resultV1, true);
+ Thread.sleep(100);
+ writeCount++;
+ continue;
+ }
+ OperateResultExOne<byte[]> resultRead1 = siemensS7Net.Read("resultV1", (short) 1);
+ if (resultRead1.IsSuccess) {
+ boolean[] status = siemensS7Net.getByteTransform().TransBool(resultRead1.Content, 0, 1);
+ if (status[devNo-1]){
+ break;
+ } else {
+ log.error("鍐欏叆RGV鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔� 鍐欏叆鐩存帴澶辫触 ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSONString(devNo),writeCount);
+ result = siemensS7Net.Write(resultV1, true);
+ Thread.sleep(100);
+ writeCount++;
+ continue;
+ }
+ } else {
+ log.error("鍐欏叆RGV鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔� 鍐欏叆鐩存帴澶辫触 ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSONString(devNo),writeCount);
+ result = siemensS7Net.Write(resultV1, true);
+ Thread.sleep(100);
+ writeCount++;
+ continue;
+ }
+ }catch (Exception e){
+ log.error("鍐欏叆鏁版嵁鍚庡洖璇诲嚭閿�,寮傚父锛�"+e);
+ }
+ writeCount++;
+ } while (writeCount<6);
+ }
+
+
+ // 鏇存柊鍏ュ嚭搴撴ā寮�
private void updateIoMode() throws InterruptedException {
if (this.ioModeOf2F != IoModeType.NONE) {
if (!siemensS7Net.Write("DB100.180", this.ioModeOf2F.id).IsSuccess) {
@@ -997,9 +1040,10 @@
* 璁剧疆鍏ュ簱鏍囪
*/
@Override
- public void setPakMk(Integer siteId, boolean pakMk) {
+ public void setPakMk(Integer siteId, boolean pakMk,Integer i) {
StaProtocol staProtocol = station.get(siteId);
if (null != staProtocol) {
+ log.info("閿佸畾鍏ュ簱鏍囪锛岀珯鐐瑰彿={};pakMk={};鏃堕棿={};鏍囪={}",siteId,pakMk,new Date(),i);
staProtocol.setPakMk(pakMk);
}
}
--
Gitblit v1.9.1