From ccc7db768baea9df601574a9e2afd52a26a8577d Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期一, 13 四月 2026 10:35:18 +0800
Subject: [PATCH] 1
---
zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java | 96 ++++++++++++++++++++++++++++++------------------
1 files changed, 60 insertions(+), 36 deletions(-)
diff --git a/zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java b/zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java
index 4df073c..d4004da 100644
--- a/zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java
+++ b/zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java
@@ -109,7 +109,7 @@
byte[] content = result.Content;
for (int i = 0; i < staNoSize; i++) {
- StaProtocol staProtocol = station.get(staNos.get(staNoSize));
+ StaProtocol staProtocol = station.get(staNos.get(i));
parseStationStatus(content, i, staProtocol);
}
@@ -134,7 +134,7 @@
*/
private void parseStationStatus(byte[] content, int index, StaProtocol staProtocol) {
int offset = index * StationStatusField.ALL.getByteLength();
- staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(content, offset));
+ staProtocol.setWorkNo(siemensS7Net.getByteTransform().TransInt32(content, offset + StationStatusField.TASK_NUMBER.getOffset()));
staProtocol.setStaNo((int) siemensS7Net.getByteTransform().TransInt16(
content, offset + StationStatusField.FINAL_TARGET.getOffset()));
@@ -158,14 +158,13 @@
* 璇诲彇鏉$爜淇℃伅
*/
private void readBarcodes() {
- List<Integer> barcodeArr = slave.getBarcodeArr();
- if (barcodeArr == null || barcodeArr.isEmpty()) {
+ if (slave.getBarcode() == null || !slave.getBarcode()) {
return;
}
OperateResultExOne<byte[]> result = siemensS7Net.Read(
DeviceField.BARCODE.buildAddress(),
- (short) (barcodeArr.size() * DeviceField.BARCODE.getByteLength()));
+ (short) (DeviceField.BARCODE.getByteLength() * DeviceField.BARCODE.getArrLength()));
if (!result.IsSuccess) {
log.warn("璇诲彇鏉$爜澶辫触 [id:{}]", slave.getId());
@@ -173,14 +172,18 @@
}
byte[] content = result.Content;
- for (int i = 0; i < barcodeArr.size(); i++) {
+ for (int i = 0; i < DeviceField.BARCODE.getArrLength(); i++) {
+ int[] seg = DeviceField.BARCODE.getSeg();
+ int staNo = siemensS7Net.getByteTransform().TransInt16(
+ content, seg[0] + i * DeviceField.BARCODE.getByteLength());
String barcode = siemensS7Net.getByteTransform().TransString(
- content, i * DeviceField.BARCODE.getByteLength(),
- DeviceField.BARCODE.getByteLength(), "UTF-8");
+ content, seg[1] + i * DeviceField.BARCODE.getByteLength(),
+ DeviceField.BARCODE.getByteLength() - seg[1], "UTF-8");
- if (!Cools.isEmpty(barcode)) {
- StaProtocol staProtocol = station.get(barcodeArr.get(i));
+ if (!Cools.isEmpty(barcode) && staNo != 0) {
+ StaProtocol staProtocol = station.get(staNo);
if (staProtocol == null) {
+ log.warn("鎵爜绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), staNo);
continue;
}
staProtocol.setBarcode(barcode);
@@ -190,29 +193,36 @@
}
/**
- * 璇诲彇鏉$爜淇℃伅
+ * 璇诲彇閲嶉噺淇℃伅
*/
private void readWeight() {
- List<Integer> weightArr = slave.getWeightArr();
- if (weightArr == null || weightArr.isEmpty()) {
+ if (slave.getWeight() == null || !slave.getWeight()) {
return;
}
OperateResultExOne<byte[]> result = siemensS7Net.Read(
DeviceField.WEIGHT.buildAddress(),
- (short) (weightArr.size() * DeviceField.WEIGHT.getByteLength()));
+ (short) (DeviceField.WEIGHT.getArrLength() * DeviceField.WEIGHT.getByteLength()));
if (!result.IsSuccess) {
log.warn("璇诲彇閲嶉噺澶辫触 [id:{}]", slave.getId());
return;
}
- for (int i = 0; i < weightArr.size(); i++) {
- StaProtocol staProtocol = station.get(weightArr.get(i));
- if (staProtocol == null) {
- continue;
+ byte[] content = result.Content;
+ for (int i = 0; i < DeviceField.WEIGHT.getArrLength(); i++) {
+ int[] seg = DeviceField.WEIGHT.getSeg();
+ int staNo = siemensS7Net.getByteTransform().TransInt16(
+ content, seg[0] + i * DeviceField.WEIGHT.getByteLength());
+ Double weight = (double) siemensS7Net.getByteTransform().TransSingle(
+ content, seg[1] + i * DeviceField.WEIGHT.getByteLength());
+ if (!Cools.isEmpty(weight) && staNo != 0) {
+ StaProtocol staProtocol = station.get(staNo);
+ if (staProtocol == null) {
+ log.warn("绉伴噸绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), staNo);
+ continue;
+ }
+ staProtocol.setWeight(BigDecimal.valueOf(weight).setScale(4, RoundingMode.HALF_UP).doubleValue());
}
- double weight = siemensS7Net.getByteTransform().TransSingle(result.Content, i * 4);
- staProtocol.setWeight(BigDecimal.valueOf(weight).setScale(2, RoundingMode.HALF_UP).doubleValue());
}
}
@@ -220,14 +230,13 @@
* 璇诲彇澶栧舰妫�娴嬮敊璇�
*/
private void readDimensionErrors() {
- List<Integer> staNosError = slave.getStaNosError();
- if (staNosError == null || staNosError.isEmpty()) {
+ if (slave.getStaNosError() == null || !slave.getStaNosError()) {
return;
}
OperateResultExOne<byte[]> result = siemensS7Net.Read(
DeviceField.DIMENSION_WORD.buildAddress(),
- (short) (staNosError.size() * DeviceField.DIMENSION_WORD.getByteLength()));
+ (short) (DeviceField.DIMENSION_WORD.getArrLength() * DeviceField.DIMENSION_WORD.getByteLength()));
if (!result.IsSuccess) {
log.warn("璇诲彇澶栧舰妫�娴嬮敊璇け璐� [id:{}]", slave.getId());
@@ -235,21 +244,35 @@
}
byte[] content = result.Content;
- for (int i = 0; i < staNosError.size(); i++) {
- Integer siteId = staNosError.get(i);
- StaProtocol staProtocol = station.get(siteId);
+ for (int i = 0; i < DeviceField.DIMENSION_WORD.getArrLength(); i++) {
+ int[] seg = DeviceField.DIMENSION_WORD.getSeg();
+ int staNo = siemensS7Net.getByteTransform().TransInt16(
+ content, seg[0]);
+ if (staNo != 0) {
+ StaProtocol staProtocol = station.get(staNo);
+ if (staProtocol == null) {
+ log.warn("寮傚父绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), staNo);
+ continue;
+ }
+ boolean[] status = siemensS7Net.getByteTransform().TransBool(
+ content, seg[1] + i * DeviceField.DIMENSION_WORD.getByteLength(),
+ 1);
+//鏈娇鐢紝棰勭暀
+// boolean[] status1 = siemensS7Net.getByteTransform().TransBool(
+// content, seg[1]+i * DeviceField.DIMENSION_WORD.getByteLength()+1,
+// 1);
- boolean[] status = siemensS7Net.getByteTransform().TransBool(
- content, i * DeviceField.DIMENSION_WORD.getByteLength(),
- DeviceField.DIMENSION_WORD.getByteLength());
+ staProtocol.setLeftErr(status[0]);
+ staProtocol.setRightErr(status[1]);
+ staProtocol.setFrontErr(status[2]);
+ staProtocol.setBackErr(status[3]);
+ staProtocol.setHighErr(status[4]);
+ staProtocol.setLoadErr(status[5]);
+ staProtocol.setWeightErr(status[6]);
+ staProtocol.setBarcodeErr(status[7]);
+ }
- staProtocol.setFrontErr(status[0]);
- staProtocol.setBackErr(status[1]);
- staProtocol.setHighErr(status[2]);
- staProtocol.setLeftErr(status[3]);
- staProtocol.setRightErr(status[4]);
- staProtocol.setWeightErr(status[5]);
- staProtocol.setBarcodeErr(status[6]);
+
}
}
@@ -271,6 +294,7 @@
Integer siteId = staNos.get(i);
StaProtocol staProtocol = station.get(siteId);
if (staProtocol == null) {
+ log.warn("绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), siteId);
continue;
}
--
Gitblit v1.9.1