From 8becddfbe242865ff9f952a949c1ce35120a53fb Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 07 十一月 2023 08:30:50 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SiemensDevpThread.java | 259 +++++++++------------------------------------------
1 files changed, 46 insertions(+), 213 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 2ce3d17..3d874c8 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -41,7 +41,7 @@
private SiemensS7Net siemensS7Net;
private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
private short heartBeatVal = 1;
- private int barcodeSize = 9;
+ private int barcodeSize = 10;
public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{
add(100);add(101);
add(102);add(103);
@@ -55,11 +55,24 @@
add(303);add(317);
add(325);add(331);
add(333);add(339);
+ add(309);add(312);
}};
- public static final ArrayList<Integer> outInStaNos = new ArrayList<Integer>() {{
- add(102);add(105);add(106);
- add(107);add(108);
+ //楂樹綆淇″彿绔欑偣
+ public static final ArrayList<Integer> locType1StaNos = new ArrayList<Integer>() {{
+ add(100);add(103);
+ add(105);add(200);
+ add(203);add(205);
+ add(300);add(341);
+ add(346);
+ }};
+
+ //鍑哄叆搴撴ā寮�
+ public static final ArrayList<Integer> outInModelStaNos = new ArrayList<Integer>() {{
+ add(100);add(103);
+ add(105);add(200);
+ add(203);add(205);
+ add(341);add(346);
}};
public boolean charge0;
@@ -90,15 +103,6 @@
write((StaProtocol) task.getData());
read();
break;
- // 鍑哄叆搴撴ā寮�
- case 3:
- write3((StaProtocol) task.getData());
- read();
- break;
- //102绔欏洖閫�淇″彿
- case 5:
- write5((StaProtocol) task.getData());
- read();
default:
break;
}
@@ -173,10 +177,17 @@
//璇绘潯鐮�
Thread.sleep(100);
- OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB1000.200", (short) 72);
+ OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB1000.200", (short) 98);
if (result2.IsSuccess) {
for (int i = 0; i < barcodeSize; i++) {
- String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8");
+ String barcode = null;
+ if (i == 8) {
+ barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,13, "UTF-8");
+ } else if (i == 9) {
+ barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8 + 6,13, "UTF-8");
+ } else {
+ barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,8, "UTF-8");
+ }
BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
barcodeThread.setBarcode(barcode);
@@ -184,14 +195,26 @@
}
}
- // 澶栧舰妫�娴� - 102
- Thread.sleep(50);
- OperateResultExOne<byte[]> result102 = siemensS7Net.Read("DB100.100", (short)2);
- if (result102.IsSuccess) {
- //鍑哄叆搴撴ā寮�
- short outInModel = siemensS7Net.getByteTransform().TransInt16(result102.Content, 0);
- StaProtocol staProtocol = station.get(102);
- staProtocol.setOutInModel(outInModel);
+ //璇婚珮浣庝俊鍙�
+ Thread.sleep(100);
+ OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB1000.300", (short) (locType1StaNos.size()*2));
+ if (result3.IsSuccess) {
+ for (int i = 0; i < locType1StaNos.size(); i++) {
+ Integer siteId = locType1StaNos.get(i); // 绔欑偣缂栧彿
+ StaProtocol staProtocol = station.get(siteId);
+ staProtocol.setLocType1(siemensS7Net.getByteTransform().TransInt16(result3.Content, i * 2));//璇诲彇楂樹綆淇″彿
+ }
+ }
+
+ //璇诲嚭鍏ュ簱妯″紡
+ Thread.sleep(100);
+ OperateResultExOne<byte[]> result4 = siemensS7Net.Read("DB1002.0", (short) (outInModelStaNos.size()*2));
+ if (result4.IsSuccess) {
+ for (int i = 0; i < outInModelStaNos.size(); i++) {
+ Integer siteId = outInModelStaNos.get(i); // 绔欑偣缂栧彿
+ StaProtocol staProtocol = station.get(siteId);
+ staProtocol.setOutInModel(siemensS7Net.getByteTransform().TransInt16(result4.Content, i * 2));//璇诲彇鍑哄叆搴撴ā寮�
+ }
}
if (result.IsSuccess && result1.IsSuccess) {
@@ -217,136 +240,6 @@
OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戣鍙栬緭閫佺嚎plc鐘舵�佷俊鎭け璐� ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
// News.error("璇诲彇杈撻�佺嚎plc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
}
- }
-
- /**
- * plc涓庢彁鍗囨満浜や簰
- */
- private void write4(Integer siteId, Integer direction) throws InterruptedException {
- if (Cools.isEmpty(siteId, direction)) {
- return;
- }
- switch (siteId) {
- case 102:
- siemensS7Net.Write("DB100.300", direction.shortValue());
- break;
- case 105:
- siemensS7Net.Write("DB100.302", direction.shortValue());
- break;
- case 106:
- siemensS7Net.Write("DB100.304", direction.shortValue());
- break;
- case 107:
- siemensS7Net.Write("DB100.306", direction.shortValue());
- break;
- case 108:
- siemensS7Net.Write("DB100.308", direction.shortValue());
- break;
- }
- }
-
- /**
- * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏�
- */
- private void write3(StaProtocol staProtocol) throws InterruptedException {
- if (Cools.isEmpty(staProtocol)) {
- return;
- }
- OperateResult writeResult = null;
- //浠诲姟涓嬪彂娆℃暟
- int writeCount = 0;
- //浠诲姟涓嬪彂鎴愬姛鏍囪瘑
- boolean writeFlag = false;
-
- Short outAndIn = staProtocol.getOutInModel();
- Integer siteId = staProtocol.getSiteId();
- Short run = 0;//鍋滄杞姩
- String address = "";
- if (staProtocol.getRotationDire() != null) {
- run = staProtocol.getRotationDire().shortValue();//杞姩鏂瑰悜
- }
- switch (siteId) {
- case 102:
- address = "DB100.300";
- break;
- case 105:
- address = "DB100.302";
- break;
- case 106:
- address = "DB100.304";
- break;
- case 107:
- address = "DB100.306";
- break;
- case 108:
- address = "DB100.308";
- break;
- }
-
- while(writeCount < 5){
- writeResult = siemensS7Net.Write(address, run);
- if (writeResult == null) {
- log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
- continue;
- }
-
- if(writeResult.IsSuccess){
- Thread.sleep(200);
- OperateResultExOne<byte[]> readResult = siemensS7Net.Read(address, (short) 2);
- if(readResult.IsSuccess){
- short run2 = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 0);
- if(run.equals(run2)){
- //浠诲姟鍛戒护鍐欏叆鎴愬姛
- writeFlag = true;
- if (staProtocol.getStaNo() != null && staProtocol.getWorkNo() != null) {
- write(staProtocol);//鍐欏叆宸ヤ綔鍙峰拰鐩爣绔�
- }
- log.info("鍐欏叆杈撻�佺嚎鍛戒护鍚庤繑鍥炴垚鍔燂紝骞朵笖鍥炶鎴愬姛銆傝緭閫佺嚎plc缂栧彿={}锛寋}锛屽啓鍏ユ鏁�={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
- break;
- } else {//杩斿洖缁撴灉鏄垚鍔熶簡锛屼絾鏄湡瀹炲�间笉鐩稿悓
- writeCount++;
- OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护鍚庤繑鍥炴垚鍔燂紝浣嗘槸璇诲彇浠诲姟鍊间笉涓�鑷淬�傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2},鍐欏叆娆℃暟={3}",
- slave.getId(), JSON.toJSON(staProtocol),writeCount));
- log.error("鍐欏叆杈撻�佺嚎鍛戒护鍚庤繑鍥炴垚鍔燂紝浣嗘槸璇诲彇浠诲姟鍊间笉涓�鑷淬�傝緭閫佺嚎plc缂栧彿={}锛寋}锛屽啓鍏ユ鏁�={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
- }
- } else {
- writeCount++;
- OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护鍚庤鍙栧け璐ャ�傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2},鍐欏叆娆℃暟={3}",
- slave.getId(), JSON.toJSON(staProtocol), writeCount));
- log.error("鍐欏叆杈撻�佺嚎鍛戒护鍚庤鍙栧け璐ャ�傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
- }
- } else {
- writeCount++;
- OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2},鍐欏叆娆℃暟={3}",
- slave.getId(), JSON.toJSON(staProtocol),writeCount));
- log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
- }
- Thread.sleep(200);
- }
-
- //鍐欏懡浠ゅ皾璇曚簡5娆¤繕鏄け璐ヤ簡
- if(!writeFlag){
- staProtocol = station.get(staProtocol.getSiteId());
- if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) {
- staProtocol.setPakMk(true);
- }
- OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护灏濊瘯5娆″け璐ャ�傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2}", slave.getId(), JSON.toJSON(staProtocol)));
- log.error("鍐欏叆杈撻�佺嚎鍛戒护灏濊瘯5娆″け璐ャ�傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={}", slave.getId(), JSON.toJSON(staProtocol));
-
- //閲嶆柊娣诲姞鏁版嵁鍒颁换鍔¢槦鍒�
- boolean result = MessageQueue.offer(SlaveType.Devp, slave.getId(), new Task(3, staProtocol));
- read();//璇诲彇1娆¤澶囩姸鎬�
- return;
- } 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));
-
- staProtocol = station.get(siteId);
- if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) {
- staProtocol.setPakMk(true);
- }
- }
-
}
/**
@@ -429,50 +322,6 @@
}
/**
- * 鍐欏叆 ID+鐩爣绔� =====> 鍗曠珯鐐瑰啓鍏�
- */
- private void write5(StaProtocol staProtocol) throws InterruptedException {
- if (null == staProtocol) {
- return;
- }
-
- OperateResult writeResult;
- //浠诲姟涓嬪彂娆℃暟
- int writeCount = 0;
- while(writeCount < 5){
- writeResult = siemensS7Net.Write("DB100.310", staProtocol.getRollback102().shortValue());
- if(writeResult.IsSuccess){
- Thread.sleep(200);
- OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB100.310", (short)2);
- if(readResult.IsSuccess){
- short rollback = siemensS7Net.getByteTransform().TransInt16(readResult.Content, 0);
- if (staProtocol.getRollback102() == (int) rollback) {
- //浠诲姟鍛戒护鍐欏叆鎴愬姛
- log.info("鍐欏叆杈撻�佺嚎鍛戒护鍚庤繑鍥炴垚鍔燂紝骞朵笖鍥炶鎴愬姛銆傝緭閫佺嚎plc缂栧彿={}锛寋}锛屽啓鍏ユ鏁�={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
- return;
- } else {//杩斿洖缁撴灉鏄垚鍔熶簡锛屼絾鏄湡瀹炲�间笉鐩稿悓
- writeCount++;
- OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护鍚庤繑鍥炴垚鍔燂紝浣嗘槸璇诲彇浠诲姟鍊间笉涓�鑷淬�傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2},鍐欏叆娆℃暟={3}",
- slave.getId(), JSON.toJSON(staProtocol), writeCount));
- log.error("鍐欏叆杈撻�佺嚎鍛戒护鍚庤繑鍥炴垚鍔燂紝浣嗘槸璇诲彇浠诲姟鍊间笉涓�鑷淬�傝緭閫佺嚎plc缂栧彿={}锛寋}锛屽啓鍏ユ鏁�={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
- }
- } else {
- writeCount++;
- OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护鍚庤鍙栧け璐ャ�傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2},鍐欏叆娆℃暟={3}",
- slave.getId(), JSON.toJSON(staProtocol), writeCount));
- log.error("鍐欏叆杈撻�佺嚎鍛戒护鍚庤鍙栧け璐ャ�傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
- }
- } else {
- writeCount++;
- OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2},鍐欏叆娆℃暟={3}",
- slave.getId(), JSON.toJSON(staProtocol),writeCount));
- log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
- }
- Thread.sleep(200);
- }
- }
-
- /**
* 蹇冭烦
*/
private void heartbeat(){
@@ -496,22 +345,6 @@
if (null != staProtocol) {
staProtocol.setPakMk(pakMk);
}
- }
-
- /**
- * 鍏呯數鎺у埗
- * @param index 鍏呯數妗╁簭鍙� 0 寮�濮�
- * @param open true 寮�濮嬪厖鐢碉紱false 缁撴潫鍏呯數
- */
- public boolean charge(int index, boolean open) {
- OperateResult write = siemensS7Net.Write("DB102.50." + (index + 3), open);
- if (!write.IsSuccess) {
- News.error("杈撻�佺嚎plc缂栧彿={} {}鍙峰厖鐢垫々{}鎺у埗澶辫触", slave.getId(), index + 1, open?"鎵撳紑":"鍏抽棴");
- return false;
- } else {
- News.error("杈撻�佺嚎plc缂栧彿={} {}鍙峰厖鐢垫々{}鎺у埗鎴愬姛", slave.getId(), index + 1, open?"鎵撳紑":"鍏抽棴");
- }
- return true;
}
@Override
--
Gitblit v1.9.1