From fcd49db2ee33ee2e1d33e5a41e53d9897a8a3b0f Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期四, 05 六月 2025 19:19:10 +0800
Subject: [PATCH] 限制plc伸到位报警,和限制开始作业无限点击问题

---
 project/后台管理/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs |  216 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 148 insertions(+), 68 deletions(-)

diff --git "a/project/\345\220\216\345\217\260\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs" "b/project/\345\220\216\345\217\260\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs"
index 3f6b351..e9327e6 100644
--- "a/project/\345\220\216\345\217\260\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs"
+++ "b/project/\345\220\216\345\217\260\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs"
@@ -63,29 +63,90 @@
                     int liftPosition = (int)para.LeftPosition;//宸︿几鍑轰綅缃�
                     int rigtpostition = (int)para.RightPosition;//鍙充几鍑轰綅缃�
 
+                    try
+                    {
+                        var leftorigin = devices.Value.left.Communicator.Read<bool>("M115");//宸lc鍒板師鐐逛綅缃俊鍙�
+                        var rightorigin = devices.Value.right.Communicator.Read<bool>("M115");//鍙硃lc鍒拌揪鍘熺偣浣嶇疆淇″彿
+                        if (leftorigin == true || rightorigin == true)
+                        {
+                            return new WebResponseContent { Status = false, Message = "宸插埌鍘熷鐐�" };
+                        }
+                    }
+                    catch (Exception)
+                    {
+
+
+                    }
+                    try
+                    {
+                        var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//宸lc鍒拌揪鐩爣浣嶇疆
+                        var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//鍙硃lc鍒拌揪鐩爣浣嶇疆
+                        if (lefttarget == true || righttarget == true)
+                        {
+                            return new WebResponseContent { Status = false, Message = "宸插埌鏈�澶у��" };
+                        }
+
+                    }
+                    catch (Exception)
+                    {
+
+
+                    }
 
 
                     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>("D1002", liftPosition);//宸︿几鍑轰綅缃�
+                        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)
+                        {
 
+                            
+                        }
 
-                        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);//鍙充几鍑轰綅缃�
+                        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)
+                        {
+
+                            throw;
+                        }
+
+                      
 
                         Console.WriteLine($"DeptId={deptId} 锛屽乏閫熷害={ext}锛屽彸閫熷害={ret}");
                     }
                     else if (extendedState == "缂╁洖")
                     {
-                        devices.Value.left.Communicator.Write<int>("D1001", ext);//缂╁洖閫熷害
-                        devices.Value.left.Communicator.Write<bool>("M103", true);//缂╁洖鎸夐挳
+                        try
+                        {
+                            devices.Value.left.Communicator.Write<int>("D1001", ext);//缂╁洖閫熷害
+                            devices.Value.left.Communicator.Write<bool>("M103", true);//缂╁洖鎸夐挳
+                        }
+                        catch (Exception)
+                        {
 
-                        devices.Value.right.Communicator.Write<int>("D1001", ret);
-                        devices.Value.right.Communicator.Write<bool>("M103", true);
+                            throw;
+                        }
 
+                        try
+                        {
+                            devices.Value.right.Communicator.Write<int>("D1001", ret);
+                            devices.Value.right.Communicator.Write<bool>("M103", true);
+                        }
+                        catch (Exception)
+                        {
+
+                            throw;
+                        }
                         Console.WriteLine($"DeptId={deptId} 缂╁洖鎿嶄綔锛屽乏閫熷害={ext}锛屽彸閫熷害={ret}");
                     }
                     else
@@ -104,61 +165,6 @@
         }
 
 
