From c99cbe6c0064deee3e57f1a751ff0717290ac621 Mon Sep 17 00:00:00 2001
From: lsh <lsh@163.com>
Date: 星期四, 05 六月 2025 15:43:56 +0800
Subject: [PATCH] *
---
src/main/java/com/zy/core/thread/SiemensDevpThread.java | 203 ++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 168 insertions(+), 35 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index f59ff6d..bd02abc 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -50,6 +50,8 @@
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 boolean connectDev = false;
+
/**
* 鏉$爜鏁伴噺
@@ -82,36 +84,53 @@
@Override
@SuppressWarnings("InfiniteLoopStatement")
public void run() {
- connect();
- while (true) {
+ connectDev = connect();
+ while(!connectDev){
try {
- int step = 1;
- Task task = MessageQueue.poll(SlaveType.Devp, slave.getId());
- if (task != null) {
- step = task.getStep();
- }
- switch (step) {
- // 璇绘暟鎹�
- case 1:
- read();
- break;
- // 鍐欐暟鎹� ID+鐩爣绔�
- case 2:
- write((StaProtocol)task.getData());
- break;
- default:
- break;
- }
- // 蹇冭烦
-// heartbeat();
- Thread.sleep(400);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ connectDev = this.connect();
+ Thread.sleep(100);
+ } catch (Exception e){
+ }
}
+
+ // 鍚姩绾跨▼鑷姩閲嶈繛
+ new Thread(this::devConnect).start();
+ new Thread(this::readStatusDev).start();
+ new Thread(this::writeStatusDev).start();
+
+
}
+
+ private void devConnect() {
+ while (true) {
+ try {
+ Thread.sleep(1000);
+
+ if(!connectDev){
+ try {
+ connectDev = this.connect();
+ Thread.sleep(100);
+ } catch (Exception e){
+
+ }
+ }
+ } catch (Exception e) {
+ log.info("dev杩炴帴澶辫触 ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+
+// log.error("rgv杩炴帴澶辫触锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ try{
+ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
+ deviceErrorService.addDeviceError("dev", slave.getId(), "rgv杩炴帴澶辫触"+e.getMessage());
+ } catch (Exception e2){
+// log.error("e2:"+e2.getMessage());
+ }
+ initSite();
+// e.printStackTrace();
+ }
+ }
+ }
/**
* 鍒濆鍖栫珯鐐圭姸鎬�
*/
@@ -161,6 +180,78 @@
return result;
}
+
+
+ private void writeStatusDev() {
+ while (true) {
+ try {
+ if(!connectDev){
+ try {
+ Thread.sleep(1000L);
+ } catch (Exception e){
+
+ }
+ continue;
+ }
+ int step = 1;
+ Task task = MessageQueue.poll(SlaveType.Devp, slave.getId());
+ if (task != null) {
+ step = task.getStep();
+ }
+ switch (step) {
+ // 璇绘暟鎹�
+ case 1:
+// read();
+ break;
+ // 鍐欐暟鎹� ID+鐩爣绔�
+ case 2:
+ write((StaProtocol)task.getData());
+ break;
+ default:
+ break;
+ }
+ // 蹇冭烦
+// heartbeat();
+ Thread.sleep(200);
+ } catch (Exception e) {
+// e.printStackTrace();
+ }
+
+ }
+ }
+ private void readStatusDev() {
+ while (true) {
+ try {
+ if(!connectDev){
+ try {
+ Thread.sleep(1000L);
+ } catch (Exception e){
+
+ }
+ initSite();
+ continue;
+ }
+ Thread.sleep(50);
+// System.out.println("璇荤嚎绋�"+ slave.getId());
+
+ read();
+
+ } catch (Exception e) {
+ log.error("RGV鏁版嵁璇诲彇绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ try{
+ DeviceErrorService deviceErrorService = SpringUtils.getBean(DeviceErrorService.class);
+ deviceErrorService.addDeviceError("rgv", slave.getId(), "RGV鏁版嵁璇诲彇绾跨▼寮傚父"+e.getMessage());
+ } catch (Exception e2){
+// log.error("e2:"+e2.getMessage());
+ }
+ initSite();
+// e.printStackTrace();
+ }
+
+ }
+
+ }
+
/**
* 璇诲彇鐘舵�� ====> 鏁村潡plc
*/
@@ -191,7 +282,7 @@
staProtocol.setInEnable(status[2]); // 鍙叆
// staProtocol.setInEnable(true); // 鍙叆
staProtocol.setOutEnable(status[3]);// 鍙嚭
- staProtocol.setOutEnable(true);// 鍙嚭
+// staProtocol.setOutEnable(true);// 鍙嚭
staProtocol.setEmptyMk(status[4]); // 绌烘澘淇″彿
staProtocol.setFullPlt(status[5]); // 婊℃墭鐩�
staProtocol.setHigh(status[6]); // 楂樺簱浣�
@@ -212,15 +303,38 @@
}
//鏉$爜
- Thread.sleep(200);
- OperateResultExOne<byte[]> result2 = siemensS7Net.Read("DB101.840.0",(short) (barcodeSize*8));
+// Thread.sleep(50);
+ 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(50);
+ 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]); // 鍙宠秴闄�
}
}
@@ -235,19 +349,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());
@@ -429,6 +551,17 @@
}
}
+ /**
+ * 璁剧疆鍏ュ簱鏍囪
+ */
+ @Override
+ public void setErrorDev(Integer siteId, String msgErr) {
+ StaProtocol staProtocol = station.get(siteId);
+ if (null != staProtocol) {
+ staProtocol.setErrorDev(msgErr);
+ }
+ }
+
@Override
public void close() {
siemensS7Net.ConnectClose();
--
Gitblit v1.9.1