From 92c572e50893a93a810bbe6adb6d3cdbfc225073 Mon Sep 17 00:00:00 2001
From: lsh <lsh@163.com>
Date: 星期二, 20 五月 2025 14:17:33 +0800
Subject: [PATCH] *
---
src/main/java/com/zy/core/thread/SiemensDevpThread.java | 120 ++++++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 84 insertions(+), 36 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index a7ddb53..fdf1b1c 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -46,13 +46,15 @@
private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
private short heartBeatVal = 1;
public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{
- add(100);add(101);add(102);add(103);add(104);add(105);add(106);add(107);
+ add(1001);add(1002);add(1003);add(1004);add(1005);add(1006);add(1007);
+ add(1008);add(1009);add(1010);add(1011);add(1012);add(1013);add(1014);add(1015);
+ add(1016);add(1017);add(1018);add(1019);add(1020);add(1021);add(1022);add(1023);
}};
/**
* 鏉$爜鏁伴噺
*/
- private int barcodeSize = 4;
+ private int barcodeSize = 3;
/**
* 鍏ュ嚭搴撴ā寮�
@@ -183,13 +185,18 @@
boolean[] status = siemensS7Net.getByteTransform().TransBool(result.Content, i*8 + 6, 2);
staProtocol.setAutoing(status[0]); // 鑷姩
+// staProtocol.setAutoing(true); // 鑷姩
staProtocol.setLoading(status[1]); // 鏈夌墿
+// staProtocol.setLoading(true); // 鏈夌墿
staProtocol.setInEnable(status[2]); // 鍙叆
+// staProtocol.setInEnable(true); // 鍙叆
staProtocol.setOutEnable(status[3]);// 鍙嚭
+ staProtocol.setOutEnable(true);// 鍙嚭
staProtocol.setEmptyMk(status[4]); // 绌烘澘淇″彿
staProtocol.setFullPlt(status[5]); // 婊℃墭鐩�
staProtocol.setHigh(status[6]); // 楂樺簱浣�
staProtocol.setLow(status[7]); // 浣庡簱浣�
+ staProtocol.setStaOk(status[8]); // 灏辩华
@@ -206,16 +213,38 @@
//鏉$爜
Thread.sleep(200);
- OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.840.0",(short) (barcodeSize*8));
+ OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB400.100.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");
+ String barcode = siemensS7Net.getByteTransform().TransString(result2.Content,i*8,6, "UTF-8");
BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
if(!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
barcodeThread.setBarcode(barcode);
}
}
+ }
+ //鏉$爜
+ Thread.sleep(200);
+ int[] staW = new int[]{1004,1014,1020};
+
+ OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB400.148.0",(short) (staW.length*4));
+ if (result3.IsSuccess) {
+ for (int i = 0; i < staW.length; i++) {
+ Integer siteId = staW[i]; // 绔欑偣缂栧彿
+ StaProtocol staProtocol = station.get(siteId);
+ if (null == staProtocol) {
+ staProtocol = new StaProtocol();
+ station.put(siteId, staProtocol);
+ }
+ staProtocol.setSiteId(siteId);
+ boolean[] status = siemensS7Net.getByteTransform().TransBool(result3.Content, i*4 + 2, 2);
+ staProtocol.setFrontErr(status[0]); // 鍓嶈秴闄�
+ staProtocol.setBackErr(status[1]); // 鍚庤秴闄�
+ staProtocol.setHighErr(status[2]); // 楂樿秴闄�
+ staProtocol.setLeftErr(status[3]); // 宸﹁秴闄�
+ staProtocol.setRightErr(status[4]); // 鍙宠秴闄�
+ }
}
if (result.IsSuccess) {
@@ -229,19 +258,27 @@
StaProtocol staProtocol = station.get(siteId);
basDevps.add(staProtocol.toSqlModel());
}
-
- BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
- if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) {
- throw new Exception("鏇存柊鏁版嵁搴撴暟鎹け璐�");
+ try{
+ BasDevpService basDevpService = SpringUtils.getBean(BasDevpService.class);
+ if (null != basDevpService && !basDevpService.updateBatchById(basDevps)) {
+ throw new Exception("鏇存柊鏁版嵁搴撴暟鎹け璐�");
+ }
+ } catch (Exception e){
+ log.error("e:"+e.getMessage());
}
+
} catch (Exception e) {
e.printStackTrace();
OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戞洿鏂版暟鎹簱鏁版嵁澶辫触 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
log.error("鏇存柊鏁版嵁搴撴暟鎹け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
}
- DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
- deviceErrorService.deleteDeviceError("devp", slave.getId());
+ try{
+ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
+ deviceErrorService.deleteDeviceError("devp", slave.getId());
+ } catch (Exception e){
+ log.error("e:"+e.getMessage());
+ }
} else {
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()));
// log.error("璇诲彇杈撻�佺嚎plc鐘舵�佷俊鎭け璐� ===>> [id:{}] [ip:{}] [port:{}] [rack:{}] [slot:{}]", slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot());
@@ -261,26 +298,26 @@
int index = staNos.indexOf(staProtocol.getSiteId());
- //鏇存柊鍛戒护鏃ュ織
- CommandInfoLogService commandInfoLogService = SpringUtils.getBean(CommandInfoLogService.class);
- CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
- CommandInfo commandInfo = commandInfoService.selectById(staProtocol.getCommandId());
- CommandInfoLog commandInfoLog = new CommandInfoLog();
- if (commandInfo != null) {
- commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
- commandInfoLog.setId(null);
- }else {
- Date now = new Date();
- commandInfoLog.setCommand(JSON.toJSONString(staProtocol));
- commandInfoLog.setCommandStatus(3);
- commandInfoLog.setStartTime(now);
- commandInfoLog.setExecuteTime(now);
- commandInfoLog.setCompleteTime(now);
- commandInfoLog.setDevice(SlaveType.Devp.toString());
- commandInfoLog.setWrkNo(9999);
- commandInfoLog.setTaskNo("9999");
- commandInfoLog.setCommandDesc("鎵嬪姩鍛戒护");
- }
+// //鏇存柊鍛戒护鏃ュ織
+// CommandInfoLogService commandInfoLogService = SpringUtils.getBean(CommandInfoLogService.class);
+// CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
+// CommandInfo commandInfo = commandInfoService.selectById(staProtocol.getCommandId());
+// CommandInfoLog commandInfoLog = new CommandInfoLog();
+// if (commandInfo != null) {
+// commandInfoLog = JSON.parseObject(JSON.toJSONString(commandInfo), CommandInfoLog.class);
+// commandInfoLog.setId(null);
+// }else {
+// Date now = new Date();
+// commandInfoLog.setCommand(JSON.toJSONString(staProtocol));
+// commandInfoLog.setCommandStatus(3);
+// commandInfoLog.setStartTime(now);
+// commandInfoLog.setExecuteTime(now);
+// commandInfoLog.setCompleteTime(now);
+// commandInfoLog.setDevice(SlaveType.Devp.toString());
+// commandInfoLog.setWrkNo(9999);
+// commandInfoLog.setTaskNo("9999");
+// commandInfoLog.setCommandDesc("鎵嬪姩鍛戒护");
+// }
OperateResult writeResult;
//浠诲姟涓嬪彂娆℃暟
@@ -288,15 +325,15 @@
//浠诲姟涓嬪彂鎴愬姛鏍囪瘑
boolean writeFlag = false;
while(writeCount < 5){
- OperateResult writeResult1 = siemensS7Net.Write("DB100." + index*6, staProtocol.getWorkNo()); // 宸ヤ綔鍙�
- OperateResult writeResult2 = siemensS7Net.Write("DB100." + (index*6+4), staProtocol.getStaNo()); // 鐩爣绔�
+ OperateResult writeResult1 = siemensS7Net.Write("DB101." + index*8, staProtocol.getWorkNo()); // 宸ヤ綔鍙�
+ OperateResult writeResult2 = siemensS7Net.Write("DB101." + (index*8+4), staProtocol.getStaNo().shortValue()); // 鐩爣绔�
if(writeResult1.IsSuccess && writeResult2.IsSuccess){
Thread.sleep(200);
OperateResultExOne<byte[]> readResult = siemensS7Net.Read("DB101.0" + index*8, (short)4);
//鏇存柊鎸囦护鏃ュ織
- commandInfoLog.setDeviceLog("鎸囦护涓嬪彂鎴愬姛");
- commandInfoLogService.insert(commandInfoLog);
+// commandInfoLog.setDeviceLog("鎸囦护涓嬪彂鎴愬姛");
+// commandInfoLogService.insert(commandInfoLog);
if(readResult.IsSuccess){
Integer workNo = siemensS7Net.getByteTransform().TransInt32(readResult.Content, 0);
@@ -325,8 +362,8 @@
log.error("鍐欏叆杈撻�佺嚎鍛戒护澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={},鍐欏叆娆℃暟={}", slave.getId(), JSON.toJSON(staProtocol), writeCount);
//鏇存柊鎸囦护鏃ュ織
- commandInfoLog.setDeviceLog("鎸囦护涓嬪彂澶辫触");
- commandInfoLogService.insert(commandInfoLog);
+// commandInfoLog.setDeviceLog("鎸囦护涓嬪彂澶辫触");
+// commandInfoLogService.insert(commandInfoLog);
}
Thread.sleep(200);
}
@@ -412,6 +449,17 @@
}
}
+ /**
+ * 璁剧疆鍏ュ簱鏍囪
+ */
+ @Override
+ public void setGrossWt(Integer siteId, Double grossWt) {
+ StaProtocol staProtocol = station.get(siteId);
+ if (null != staProtocol) {
+ staProtocol.setGrossWt(grossWt);
+ }
+ }
+
@Override
public void close() {
siemensS7Net.ConnectClose();
--
Gitblit v1.9.1