From bb017102f135d427606dfbdc0503191e5f001265 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期五, 02 十二月 2022 09:19:38 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SiemensDevpThread.java | 70 +++++++++++++++++++++-------------
1 files changed, 43 insertions(+), 27 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 56bb030..69a088e 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -43,11 +43,14 @@
private int barcodeSize = 2;
public static final ArrayList<Integer> staNos = new ArrayList<Integer>() {{
add(100);add(101);add(102);add(103);add(104);add(105);add(106);add(107);add(108);add(109);
- add(110);add(111);
+ add(110);add(111);add(112);add(113);add(114);add(115);add(116);add(117);add(118);add(119);
+ add(1000);add(2000);
add(200);add(201);add(202);add(203);add(204);add(205);add(206);add(207);add(208);add(209);
- add(210);add(211);
- add(300);
}};
+
+ public boolean charge0;
+ public boolean charge1;
+ public boolean charge2;
public SiemensDevpThread(DevpSlave slave) {
this.slave = slave;
@@ -109,9 +112,9 @@
* 璇诲彇鐘舵�� ====> 鏁村潡plc
*/
private void read() throws InterruptedException {
- OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) 50);
+ OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) 128);
if (result.IsSuccess) {
- for (int i = 0; i < 25; i++) {
+ for (int i = 0; i < staNos.size(); i++) {
Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
StaProtocol staProtocol = station.get(siteId);
if (null == staProtocol) {
@@ -119,29 +122,16 @@
staProtocol.setSiteId(siteId);
station.put(siteId, staProtocol);
}
- staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*2)); // 宸ヤ綔鍙�
+ staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*4)); // 宸ヤ綔鍙�
+ staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*4+2)); // 鐩爣绔�
}
}
Thread.sleep(200);
- OperateResultExOne<byte[]> result0 = siemensS7Net.Read("DB101.0", (short) 50);
- if (result0.IsSuccess) {
- for (int i = 0; i < 25; 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("DB102.0", (short) 50);
+ OperateResultExOne<byte[]> result1 = siemensS7Net.Read("DB102.0", (short) 128);
if (result1.IsSuccess) {
- for (int i = 0; i < 25; i++) {
+ for (int i = 0; i < staNos.size(); i++) {
Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
- boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i*2, 1);
+ boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i*4+2, 1);
StaProtocol staProtocol = station.get(siteId);
staProtocol.setAutoing(status[0]); // 鑷姩
staProtocol.setLoading(status[1]); // 鏈夌墿
@@ -159,7 +149,7 @@
}
//璇绘潯鐮�
- Thread.sleep(200);
+ Thread.sleep(100);
OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.100",(short)(barcodeSize*8));
if (result2.IsSuccess) {
for (int i = 0; i < barcodeSize; i++) {
@@ -172,7 +162,17 @@
}
- if (result.IsSuccess && result0.IsSuccess && result1.IsSuccess) {
+ // 鍏呯數淇″彿浣�
+ Thread.sleep(100);
+ OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB102.128", (short)1);
+ if (result3.IsSuccess) {
+ boolean[] status = siemensS7Net.getByteTransform().TransBool(result3.Content, 0, 1);
+ charge0 = status[0];
+ charge1 = status[1];
+ charge2 = status[2];
+ }
+
+ if (result.IsSuccess && result1.IsSuccess) {
OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
@@ -206,9 +206,9 @@
return;
}
int index = staNos.indexOf(staProtocol.getSiteId());
- OperateResult write = siemensS7Net.Write("DB100." + index*2, staProtocol.getWorkNo()); // 宸ヤ綔鍙�
+ OperateResult write = siemensS7Net.Write("DB100." + index*4, staProtocol.getWorkNo()); // 宸ヤ綔鍙�
Thread.sleep(500);
- OperateResult write1 = siemensS7Net.Write("DB101." + index*2, staProtocol.getStaNo()); // 鐩爣绔�
+ OperateResult write1 = siemensS7Net.Write("DB100." + (index*4+2), staProtocol.getStaNo()); // 鐩爣绔�
if (!write.IsSuccess || !write1.IsSuccess) {
staProtocol = station.get(staProtocol.getSiteId());
@@ -249,6 +249,22 @@
}
}
+ /**
+ * 鍏呯數鎺у埗
+ * @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) {
+ log.error("杈撻�佺嚎plc缂栧彿={} {}鍙峰厖鐢垫々{}鎺у埗澶辫触", slave.getId(), index + 1, open?"鎵撳紑":"鍏抽棴");
+ return false;
+ } else {
+ log.error("杈撻�佺嚎plc缂栧彿={} {}鍙峰厖鐢垫々{}鎺у埗鎴愬姛", slave.getId(), index + 1, open?"鎵撳紑":"鍏抽棴");
+ }
+ return true;
+ }
+
@Override
public void close() {
siemensS7Net.ConnectClose();
--
Gitblit v1.9.1