From 1e414dac65915133e5474b6f811fd782be36a17f Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期四, 29 五月 2025 13:30:15 +0800
Subject: [PATCH] 修改plc读写

---
 project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs |  186 +++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 156 insertions(+), 30 deletions(-)

diff --git a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
index 6358dba..c10c5af 100644
--- a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
+++ b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
@@ -5,6 +5,7 @@
 using System.Text;
 using System.Threading.Tasks;
 using AutoMapper;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
 using SqlSugar;
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.BaseRepository;
@@ -53,23 +54,58 @@
 
                 int ext = (int)para.ExtendSpeed;//宸LC鑷姩浼稿嚭缂╁洖閫熷害
                 int ret = (int)para.RetractionSpeed;//鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害
+                int liftPosition= (int)para.LeftPosition;//宸︿几鍑轰綅缃�
+                int rigtpostition= (int)para.RightPosition;//鍙充几鍑轰綅缃�
 
                 if (ExtendedState == "浼稿嚭")
                 {
-                    devices.Value.left.Communicator.Write<int>("D1001", ext);//宸LC鑷姩浼稿嚭缂╁洖閫熷害
-                    devices.Value.left.Communicator.Write<bool>("M102", true);//浼稿嚭鎸夐挳
-                    devices.Value.right.Communicator.Write<int>("D1001", ret);//鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害
-                    devices.Value.right.Communicator.Write<bool>("M102", true);//浼稿嚭鎸夐挳
-                    Console.WriteLine($"鑷姩浼哥缉鏉嗕几鍑� {ext}");
+                    try
+                    {
+                        devices.Value.left.Communicator.Write<int>("D1001", ext);//宸LC鑷姩浼稿嚭缂╁洖閫熷害
+                        devices.Value.left.Communicator.Write<bool>("M102", true);//浼稿嚭鎸夐挳
+                        devices.Value.left.Communicator.Write<int>("D1002", liftPosition);//宸︿几鍑轰綅缃�
+                    }
+                    catch (Exception)
+                    {
+
+                    }
+                    try
+                    {
+                        devices.Value.right.Communicator.Write<int>("D1001", ret);//鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害
+                        devices.Value.right.Communicator.Write<bool>("M102", true);//浼稿嚭鎸夐挳
+                        devices.Value.right.Communicator.Write<int>("D1002", rigtpostition);//鍙充几鍑轰綅缃�
+                    }
+                    catch (Exception)
+                    {
+
+                    }
+                    
+                    Console.WriteLine($"鑷姩浼哥缉鏉嗕几鍑� {ext},鍙充几鍑轰綅缃畕liftPosition}锛屽彸浼稿嚭浣嶇疆{rigtpostition}");
                 }
                 else if (ExtendedState == "缂╁洖")
                 {
-                    devices.Value.left.Communicator.Write<int>("D1001", ext);//宸LC鑷姩浼稿嚭缂╁洖閫熷害
-                    devices.Value.left.Communicator.Write<bool>("M103", true);//缂╁洖鎸夐挳
-                    devices.Value.right.Communicator.Write<int>("D1001", ret);//鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害
-                    devices.Value.right.Communicator.Write<bool>("M103", true);//缂╁洖鎸夐挳
+                    try
+                    {
+                        devices.Value.left.Communicator.Write<int>("D1001", ext);//宸LC鑷姩浼稿嚭缂╁洖閫熷害
+                        devices.Value.left.Communicator.Write<bool>("M103", true);//缂╁洖鎸夐挳
+                    }
+                    catch (Exception)
+                    {
+
+                    }
+                    try
+                    {
+                        devices.Value.right.Communicator.Write<int>("D1001", ret);//鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害
+                        devices.Value.right.Communicator.Write<bool>("M103", true);//缂╁洖鎸夐挳
+                    }
+                    catch (Exception)
+                    {
+
+                    }
+                    
                     Console.WriteLine($"鑷姩浼哥缉鏉嗙缉鍥� {ret}");
                 }
+
                 else
                 {
                     return new WebResponseContent { Status = false, Message = "鏈煡鐨勬搷浣滃懡浠�" };
@@ -79,7 +115,8 @@
                     Data = new
                     {
                         ExtendSpeed = ext,//
-                        RetractionSpeed = ret
+                        RetractionSpeed = ret,
+                       
                     }
                 };
             }
