From 034839c93e9f18d2b77105a85f65c8400798d74c Mon Sep 17 00:00:00 2001
From: zxx <Zxx@HanInfo>
Date: 星期五, 30 五月 2025 08:31:10 +0800
Subject: [PATCH] 巨石

---
 HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/device/S7Helper.cs |   34 ++++++++++++++++++++++------------
 1 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/device/S7Helper.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/device/S7Helper.cs
index 30eb63b..5f236c6 100644
--- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/device/S7Helper.cs
+++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/device/S7Helper.cs
@@ -3,6 +3,7 @@
 using Microsoft.Owin.BuilderProperties;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
+using Opc.Ua;
 using S7.Net;
 using S7.Net.Types;
 using SqlSugar;
@@ -298,9 +299,11 @@
             var db = new SqlHelper<WCSTask>().GetInstance();
             try
             {
-                var linkplc = Settings.linePlcInfos.Find(a => a.enable == 1);
-                var plc = new Plc(CpuType.S71500, linkplc.address, 0, 1);
+                var linkplc = Settings.SafeInteractions.FindAll(a => a.code == 1|| a.code == 7).ToList();
+                var plc = new Plc(CpuType.S71500, linkplc[1].ip, 0, 1);
                 Link(plc);
+                var plc1 = new Plc(CpuType.S71200, linkplc[0].ip, 0, 1);
+                Link(plc1);
                 //鎷嗘墭鏈�
                 //object rawValue = plc.Read(DataType.DataBlock, 8, 230, VarType.Byte, 1);
                 //LogHelper.Info($"Raw value: {rawValue} (Type: {rawValue?.GetType()})");
@@ -314,13 +317,17 @@
                 LogHelper.Info($"鎷嗘墭鏈烘帴鏀朵俊鍙�===={requestPut1}锛寋requestTake1}锛寋requestPut2}锛寋requestTake2}");
 
                 //RGV
+                //var rawValue = plc1.Read(DataType.DataBlock, 51, 0, VarType.Int, 1);
+                //LogHelper.Info($"Raw value: {rawValue}, Type: {rawValue?.GetType()}");
+
                 // RGV鍏佽鍗歌揣鐘舵�璇诲彇 (浠嶥B51璇诲彇)
-                int rgv1AllowUnload = (int)plc.Read(DataType.DataBlock, 51, 0, VarType.Int, 1);
-                int rgv2AllowUnload = (int)plc.Read(DataType.DataBlock, 51, 2, VarType.Int, 1);
-                int rgv3AllowUnload = (int)plc.Read(DataType.DataBlock, 51, 4, VarType.Int, 1);
-                int rgv4AllowUnload = (int)plc.Read(DataType.DataBlock, 51, 6, VarType.Int, 1);
-                int rgv5AllowUnload = (int)plc.Read(DataType.DataBlock, 51, 8, VarType.Int, 1);
-                int rgv6AllowUnload = (int)plc.Read(DataType.DataBlock, 51, 10, VarType.Int, 1);
+                int rgv1AllowUnload = Convert.ToInt32(plc1.Read(DataType.DataBlock, 51, 0, VarType.Int, 1));
+                int rgv2AllowUnload = Convert.ToInt32(plc1.Read(DataType.DataBlock, 51, 2, VarType.Int, 1));
+                int rgv3AllowUnload = Convert.ToInt32(plc1.Read(DataType.DataBlock, 51, 4, VarType.Int, 1));
+                int rgv4AllowUnload = Convert.ToInt32(plc1.Read(DataType.DataBlock, 51, 6, VarType.Int, 1));
+                int rgv5AllowUnload = Convert.ToInt32(plc1.Read(DataType.DataBlock, 51, 8, VarType.Int, 1));
+                int rgv6AllowUnload = Convert.ToInt32(plc1.Read(DataType.DataBlock, 51, 10, VarType.Int, 1));
+
                 LogHelper.Info($"RGV鎺ユ敹淇″彿=== 1={rgv1AllowUnload}, 2={rgv2AllowUnload}, 3={rgv3AllowUnload}, 4={rgv4AllowUnload}, 5={rgv5AllowUnload}, 6={rgv6AllowUnload}");
 
                 //瀛樺埌缂撳瓨
@@ -964,12 +971,15 @@
         }
 
         //S7鍐欏叆淇″彿 娴嬭瘯鐢�-        internal static Results S7Write(int offsetAddr)
+        internal static Results S7Write(Isusing offsetAddr)
         {
-            var linkplcs = Settings.linePlcInfos.Find(a => a.deviceNo == "1");
-            var plc = new Plc(CpuType.S71500, linkplcs.address, 0, 1);
+            //var linkplcs = Settings.linePlcInfos.Find(a => a.deviceNo == "1");
+            //var plc = new Plc(CpuType.S71200, linkplcs.address, 0, 1);
+            var linkplc = Settings.SafeInteractions.First();
+            var plc = new Plc(CpuType.S71200, linkplc.ip, 0, 1);
             Link(plc);
-            plc.WriteBit(DataType.DataBlock, 9, 182, offsetAddr, false);
+            S7Helper.WriteInt(50, 0, (short)(offsetAddr.S_STATUS * 10 + int.Parse(offsetAddr.S_TYPE)));
+            //plc.WriteBit(DataType.DataBlock, 9, 182, offsetAddr, false);
             return new Results() { Code = "0", Message = $"鍐欏叆鎴愬姛", Data = null };
         }
 

--
Gitblit v1.9.1