From b427e1d0102d4b3b4263c7c6e572f29f9c50bef9 Mon Sep 17 00:00:00 2001
From: 野心家 <1051256694@qq.com>
Date: 星期四, 08 五月 2025 11:01:04 +0800
Subject: [PATCH] 初始化
---
src/main/java/com/zy/core/thread/SiemensDevpThread.java | 153 ++++++++++++++-------------------------------------
1 files changed, 42 insertions(+), 111 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index 85c82c1..be7d3ac 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -44,21 +44,16 @@
private short heartBeatVal = 1;
public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{
- add(101);add(102);add(103);add(104);
- add(201);add(202);add(203);add(204);
- add(301);add(302);add(303);add(304);add(305);add(306);
+ add(100);add(101);add(102);add(103);
}};
- public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{
- add(401);add(402);
- }};
private Integer count=0;
/**
* 鏉$爜鏁伴噺
*/
- private int barcodeSize = 4;
+ private int barcodeSize = 1;
/**
* 鍏ュ嚭搴撴ā寮�
@@ -68,8 +63,10 @@
* 3.鍑哄簱鍚姩涓� 锛堜笉鑳界敓鎴愬叆搴撳伐浣滄。锛�
* 4.鍑哄簱妯″紡
*/
+ public IoModeType ioModeOf1F = IoModeType.NONE;
public IoModeType ioModeOf2F = IoModeType.NONE;
// public IoModeType ioMode = IoModeType.NONE;
+ public IoModeType ioModeOf3F = IoModeType.NONE;
public IoModeType ioModeOf4F = IoModeType.NONE;
// public IoModeType ioMode = IoModeType.NONE;
@@ -81,8 +78,6 @@
switch (slave.getId()) {
case 1:
return staNos1;
- case 2:
- return staNos2;
default:
throw new CoolException("鏈嶅姟鍣ㄥ紓甯�");
}
@@ -177,10 +172,10 @@
*/
private void read() throws InterruptedException {
// // 鏇存柊鍏ュ嚭搴撴ā寮�
- updateIoMode();
+// updateIoMode();
ArrayList<Integer> staNos = getStaNo();
int staNoSize = staNos.size();
- OperateResultExOne<byte[]> result = siemensS7Net.Read("DB100.0", (short) (staNoSize*4));
+ OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (staNoSize*8));
if (result.IsSuccess) {
for (int i = 0; i < staNoSize; i++) {
Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
@@ -190,76 +185,44 @@
staProtocol.setSiteId(siteId);
station.put(siteId, staProtocol);
}
- staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*4)); // 宸ヤ綔鍙�
+ staProtocol.setWorkNo((short)siemensS7Net.getByteTransform().TransInt32(result.Content, i*8)); // 宸ヤ綔鍙�
- staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*4 + 2)); // 鐩爣绔�
+ staProtocol.setStaNo(siemensS7Net.getByteTransform().TransInt16(result.Content, i*8 + 4)); // 鐩爣绔�
+
+ boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, i*8 + 6, 2);
+ 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);
+ }
}
}
-// 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 = null;
- if(slave.getId()==1) {
- result1 = siemensS7Net.Read("DB100.100", (short) (staNoSize));
- if (result1.IsSuccess) {
- for (int i = 0; i < staNoSize; i++) {
- Integer siteId = staNos.get(i); // 绔欑偣缂栧彿
- boolean[] status = siemensS7Net.getByteTransform().TransBool(result1.Content, i, 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);
- }
- count = 0;
- }
- }
- } else if(slave.getId()==2) {
- 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]); // 浣庡簱浣�
+ //澶栧舰妫�娴�
+ OperateResultExOne<byte[]> resultErr1 = siemensS7Net.Read("DB101.702.0", (short) (barcodeSize*1));
+ if(resultErr1.IsSuccess){
+ StaProtocol staProtocol1 = station.get(101);
+ boolean[] status1 = siemensS7Net.getByteTransform().TransBool(resultErr1.Content, 0, 1);
+ staProtocol1.setFrontErr(status1[0]);
+ staProtocol1.setBackErr(status1[1]);
+ staProtocol1.setHighErr(status1[2]);
+ staProtocol1.setLeftErr(status1[3]);
+ staProtocol1.setRightErr(status1[4]);
+ staProtocol1.setWeightErr(status1[5]);
+ staProtocol1.setBarcodeErr(status1[6]);
- if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
- staProtocol.setPakMk(true);
- }
- }
- count = 0;
- }
}
Thread.sleep(200);
if(slave.getId()==1) {
- OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.150", (short) (barcodeSize * 8));
+ OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.602.0", (short) (barcodeSize * 8));
if (result2.IsSuccess) {
for (int i = 0; i < barcodeSize; i++) {
String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 8, 8, "UTF-8");
@@ -270,26 +233,9 @@
}
}
- } else if(slave.getId()==2) {
- OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB100.150", (short) (1 * 8));
- if (result2.IsSuccess) {
- for (int i = 0; i < 1; i++) {
- String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 8, 8, "UTF-8");
- BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 4);
- if (!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
- barcodeThread.setBarcode(barcode);
- }
- }
-
- }
}
-// OperateResultExOne<Short> result2 = siemensS7Net.ReadInt16("DB200.0");
-// if (result2.IsSuccess) {
-// this.ioMode = IoModeType.get(result2.Content);
-// }
-
- if (result.IsSuccess && !Cools.isEmpty(result1) && result1.IsSuccess) {
+ if (result.IsSuccess) {
OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), slave.getId()));
@@ -328,15 +274,14 @@
ArrayList<Integer> staNos = getStaNo();
int index = staNos.indexOf(staProtocol.getSiteId());
short[] array = new short[2];
- array[0] = staProtocol.getWorkNo();
- array[1] = staProtocol.getStaNo();
- OperateResult write = siemensS7Net.Write("DB100." + index*4, array);
+ OperateResult writeResult1 = siemensS7Net.Write("DB100." + index*6, staProtocol.getWorkNo().intValue()); // 宸ヤ綔鍙�
+ OperateResult writeResult2 = siemensS7Net.Write("DB100." + (index*6+4), staProtocol.getStaNo()); // 鐩爣绔�
-// OperateResult write = siemensS7Net.Write("DB100." + index*2, staProtocol.getWorkNo()); // 宸ヤ綔鍙�
+// OperateResult write = siemensS7Net.Write("DB100.0" + index*4, staProtocol.getWorkNo()); // 宸ヤ綔鍙�
// Thread.sleep(500);
-// OperateResult write1 = siemensS7Net.Write("DB101." + index*2, staProtocol.getStaNo()); // 鐩爣绔�
+// OperateResult write1 = siemensS7Net.Write("DB100.2" + index*4+2, staProtocol.getStaNo()); // 鐩爣绔�
- if (!write.IsSuccess) {
+ if (!writeResult1.IsSuccess&&!writeResult2.IsSuccess) {
staProtocol = station.get(staProtocol.getSiteId());
if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) {
staProtocol.setPakMk(true);
@@ -349,21 +294,7 @@
}
}
- // 鏇存柊鍏ュ嚭搴撴ā寮�
- private void updateIoMode() throws InterruptedException {
- if (slave.getId()==1 && this.ioModeOf2F != IoModeType.NONE) {
- if (!siemensS7Net.Write("DB100.180", this.ioModeOf2F.id).IsSuccess) {
- OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎2F鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={1}", slave.getId()));
- log.error("鍐欏叆杈撻�佺嚎2F鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={}", slave.getId());
- }
- }
- if (slave.getId()==2 && this.ioModeOf4F != IoModeType.NONE) {
- if (!siemensS7Net.Write("DB100.170", this.ioModeOf4F.id).IsSuccess) {
- OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎4F鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={1}", slave.getId()));
- log.error("鍐欏叆杈撻�佺嚎4F鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎plc缂栧彿={}", slave.getId());
- }
- }
- }
+
/**
* 蹇冭烦
--
Gitblit v1.9.1