From e0a42fbbf3d0c7c3fc7dcead67ee77e86759056c Mon Sep 17 00:00:00 2001
From: Administrator <1051256694@qq.com>
Date: 星期一, 16 三月 2026 16:30:53 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/network/real/ZyCrnRealConnect.java |  260 +++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 198 insertions(+), 62 deletions(-)

diff --git a/src/main/java/com/zy/core/network/real/ZyCrnRealConnect.java b/src/main/java/com/zy/core/network/real/ZyCrnRealConnect.java
index ba2a839..74cf0f1 100644
--- a/src/main/java/com/zy/core/network/real/ZyCrnRealConnect.java
+++ b/src/main/java/com/zy/core/network/real/ZyCrnRealConnect.java
@@ -5,14 +5,12 @@
 import HslCommunication.Profinet.Siemens.SiemensPLCS;
 import HslCommunication.Profinet.Siemens.SiemensS7Net;
 import com.alibaba.fastjson.JSON;
+import com.core.common.Cools;
 import com.core.common.DateUtils;
-import com.core.common.SpringUtils;
-import com.zy.asrs.entity.BasCrnpOpt;
 import com.zy.asrs.entity.DeviceConfig;
-import com.zy.asrs.service.BasCrnpOptService;
-import com.zy.asrs.utils.Utils;
 import com.zy.core.News;
 import com.zy.core.cache.OutputQueue;
+import com.zy.core.enums.CrnTaskModeType;
 import com.zy.core.model.CommandResponse;
 import com.zy.core.model.command.CrnCommand;
 import com.zy.core.network.api.ZyCrnConnectApi;
@@ -34,9 +32,9 @@
         boolean connected = false;
         siemensNet = new SiemensS7Net(SiemensPLCS.S1200, deviceConfig.getIp());
         OperateResult connect = siemensNet.ConnectServer();
