From 572a655759f4f8fcfce2c89db491dd837327527a Mon Sep 17 00:00:00 2001
From: yxFwq <1>
Date: 星期一, 03 十一月 2025 09:54:09 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/core/thread/SiemensDevpThread.java | 132 ++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 128 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/SiemensDevpThread.java b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
index cfcab87..e0a32ce 100644
--- a/src/main/java/com/zy/core/thread/SiemensDevpThread.java
+++ b/src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -47,6 +47,8 @@
private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
public boolean charge0; //璇锋眰鍏呯數
public boolean charge1; //璇锋眰鍏呯數
+ private short weight464;
+ private String matnr464;
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);
@@ -132,6 +134,9 @@
add(696);add(697);add(698);add(699);
}};
+ private boolean connectDev = false;
+
+
/**
* 鏉$爜鏁伴噺
*/
@@ -165,12 +170,88 @@
}
}
+
+ /**
+ * 鍒濆鍖栫珯鐐圭姸鎬�
+ */
+ private void initSite() {
+ try{
+ ArrayList<Integer> staNos = getStaNo();
+ // 绔欑偣缂栧彿
+ for (Integer siteId : staNos) {
+ StaProtocol staProtocol = station.get(siteId);
+ if (null == staProtocol) {
+ staProtocol = new StaProtocol();
+ staProtocol.setSiteId(siteId);
+ station.put(siteId, staProtocol);
+ }
+ staProtocol.setSiteId(siteId);
+ staProtocol.setWorkNo(0); // ID
+ staProtocol.setAutoing(false); // 鑷姩
+ staProtocol.setLoading(false); // 鏈夌墿
+ staProtocol.setInEnable(false); // 鍙叆
+ staProtocol.setOutEnable(false); // 鍙嚭
+ staProtocol.setEmptyMk(false); // 绌烘澘淇″彿
+ staProtocol.setStaNo(0); // 鐩爣绔�
+
+ if (!staProtocol.isPakMk() && !staProtocol.isLoading()) {
+ staProtocol.setPakMk(true);
+ }
+ }
+ } catch (Exception e){
+ try{
+ log.error(e.getMessage());
+ } catch (Exception e1){
+
+ }
+ log.error("鍒濆鍖栫珯鐐圭姸鎬佸紓甯�");
+ }
+ }
+
@Override
@SuppressWarnings("InfiniteLoopStatement")
public void run() {
- connect();
+ connectDev = connect();
+ while(!connectDev){
+ try {
+ 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());
+ initSite();
+// e.printStackTrace();
+ }
+ }
+ }
+
+ private void writeStatusDev() {
+ while (true) {
+ try {
+ Thread.sleep(50);
int step = 1;
Task task = MessageQueue.poll(SlaveType.Devp, slave.getId());
if (task != null) {
@@ -179,7 +260,7 @@
switch (step) {
// 璇绘暟鎹�
case 1:
- read();
+// read();
break;
// 鍐欐暟鎹� ID+鐩爣绔�
case 2:
@@ -218,10 +299,34 @@
// heartbeat();
Thread.sleep(400);
} catch (Exception e) {
- e.printStackTrace();
+// e.printStackTrace();
+ try{
+ log.error("dev鍐欑嚎绋嬪紓甯�"+e.getMessage());
+
+ } catch (Exception e1){
+
+ }
+ log.error("DEV鏁版嵁鍐欏叆绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+
}
}
+
+ }
+
+ private void readStatusDev() {
+ while (true) {
+ try {
+ Thread.sleep(50);
+ read();
+
+ } catch (Exception e) {
+ log.error("Dev鏁版嵁璇诲彇绾跨▼寮傚父锛侊紒锛� ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort());
+ initSite();
+ }
+
+ }
+
}
@Override
@@ -415,6 +520,18 @@
}
}
}
+
+ try{
+ OperateResultExOne<byte[]> resultW464 = siemensS7Net.Read("DB100.1874", (short) 2);
+ weight464 = siemensS7Net.getByteTransform().TransInt16(resultW464.Content, 0);// 閲嶉噺464
+ OperateResultExOne<byte[]> resultM464 = siemensS7Net.Read("DB100.1882", (short) 16);
+ matnr464 = siemensS7Net.getByteTransform().TransString(resultM464.Content, 0,16, "UTF-8");
+ matnr464 = matnr464.replaceAll("\\s+", "");
+ } catch (Exception e){
+ log.error("璇诲彇464绔欑偣淇℃伅澶辫触");
+ weight464 = 0;
+ matnr464 = "";
+ }
}
// //RGV灏忚溅
@@ -440,7 +557,14 @@
List<BasDevp> basDevps = new ArrayList<>();
for (Integer siteId : staNos) {
StaProtocol staProtocol = station.get(siteId);
- basDevps.add(staProtocol.toSqlModel());
+ if (siteId == 464){
+ BasDevp basDevp = staProtocol.toSqlModel();
+ basDevp.setGrossWt(Double.valueOf(weight464));
+ basDevp.setDecDesc(matnr464);
+ basDevps.add(basDevp);
+ } else {
+ basDevps.add(staProtocol.toSqlModel());
+ }
}
try{
--
Gitblit v1.9.1