@@ -201,6 +238,8 @@
                     RetractionSpeed = entity.RetractionSpeed,
                     ManualExtend = entity.ManualExtend,
                     ManualRetraction = entity.ManualRetraction,
+                    LeftPosition = entity.LeftPosition,
+                    RightPosition = entity.RightPosition,   
                     Deptid = isAdmin ? deid : dept.GetValueOrDefault()//濡傛灉褰撳墠鐢ㄦ埛鏄鐞嗗憳锛屽氨鐢ㄩ厤缃枃浠朵腑鐨� DepartmentID锛屽惁鍒欑敤浼犲叆鐨� entity 鍙傛暟涓殑 Deptid
                 };
                 // 娣诲姞鏁版嵁
@@ -222,7 +261,111 @@
         }
 
 
+        /// <summary>
+        ///褰撹嚜鍔ㄤ几鍑洪渶瑕佹殏鍋滄椂锛屾殏鍋滄寜閽�
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent PauseButton()
+        {
+            try
+            {
+                //鏍规嵁int.TryParse(AppSettings.Get("DepartmentID")璇诲彇鍒板綋鍓嶆槸杞ㄩ亾鍑狅紝鎵�鏈変汉閮藉彧鑳芥搷浣滃綋鍓�
+                if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+                {
+                    return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
+                };
+                var devices = GetDevicesByDeptId(deid);
+                try
+                {
+                    devices.Value.left.Communicator.Write<bool>("M104", true);
+                }
+                catch (Exception)
+                {
 
+                    throw;
+                }
+                try
+                {
+                    devices.Value.right.Communicator.Write<bool>("M104", true);
+                }
+                catch (Exception)
+                {
+
+                    throw;
+                }
+               
+                
+                return new WebResponseContent { Status =true,Message="鏆傚仠鎴愬姛",Data = devices};
+            }
+            catch (Exception ex)
+            {
+
+                return new WebResponseContent { Status = false, Message = ex.Message };
+            }
+        }
+
+
+        /// <summary>
+        /// 鑾峰彇褰撳墠绋嬪簭鏈�鏂扮殑浼哥缉鏉嗛�熷害
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent BackfillSpeed()
+        {
+            try
+            {
+                if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+                {
+                    return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
+
+                }
+                var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault();
+                if (para == null)
+                {
+                    return new WebResponseContent { Message = "浣犺繕娌℃湁閰嶇疆閫熷害" };
+                }
+                return new WebResponseContent { Status = true, Data = para };
+            }
+            catch (Exception ex)
+            {
+
+                return new WebResponseContent { Status = false, Message = ex.Message };
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇褰撳墠浼哥缉鏉嗙殑浣嶇疆(鑷姩)
+        /// </summary>
+        /// <param name="ExtendedState"></param>
+        /// <returns></returns>
+        public WebResponseContent CurrentLocation()
+        {
+            try
+            {
+                if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+                {
+                    return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
+
+                }
+                var devices = GetDevicesByDeptId(deid);
+                
+            
+                    var deviceslift = devices.Value.left.Communicator.Read<float>("D80");
+                    var devicesright = devices.Value.right.Communicator.Read<float>("D80");
+                    Console.WriteLine($"褰撳墠宸﹀彸浼哥缉鏉嗚繑鍥為�熷害鍒嗗埆涓轰负{deviceslift}");
+             
+
+                return new WebResponseContent
+                {
+                    Status = true,
+                    Data = new { lift = deviceslift, Right = devicesright }
+                };
+                }
+            catch (Exception ex)
+            {
+
+                return new WebResponseContent { Status = false, Message = ex.Message };
+            }
+        }
 
 
         /// <summary>
@@ -248,28 +391,11 @@
 
 
 
-        public WebResponseContent BackfillSpeed()
-        {
-            try
-            {
-                if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
-                {
-                    return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
 
-                }
-                var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault();
-                if (para==null)
-                {
-                    return new WebResponseContent { Message = "浣犺繕娌℃湁閰嶇疆閫熷害" };
-                }
-                return new WebResponseContent { Status = true, Data = para };
-            }
-            catch (Exception ex)
-            {
 
-                return new WebResponseContent { Status = false, Message = ex.Message };
-            }
-        }
+
+
+
     }
 
 }

--
Gitblit v1.9.3