-        if(connect.IsSuccess){
+        if (connect.IsSuccess) {
             connected = true;
-            OutputQueue.CRN.offer(MessageFormat.format( "銆恵0}銆戝爢鍨涙満plc杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()));
+            OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝爢鍨涙満plc杩炴帴鎴愬姛 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()));
             News.info("鍫嗗灈鏈簆lc杩炴帴鎴愬姛 ===>> [id:{}] [ip:{}] [port:{}]", deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
         } else {
             OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝爢鍨涙満plc杩炴帴澶辫触锛侊紒锛� ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort()));
@@ -55,7 +53,7 @@
     @Override
     public ZyCrnStatusEntity getStatus() {
         try {
-            OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 56);
+            OperateResultExOne<byte[]> result = siemensNet.Read("DB101.0", (short) 60);
             if (result.IsSuccess) {
                 ZyCrnStatusEntity crnStatus = new ZyCrnStatusEntity();
                 crnStatus.setCrnNo(deviceConfig.getDeviceNo());
@@ -78,6 +76,14 @@
                 crnStatus.setYDistance((double) siemensNet.getByteTransform().TransSingle(result.Content, 44));
                 crnStatus.setXDuration((double) siemensNet.getByteTransform().TransSingle(result.Content, 48));
                 crnStatus.setYDuration((double) siemensNet.getByteTransform().TransSingle(result.Content, 52));
+                crnStatus.setWeight((double) siemensNet.getByteTransform().TransSingle(result.Content, 56));
+
+                // 璇诲彇DB110.200 - DB110.398
+                OperateResultExOne<byte[]> resultDb110 = siemensNet.Read("DB110.200", (short) 200);
+                if (resultDb110.IsSuccess) {
+                    short[] db110Data = siemensNet.getByteTransform().TransInt16(resultDb110.Content, 0, 100);
+                    crnStatus.setDb110Data(db110Data);
+                }
 
                 return crnStatus;
             } else {
@@ -105,15 +111,21 @@
             int writeAck = 0;
             boolean commandResult = false;
             do {
-                OperateResultExOne<byte[]> commandReadResult = siemensNet.Read("DB100.0", (short) 2);
-                if (commandReadResult.IsSuccess) {
-                    short commandRead = siemensNet.getByteTransform().TransInt16(commandReadResult.Content, 0);
-                    if (commandRead == 1) {
-                        Thread.sleep(500);
-                    }else {
-                        commandResult = true;
+                OperateResult result = siemensNet.Write("DB100.0", (short) 0);
+                if (result.IsSuccess) {
+                    OperateResultExOne<byte[]> commandReadResult = siemensNet.Read("DB100.0", (short) 2);
+                    if (commandReadResult.IsSuccess) {
+                        short commandRead = siemensNet.getByteTransform().TransInt16(commandReadResult.Content, 0);
+                        if (commandRead == 1) {
+                            Thread.sleep(500);
+                        }else {
+                            commandResult = true;
+                            break;
+                        }
                     }
                 }
+                writeAck++;
+                Thread.sleep(200);
             } while (writeAck < 5);
 
             if (!commandResult) {
@@ -121,64 +133,188 @@
                 return response;
             }
 
-            short[] array = new short[9];
-            array[0] = (short) 0;
-            array[1] = command.getTaskNo().shortValue();
-            array[2] = command.getTaskMode().shortValue();
-            array[3] = command.getSourcePosX().shortValue();
-            array[4] = command.getSourcePosY().shortValue();
-            array[5] = command.getSourcePosZ().shortValue();
-            array[6] = command.getDestinationPosX().shortValue();
-            array[7] = command.getDestinationPosY().shortValue();
-            array[8] = command.getDestinationPosZ().shortValue();
+            Integer commandTaskMode = command.getTaskMode();
+            if (commandTaskMode.equals(CrnTaskModeType.RESET.id)) {
+                short[] array = new short[9];
+                array[0] = command.getAckFinish().shortValue();
+                array[1] = (short) 0;
+                array[2] = (short) 0;
+                array[3] = (short) 0;
+                array[4] = (short) 0;
+                array[5] = (short) 0;
+                array[6] = (short) 0;
+                array[7] = (short) 0;
+                array[8] = (short) 0;
 
-            OperateResult result = siemensNet.Write("DB100.0", array);
-            if (!result.IsSuccess) {
-                response.setMessage("鍫嗗灈鏈哄懡浠や笅鍙慬id:{}] >>>>> {}" + command.getCrnNo() + "浠诲姟鐘舵�佷綅寮傚父");
-                return response;
-            }
+                int idx = 0;
+                boolean commandDataResult = false;
+                do {
+                    OperateResult result = siemensNet.Write("DB100.0", array);
+                    if (result.IsSuccess) {
+                        OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20);
+                        if (resultRead.IsSuccess) {
+                            short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2);
+                            short taskMode = siemensNet.getByteTransform().TransInt16(resultRead.Content, 4);
+                            short sourcePosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 6);
+                            short sourcePosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 8);
+                            short sourcePosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 10);
+                            short destinationPosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 12);
+                            short destinationPosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 14);
+                            short destinationPosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 16);
+                            if (taskNo != 0 || taskMode != 0 || sourcePosX != 0 || sourcePosY != 0 || sourcePosZ != 0 || destinationPosX != 0 || destinationPosY != 0 || destinationPosZ != 0) {
+                                result = siemensNet.Write("DB100.0", array);
+                            } else {
+                                commandDataResult = true;
+                                break;
+                            }
+                        }
+                    }
+                    idx++;
+                    Thread.sleep(200);
+                } while (idx < 5);
 