-
-
-
-
-
-        /// <summary>
-        /// 鎵嬪姩鎺у埗锛屼几缂╂潌鐨勭缉鍥炲拰浼稿嚭閫熷害
-        /// </summary>
-        /// <param name="position">浼哥缉鏉嗙殑浣嶇疆锛堝乏鍙筹級</param>
-        /// <param name="ExtendedState">浼�/缂╃姸鎬�</param>
-        /// <returns></returns>
-        /// 
-        //public WebResponseContent ManualOperation(string position, string ExtendedState)
-        //{
-        //    try
-        //    {
-        //        //淇╀釜plc宸﹀彸鍚勪竴涓�
-        //        OtherDevice liftotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG001");
-        //        OtherDevice rightotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG002");
-        //        //鎵惧埌Dt_Parameters涓殑鏈�鏂颁竴鏉℃暟鎹�
-        //        var para = BaseDal.QueryData().OrderBy(x => x.CreateDate).FirstOrDefault();
-        //        int ext = (int)para.ManualExtend;//鑷姩浼稿嚭閫熷害
-        //        int ret = (int)para.ManualRetraction;//鑷姩缂╁洖閫熷害
-        //            if (position == "宸�" && ExtendedState == "浼稿嚭")
-        //            {
-        //                var values = liftotherDevice.Communicator.Write<int>("D500", ext);//閫熷害
-        //    var button = liftotherDevice.Communicator.Write<bool>("M100", true);//浼稿嚭鎸夐挳
-        //    Console.WriteLine($"{position}浼哥缉鏉嗕几鍑簕ext}");
-        //            }
-        //            if (position == "宸�" && ExtendedState == "缂╁洖")
-        //            {
-        //                var values = liftotherDevice.Communicator.Write<int>("D501", ret);
-        //var button = liftotherDevice.Communicator.Write<bool>("M101", true);//缂╁洖鎸夐挳
-        //Console.WriteLine($"{position}浼哥缉鏉嗙缉鍥瀧ret}");
-        //            }
-        //        if (position == "鍙�" && ExtendedState == "浼稿嚭")
-        //        {
-        //            var values = rightotherDevice.Communicator.Write<int>("D500", ext);//閫熷害
-        //            var button = rightotherDevice.Communicator.Write<bool>("M100", true);//浼稿嚭鎸夐挳
-        //            Console.WriteLine($"{position}浼哥缉鏉嗕几鍑簕ext}");
-        //        }
-        //        if (position == "鍙�" && ExtendedState == "缂╁洖")
-        //        {
-        //            var values = rightotherDevice.Communicator.Write<int>("D501", ret);
-        //            var button = rightotherDevice.Communicator.Write<bool>("M101", true);//缂╁洖鎸夐挳
-        //            Console.WriteLine($"{position}浼哥缉鏉嗙缉鍥瀧ret}");
-        //        }
-        //        return new WebResponseContent { Status = true, Message = "鎴愬姛" };
-        //    }
-        //    catch (Exception ex)
-        //    {
-        //        return new WebResponseContent { Status = false, Message = ex.Message };
-
-        //    }
-        //}
 
 
 
@@ -184,6 +190,36 @@
 
                 int ext = (int)para.ManualExtend;//宸LC鎵嬪姩浼稿嚭缂╁洖閫熷害
                 int ret = (int)para.ManualRetraction;//鍙砅LC鎵嬪姩浼稿嚭缂╁洖閫熷害
+                try
+                {
+                    var leftorigin = devices.Value.left.Communicator.Read<bool>("M115");//宸lc鍒板師鐐逛綅缃俊鍙�
+                    var rightorigin = devices.Value.right.Communicator.Read<bool>("M115");//鍙硃lc鍒拌揪鍘熺偣浣嶇疆淇″彿
+                    if (leftorigin == true || rightorigin == true)
+                    {
+                        return new WebResponseContent { Status = false, Message = "宸插埌鍘熷鐐�" };
+                    }
+                }
+                catch (Exception)
+                {
+
+
+                }
+                try
+                {
+                    var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//宸lc鍒拌揪鐩爣浣嶇疆
+                    var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//鍙硃lc鍒拌揪鐩爣浣嶇疆
+                    if (lefttarget == true || righttarget == true)
+                    {
+                        return new WebResponseContent { Status = false, Message = "宸插埌鏈�澶у��" };
+                    }
+
+                }
+                catch (Exception)
+                {
+
+
+                }
+
 
                 if (position == "宸�" && ExtendedState == "浼稿嚭")
                 {
@@ -243,14 +279,58 @@
             {
                 //鏍规嵁int.TryParse(AppSettings.Get("DepartmentID")璇诲彇鍒板綋鍓嶆槸杞ㄩ亾鍑狅紝鎵�鏈変汉閮藉彧鑳芥搷浣滃綋鍓�
                 var devices = GetDevicesByDeptId(deptid);
-                devices.Value.left.Communicator.Write<bool>("M104", true);
-                devices.Value.right.Communicator.Write<bool>("M104", true);
+                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>
+        /// 浼哥缉鏉嗗綋鍓嶄綅缃�(杩欎釜娌℃湁鐢�)
+        /// <param name="deptid">杞ㄩ亾绔欏彿</param>
+        public WebResponseContent CurrentLocation(int deptid)
+        {
+            try
+            {
+                var devices = GetDevicesByDeptId(deptid);
+                if (devices == null)
+                    return new WebResponseContent { Status = false, Message = "璁惧鏈壘鍒�" };
+                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};
             }
         }
 
@@ -276,7 +356,7 @@
             return (left, right);
         }
 
-       
+   
     }
 
 }

--
Gitblit v1.9.3