From f30358a20ae9a74ee7f6c604a8d102c1b9b24659 Mon Sep 17 00:00:00 2001
From: lsh <lsh123456>
Date: 星期二, 25 六月 2024 16:24:26 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SiemensDevpThread.java | 145 ++++++++++++++++++++++++++++++++++++-----------
1 files changed, 110 insertions(+), 35 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index baf9974..cd891bc 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -197,6 +197,9 @@
Thread.sleep(400);
write((StaProtocol)task.getData());
break;
+ case 9:
+ write9((StaProtocol)task.getData());
+ break;
default:
break;
}
@@ -289,41 +292,33 @@
staProtocol.setBarcodeErr(status[6]);// 鎵爜澶辫触
}
}
-// Thread.sleep(200);
-// OperateResultExOne<byte[]> result0 = siemensS7Net.Read("DB101.0", (short) 186);
-// if (result0.IsSuccess) {
-// for (int i = 0; i < 93; i++) {
-// Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
-// StaProtocol staProtocol = station.get(siteId);
-// if (null == staProtocol) {
-// staProtocol = new StaProtocol();
-// staProtocol.setSiteId(siteId);
-// station.put(siteId, staProtocol);
-// }
-// staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result0.Content, i*2)); // 鐩爣绔�
-// }
-// }
-// Thread.sleep(200);
-// OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB100.100", (short) (staNoSize * 2));
-// if (result1.IsSuccess) {
-// for (int i = 0; i < staNoSize; i++) {
-// Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
-// boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i*2, 1);
-// StaProtocol staProtocol = station.get(siteId);
-// staProtocol.setAutoing(status[0]); // 鑷姩
-// staProtocol.setLoading(status[1]); // 鏈夌墿
-// staProtocol.setInEnable(status[2]); // 鍙叆
-// staProtocol.setOutEnable(status[3]);// 鍙嚭
-// staProtocol.setEmptyMk(status[4]); // 绌烘澘淇″彿
-// staProtocol.setFullPlt(status[5]); // 婊℃墭鐩�
-// staProtocol.setHigh(status[6]); // 楂樺簱浣�
-// staProtocol.setLow(status[7]); // 浣庡簱浣�
-//
-// if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
-// staProtocol.setPakMk(true);
-// }
-// }
-// }
+ if (slave.getId()==2){
+ Thread.sleep(200);
+ int[] staNosRgv = {623,624,625,626};
+ for (int i = 0; i < staNosRgv.length; i++) {
+ OperateResultExOne<byte[]> resultRgv = siemensS7Net.Read("DB100."+(1800+i*6), (short) 5);
+ if (resultRgv.IsSuccess) {
+ Integer siteId = staNosRgv[i]; // 绔欑偣缂栧彿
+ StaProtocol staProtocol = station.get(siteId);
+ if (null == staProtocol) {
+ staProtocol = new StaProtocol();
+ staProtocol.setSiteId(siteId);
+ station.put(siteId, staProtocol);
+ }
+ staProtocol.setEndRow(siemensS7Net.getByteTransform().TransInt16(result.Content, 0)); // 灏忚溅鐩爣浣�
+
+ staProtocol.setNowRow(siemensS7Net.getByteTransform().TransInt16(result.Content, 2)); // 鐩爣绔�
+
+ boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, 4, 1);
+ staProtocol.setRGV1(status[0]); // 鑷姩
+ staProtocol.setRGV2(status[1]); // 鏈夌墿
+ staProtocol.setRGV3(status[2]); // 鍙叆
+ staProtocol.setRGV4(status[3]);// 鍙嚭
+ staProtocol.setRGV5(status[4]); // 绌烘澘淇″彿
+ staProtocol.setRGV6(status[5]); // 婊℃墭鐩�
+ }
+ }
+ }
//鏉$爜鎵弿鍣�
Thread.sleep(200);
@@ -542,6 +537,86 @@
log.info("杈撻�佺嚎鍛戒护涓嬪彂鐮佸灈瀹屾垚 缁欒緭閫佸浣� [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}", slave.getId(), JSON.toJSON(staProtocol));
}
}
+
+ /**
+ * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏�
+ */
+ private void write9(StaProtocol staProtocol) throws InterruptedException {
+ if (null == staProtocol) {
+ return;
+ }
+ short resultS1 = staProtocol.getEndRow();
+ OperateResult result1 = null;
+ String resultV1 = "";
+ switch (staProtocol.getSiteId()){
+ case 623:
+ resultV1 = "1800";
+ break;
+ case 624:
+ resultV1 = "1806";
+ break;
+ case 625:
+ resultV1 = "1812";
+ break;
+ case 626:
+ resultV1 = "1818";
+ break;
+ default:
+ return;
+ }
+ result1 = siemensS7Net.Write(resultV1, resultS1);
+ //纭寲缃愪换鍔″啓鍏ュ悗锛屽洖璇讳竴娆★紝鐪嬫槸鍚︽垚鍔�
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ int writeCount = 1;
+ do {
+ try{
+ if(!result1.IsSuccess){
+ log.error("鍐欏叆RGV鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔� 鍐欏叆鐩存帴澶辫触 ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSON(staProtocol),writeCount);
+ result1 = siemensS7Net.Write(resultV1, resultS1);
+ Thread.sleep(100);
+ writeCount++;
+ continue;
+ }
+ OperateResultExOne<byte[]> resultRead1 = siemensS7Net.Read(resultV1, (short) 2);
+ if (resultRead1.IsSuccess) {
+ short transInt16 = siemensS7Net.getByteTransform().TransInt16(resultRead1.Content, 0);
+ if (transInt16 == resultS1 || transInt16 == (short) 2 || transInt16 == (short) 3){
+ break;
+ } else {
+ log.error("鍐欏叆RGV鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔� 鍐欏叆鐩存帴澶辫触 ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSON(staProtocol),writeCount);
+ result1 = siemensS7Net.Write(resultV1, resultS1);
+ Thread.sleep(100);
+ writeCount++;
+ continue;
+ }
+ } else {
+ log.error("鍐欏叆RGV鏁版嵁澶辫触锛岄噸鏂颁笅鍙戜换鍔� 鍐欏叆鐩存帴澶辫触 ===>> [id:{}],{},[鍐欏叆娆℃暟:{}]", slave.getId(), JSON.toJSON(staProtocol),writeCount);
+ result1 = siemensS7Net.Write(resultV1, resultS1);
+ Thread.sleep(100);
+ writeCount++;
+ continue;
+ }
+ }catch (Exception e){
+ log.error("鍐欏叆RGV鏁版嵁鍚庡洖璇诲嚭閿�,寮傚父锛�"+e);
+ }
+ writeCount++;
+ } while (writeCount<6);
+
+ if (!result1.IsSuccess) {
+ staProtocol = station.get(staProtocol.getSiteId());
+ OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2}", slave.getId(), JSON.toJSON(staProtocol)));
+ log.error("鍐欏叆杈撻�佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={}", slave.getId(), JSON.toJSON(staProtocol));
+ } else {
+ OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆� 杈撻�佺嚎鍛戒护涓嬪彂 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(staProtocol)));
+ log.info("杈撻�佺嚎鍛戒护涓嬪彂鐮佸灈瀹屾垚 缁欒緭閫佸浣� [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}", slave.getId(), JSON.toJSON(staProtocol));
+ }
+ }
+
// 鏇存柊鍏ュ嚭搴撴ā寮�
private void updateIoMode() throws InterruptedException {
if (this.ioModeOf2F != IoModeType.NONE) {
--
Gitblit v1.9.1