-            int idx = 0;
-            do {
-                OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20);
-                if (resultRead.IsSuccess) {
-                    short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2);
-                    short taskMode = siemensNet.getByteTransform().TransInt16(resultRead.Content, 4);
-                    short sourcePosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 6);
-                    short sourcePosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 8);
-                    short sourcePosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 10);
-                    short destinationPosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 12);
-                    short destinationPosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 14);
-                    short destinationPosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 16);
-                    if (taskNo == 0 || taskMode == 0 || sourcePosX == 0 || sourcePosY == 0 || sourcePosZ == 0 || destinationPosX == 0 || destinationPosY == 0 || destinationPosZ == 0) {
-                        result = siemensNet.Write("DB100.0", array);
+                if (!commandDataResult) {
+                    response.setMessage("鍫嗗灈鏈哄懡浠や笅鍙慬id:{}] >>>>> {}" + command.getCrnNo() + "鍫嗗灈鏈哄啓鍏ヤ换鍔℃暟鎹け璐�");
+                    return response;
+                }
+
+                if (!Cools.isEmpty(command.getLocNo())){
+                    OperateResult resultAck = siemensNet.Write("DB110." + command.getIndex() * 2, command.getValue());
+                    if (resultAck.IsSuccess) {
+                        Integer index = command.getIndex()*2 + 200;
+                        OperateResult resultAck1 = siemensNet.Write("DB110." + index, command.getValue());
+                        if (resultAck1.IsSuccess) {
+                            News.info("搴撲綅姗欒壊鎸夐挳鍛戒护涓嬪彂[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
+                        } else {
+                            News.error("搴撲綅鐧借壊鐏懡浠や笅鍙戝け璐locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
+                        }
+                        News.info("搴撲綅鐧借壊鐏懡浠や笅鍙慬locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
                     } else {
-                        break;
+                        News.error("搴撲綅鐧借壊鐏懡浠や笅鍙戝け璐locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
                     }
                 }
-                idx++;
-                Thread.sleep(500);
-            } while (idx < 5);
+            }else {
+                short[] array = new short[9];
+                array[0] = command.getAckFinish().shortValue();
+                array[1] = command.getTaskNo().shortValue();
+                array[2] = command.getTaskMode().shortValue();
+                array[3] = command.getSourcePosX().shortValue();
+                array[4] = command.getSourcePosY().shortValue();
+                array[5] = command.getSourcePosZ().shortValue();
+                array[6] = command.getDestinationPosX().shortValue();
+                array[7] = command.getDestinationPosY().shortValue();
+                array[8] = command.getDestinationPosZ().shortValue();
 
-            OperateResult confirmResult = siemensNet.Write("DB100.0", (short) 1);
-            if (!confirmResult.IsSuccess) {
-                News.error("鍫嗗灈鏈哄啓鍏ョ‘璁ゆ暟鎹け璐� ===>> [id:{}]", command.getCrnNo());
-                response.setMessage("鍫嗗灈鏈哄啓鍏ョ‘璁ゆ暟鎹け璐�");
+                int idx = 0;
+                boolean commandDataResult = false;
+                do {
+                    OperateResult result = siemensNet.Write("DB100.0", array);
+                    if (result.IsSuccess) {
+                        OperateResultExOne<byte[]> resultRead = siemensNet.Read("DB100.0", (short) 20);
+                        if (resultRead.IsSuccess) {
+                            short taskNo = siemensNet.getByteTransform().TransInt16(resultRead.Content, 2);
+                            short taskMode = siemensNet.getByteTransform().TransInt16(resultRead.Content, 4);
+                            short sourcePosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 6);
+                            short sourcePosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 8);
+                            short sourcePosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 10);
+                            short destinationPosX = siemensNet.getByteTransform().TransInt16(resultRead.Content, 12);
+                            short destinationPosY = siemensNet.getByteTransform().TransInt16(resultRead.Content, 14);
+                            short destinationPosZ = siemensNet.getByteTransform().TransInt16(resultRead.Content, 16);
+                            if (taskNo == 0 || taskMode == 0 || sourcePosX == 0 || sourcePosY == 0 || sourcePosZ == 0 || destinationPosX == 0 || destinationPosY == 0 || destinationPosZ == 0) {
+                                result = siemensNet.Write("DB100.0", array);
+                            } else {
+                                commandDataResult = true;
+                                break;
+                            }
+                        }
+                    }
+                    idx++;
+                    Thread.sleep(200);
+                } while (idx < 5);
+
+                if (!commandDataResult) {
+                    response.setMessage("鍫嗗灈鏈哄懡浠や笅鍙慬id:{}] >>>>> {}" + command.getCrnNo() + "鍫嗗灈鏈哄啓鍏ヤ换鍔℃暟鎹け璐�");
+                    return response;
+                }
+
+                int writeConfirmIdx = 0;
+                boolean commandConfirmResult = false;
+                do {
+                    OperateResult result = siemensNet.Write("DB100.18", (short) 1);
+                    if (result.IsSuccess) {
+                        OperateResultExOne<byte[]> commandReadResult = siemensNet.Read("DB100.18", (short) 2);
+                        if (commandReadResult.IsSuccess) {
+                            short commandRead = siemensNet.getByteTransform().TransInt16(commandReadResult.Content, 0);
+                            if (commandRead == 0) {
+                                Thread.sleep(500);
+                            }else {
+                                commandConfirmResult = true;
+                                break;
+                            }
+                        }
+                    }
+                    writeConfirmIdx++;
+                    Thread.sleep(200);
+                } while (writeConfirmIdx < 1);
+
+                if (!commandConfirmResult) {
+                    News.error("鍫嗗灈鏈哄啓鍏ョ‘璁ゆ暟鎹け璐� ===>> [id:{}]", command.getCrnNo());
+                    response.setMessage("鍫嗗灈鏈哄啓鍏ョ‘璁ゆ暟鎹け璐�");
+                    return response;
+                }
+            }
+
+            News.info("鍫嗗灈鏈哄懡浠や笅鍙慬id:{}] >>>>> {}", command.getCrnNo(), JSON.toJSON(command));
+            OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), command.getCrnNo(), JSON.toJSON(command)));
+            response.setResult(true);
+            response.setMessage("鍛戒护涓嬪彂鎴愬姛");
+            return response;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return response;
+    }
+
+    @Override
+    public CommandResponse sendCommand2(CrnCommand command) {
+        CommandResponse response = new CommandResponse(false);
+        try {
+            if (null == command) {
+                News.error("鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�");
+                response.setMessage("鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�");
                 return response;
             }
 
-            if (result != null && result.IsSuccess) {
-                News.info("鍫嗗灈鏈哄懡浠や笅鍙慬id:{}] >>>>> {}", command.getCrnNo(), JSON.toJSON(command));
-                OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆慬id:{1}] >>>>> 鍛戒护涓嬪彂锛� {2}", DateUtils.convert(new Date()), command.getCrnNo(), JSON.toJSON(command)));
-                response.setResult(true);
-                response.setMessage("鍛戒护涓嬪彂鎴愬姛");
-            } else {
-                News.error("鍐欏叆鍫嗗灈鏈簆lc鏁版嵁澶辫触 ===>> [id:{}]", command.getCrnNo());
-                OutputQueue.CRN.offer(MessageFormat.format("銆恵0}銆戝啓鍏ュ爢鍨涙満plc鏁版嵁澶辫触 ===>> [id:{1}]", DateUtils.convert(new Date()), command.getCrnNo()));
-                response.setResult(false);
-                response.setMessage("鍛戒护涓嬪彂澶辫触");
-            }
 
+            OperateResult resultAck = siemensNet.Write("DB110." + command.getIndex() * 2, command.getValue());
+            if (resultAck.IsSuccess) {
+                News.info("搴撲綅鐧借壊鐏懡浠や笅鍙慬locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
+            } else {
+                News.error("搴撲綅鐧借壊鐏懡浠や笅鍙戝け璐locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
+            }
+            return response;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return response;
+    }
+
+    @Override
+    public CommandResponse sendCommand3(CrnCommand command) {
+        CommandResponse response = new CommandResponse(false);
+        try {
+            if (null == command) {
+                News.error("鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�");
+                response.setMessage("鍫嗗灈鏈哄啓鍏ュ懡浠や负绌�");
+                return response;
+            }
+            Integer index = command.getIndex()*2 + 200;
+            OperateResult resultAck = siemensNet.Write("DB110." + index, command.getValue());
+            if (resultAck.IsSuccess) {
+                News.info("搴撲綅姗欒壊鎸夐挳鍛戒护涓嬪彂[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
+            } else {
+                News.error("搴撲綅姗欒壊鎸夐挳鍛戒护涓嬪彂澶辫触[locNo:{}] >>>>> {}", command.getLocNo(), command.getValue());
+            }
             return response;
         } catch (Exception e) {
             e.printStackTrace();

--
Gitblit v1.9.1