From 9f3858dd723a69c56dbab909e0c7e6c5ef8b85a8 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期一, 09 六月 2025 20:27:19 +0800
Subject: [PATCH] 修改plc信息,以及进入检修接口

---
 project/后台管理/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs |  314 ++++++++++++++++++++++++---------------------------
 1 files changed, 149 insertions(+), 165 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 d40bdc8..566e4f4 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"
@@ -67,54 +67,23 @@
                         int liftPos = (int)para.LeftPosition;
                         int rightPos = (int)para.RightPosition;
 
-                        // 鐙珛鍒ゆ柇宸�/鍙虫槸鍚﹀彲鎵ц
-                        bool canLeft = true, canRight = true;
-
                         try
                         {
-                            var leftOrigin = devices.Value.left.Communicator.Read<bool>("M115");//鍒拌揪鍘熺偣
-                            if (leftOrigin)
+                            if (devices.Value.left.Communicator.Read<bool>("M117"))
                             {
-                                messages.Add($"{deptId}杞ㄩ亾宸LC宸插埌鍘熺偣");
-                                canLeft = false;
+
+                                return new WebResponseContent { Status = false, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
                             }
 
                         }
                         catch (Exception)
-                        { }
-                        try
-                        {
-                            var rightOrigin = devices.Value.right.Communicator.Read<bool>("M115");
-                            if (rightOrigin)
-                            {
-                                messages.Add($"{deptId}杞ㄩ亾鍙砅LC宸插埌鍘熺偣");
-                                canRight = false;
-                            }
-                        }
-                        catch (Exception)
-                        {
-                        }
-
-
-                        try
-                        {
-                            var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//宸lc鍒拌揪鐩爣浣嶇疆
-                            if (lefttarget)
-                            {
-                                messages.Add($"{deptId}杞ㄩ亾宸lc鍒拌揪鐩爣浣嶇疆");
-                                canLeft = false;
-                            }
-                        }
-                        catch (Exception)
                         {
                         }
                         try
                         {
-                            var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//鍙硃lc鍒拌揪鐩爣浣嶇疆
-                            if (righttarget)
+                            if (devices.Value.right.Communicator.Read<bool>("M117"))
                             {
-                                messages.Add($"{deptId}杞ㄩ亾鍙硃lc鍒拌揪鐩爣浣嶇疆");
-                                canRight = false;
+                                return new WebResponseContent { Status = false, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
                             }
 
                         }
@@ -124,71 +93,83 @@
 
                         if (extendedState == "浼稿嚭")
                         {
-                            if (canLeft)
-                            {
-                                try
-                                {
-                                    devices.Value.left.Communicator.Write<int>("D1001", ext);
-                                    devices.Value.left.Communicator.Write<bool>("M102", true);
-                                    devices.Value.left.Communicator.Write<int>("D1002", liftPos);
-                                }
-                                catch (Exception)
-                                {
-
-                                    
-                                }
-
-                               
-                            }
-
-                            if (canRight)
-                            {
-                                try
-                                {
-
-                                    devices.Value.right.Communicator.Write<int>("D1001", ret);
-                                    devices.Value.right.Communicator.Write<bool>("M102", true);
-                                    devices.Value.right.Communicator.Write<int>("D1002", rightPos);
-                                }
-                                catch (Exception)
-                                {
-
-                                }
-                              
-                            }
-                        }
-                        else if (extendedState == "缂╁洖")
+                   
+                        try
                         {
-                            if (canLeft)
-                            {
-                                try
-                                {
-                                        devices.Value.left.Communicator.Write<int>("D1001", ext);
-                                        devices.Value.left.Communicator.Write<bool>("M103", true);
-                                    }
-                                catch (Exception)
-                                {
-
-
-                                }
-                               
-                               
-                            }
-
-                            if (canRight)
-                            {
-                                try
-                                {
-                                        devices.Value.right.Communicator.Write<int>("D1001", ret);
-                                        devices.Value.right.Communicator.Write<bool>("M103", true);
-                                    }
-                                catch (Exception)
-                                {
-
-
-                                }
-                            }
+                        if (devices.Value.left.Communicator.Read<float>("D80")>= liftPos-5)//鍒拌揪鏈�澶т綅缃�)
+                        {
+                                    messages.Add($"杞ㄩ亾绔檣deptId}宸︿几缂╂潌宸插埌鏈�澶т綅缃�");
+                           
                         }
+                        else
+                        {
+                                    devices.Value.left.Communicator.Write<int>("D1022", liftPos);//浼稿嚭浣嶇疆
+                                    devices.Value.left.Communicator.Write<int>("D1002", ext);//宸LC鑷姩鍔ㄤ几鍑虹缉鍥為�熷害
+                                    devices.Value.left.Communicator.Write<bool>("M102", true);//浼稿嚭鎸夐挳
+                            
+                        } 
+                        }
+                        catch { }
+                
+                        try
+                        {
+                        if (devices.Value.left.Communicator.Read<float>("D80") >=rightPos-5)
+                        {
+                                    messages.Add($"杞ㄩ亾绔檣deptId}鍙充几缂╂潌宸插埌鏈�澶т綅缃�");
+                        
+                        }
+                        else
+                        {
+                                    devices.Value.right.Communicator.Write<int>("D1022", rightPos);
+                                    devices.Value.right.Communicator.Write<int>("D1002", ret);
+                            devices.Value.right.Communicator.Write<bool>("M102", true);
+                            
+                        }                        }
+                        catch { }
+                    
+                }
+                else if (extendedState == "缂╁洖")
+                {
+                    
+                        try
+                        {
+                        if (devices.Value.left.Communicator.Read<bool>("M115")) //鍒拌揪鍘熺偣浣�
+                        {
+                                    messages.Add($"杞ㄩ亾绔檣deptId}宸︿几缂╂潌宸插埌鍘熺偣");
+                           
+                        }
+                        else
+                        {
+                                    devices.Value.left.Communicator.Write<int>("D1022", liftPos);//浼稿嚭浣嶇疆
+                                    devices.Value.left.Communicator.Write<int>("D1002", ext);//宸LC鑷姩浼�=缂╁洖鍑虹缉鍥為�熷害
+                            devices.Value.left.Communicator.Write<bool>("M103", true);//宸lc缂╁洖鎸夐挳
+                            
+                         }                           
+                    }
+                        catch { }
+                    
+
+                   
+                        try
+                        {
+                        if (devices.Value.right.Communicator.Read<bool>("M115"))
+                        {
+                                    messages.Add($"杞ㄩ亾绔檣deptId}鍙充几缂╂潌宸插埌鍘熺偣");
+                          
+                        }
+                        else
+                        {
+                                    devices.Value.right.Communicator.Write<int>("D1022", rightPos);
+                                    devices.Value.right.Communicator.Write<int>("D1002", ret);
+                            devices.Value.right.Communicator.Write<bool>("M103", true);
+                            
+                         }
+                          
+                          
+                        }
+                        catch { }
+                    
+                }
                         else
                         {
                             return new WebResponseContent { Status = false, Message = "鏈煡鎿嶄綔鍛戒护" };
@@ -232,144 +213,147 @@
         /// <param name="DeptId">鑲¢亾鍙�</param>
         /// <returns></returns>
         public WebResponseContent ManualOperation(string position, string ExtendedState,int DeptId)
-                {
+          {
             try
             {
+                if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid))
+                {
+                    return new WebResponseContent { Status = false, Message = "閰嶇疆椤� DepartmentID 鏃犳硶杞崲涓烘暣鏁�" };
+                }
+                var devices = GetDevicesByDeptId(deid);
 
-                var devices = GetDevicesByDeptId(DeptId);
-                if (devices == null)
-                    return new WebResponseContent { Status = false, Message = "璁惧鏈壘鍒�" };
+                //淇╀釜plc宸﹀彸鍚勪竴涓�
+                //OtherDevice liftotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG001");
+                //OtherDevice rightotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG002");
 
-                var para = BaseDal.QueryData(x=>x.Deptid== DeptId).OrderByDescending(x => x.CreateDate).FirstOrDefault();
-                if (para == null)
-                    return new WebResponseContent { Status = false, Message = "鍙傛暟鏈厤缃�" };
-
+                //鎵惧埌Dt_Parameters涓殑鏈�鏂颁竴鏉℃暟鎹牴鎹綋鍓嶇殑deid
+                var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault();
                 int ext = (int)para.ManualExtend;//宸LC鎵嬪姩浼稿嚭缂╁洖閫熷害
                 int ret = (int)para.ManualRetraction;//鍙砅LC鎵嬪姩浼稿嚭缂╁洖閫熷害
                 int liftPosition = (int)para.LeftPosition;//宸︿几鍑轰綅缃�
                 int rigtpostition = (int)para.RightPosition;//鍙充几鍑轰綅缃�
-                bool canLeft = true,
-                   canRight = true;
+                //bool canLeft = true,
+                // canRight = true;
                 string message = "";
 
                 try
                 {
-                    var leftOrigin = devices.Value.left.Communicator.Read<bool>("M115");
-
-
-                    if (leftOrigin)
+                    if (devices.Value.left.Communicator.Read<bool>("M117")) //榛樿鏄痜lase 
                     {
-                        message += "宸LC宸插埌鍘熺偣锛�";
-                        canLeft = false;
+
+                        return new WebResponseContent { Status = true, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
                     }
 
                 }
                 catch (Exception)
-                { }
+                {
+                }
                 try
                 {
-                    var rightOrigin = devices.Value.right.Communicator.Read<bool>("M115");
-                    if (rightOrigin)
+                    if (devices.Value.right.Communicator.Read<bool>("M117"))
                     {
-                        message += "鍙砅LC宸插埌鍘熺偣锛�";
-                        canRight = false;
+                        return new WebResponseContent { Status = false, Message = "鐜板湪姝e湪杩涜涓紝绛夊緟鎿嶄綔瀹屾垚" };
                     }
+
                 }
                 catch (Exception)
                 {
                 }
-
-               
-                    try
-                    {
-                        var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//宸lc鍒拌揪鐩爣浣嶇疆
-                        if (lefttarget)
-                        {
-                            message += "宸lc鍒拌揪鐩爣浣嶇疆锛�";
-                            canLeft = false;
-                        }
-                    }
-                    catch (Exception)
-                    {
-                    }
-                    try
-                    {
-                        var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//鍙硃lc鍒拌揪鐩爣浣嶇疆
-                        if (righttarget)
-                        {
-                            message += "鍙硃lc鍒拌揪鐩爣浣嶇疆锛�";
-                            canRight = false;
-                        }
-
-                    }
-                    catch (Exception)
-                    {
-                    }
-
-
-                if (canLeft)
+                if (position == "宸�" && ExtendedState == "浼稿嚭")
                 {
-                    if (position == "宸�" && ExtendedState == "浼稿嚭")
+                    if (devices.Value.left.Communicator.Read<float>("D80") >= liftPosition - 5) //鍒拌揪鐩爣浣嶇疆
                     {
+                        message += "宸︿几缂╂潌鍒拌揪鐩爣浣嶇疆锛�";
+                    }
+                    else
+                    {
+                        devices.Value.left.Communicator.Write<int>("D1004", liftPosition);//宸︿几鍑轰綅缃�
                         devices.Value.left.Communicator.Write<int>("D1000", ext);//宸LC鎵嬪姩浼稿嚭缂╁洖閫熷害
                         devices.Value.left.Communicator.Write<bool>("M100", true);//浼稿嚭鎸夐挳
                         Thread.Sleep(100); // 绛夊緟100ms锛堟ā鎷熸寜閽寜涓嬶級
                         devices.Value.left.Communicator.Write<bool>("M100", false); // 閲婃斁鎸夐挳
-                        devices.Value.left.Communicator.Write<int>("D1002", liftPosition);//宸︿几鍑轰綅缃�
+
+
                         Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ext}");
                     }
-                    else if (position == "宸�" && ExtendedState == "缂╁洖")
+
+                }
+                else if (position == "宸�" && ExtendedState == "缂╁洖")
+                {
+                    if (devices.Value.left.Communicator.Read<bool>("M115"))//缂╁洖鐨勬椂鍊欏垽鏂�) 
                     {
+                        message += "宸LC宸插埌鍘熺偣锛�";
+                    }
+                    else
+                    {
+                        devices.Value.left.Communicator.Write<int>("D1004", liftPosition);//浼稿嚭浣嶇疆
                         devices.Value.left.Communicator.Write<int>("D1000", ext);//宸LC鎵嬪姩浼稿嚭缂╁洖閫熷害
                         devices.Value.left.Communicator.Write<bool>("M101", true);
                         Thread.Sleep(100); // 绛夊緟100ms锛堟ā鎷熸寜閽寜涓嬶級
                         devices.Value.left.Communicator.Write<bool>("M101", false); // 閲婃斁鎸夐挳
                         Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄧ缉鍥瀧ext}");
                     }
+
                 }
-                if (canRight)
+
+                if (position == "鍙�" && ExtendedState == "浼稿嚭")
                 {
-                    if (position == "鍙�" && ExtendedState == "浼稿嚭")
+                    if (devices.Value.right.Communicator.Read<float>("D80") >= rigtpostition - 5)
                     {
+                        message += "鍙充几缂╂潌鍒拌揪鐩爣浣嶇疆锛�";
+                    }
+                    else
+                    {
+                        devices.Value.right.Communicator.Write<int>("D1004", rigtpostition);//鍙充几鍑轰綅缃�
                         devices.Value.right.Communicator.Write<int>("D1000", ret);//鍙砅LC鎵嬪姩浼稿嚭缂╁洖閫熷害
                         devices.Value.right.Communicator.Write<bool>("M100", true);
                         Thread.Sleep(100); // 绛夊緟100ms锛堟ā鎷熸寜閽寜涓嬶級
                         devices.Value.right.Communicator.Write<bool>("M100", false); // 閲婃斁鎸夐挳
-                        devices.Value.right.Communicator.Write<int>("D1002", liftPosition);//宸︿几鍑轰綅缃�
                         Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄤ几鍑簕ret}");
                     }
-                    else if (position == "鍙�" && ExtendedState == "缂╁洖")
+
+
+                }
+                else if (position == "鍙�" && ExtendedState == "缂╁洖")
+                {
+                    if (devices.Value.right.Communicator.Read<bool>("M115"))
                     {
+                        message += "鍙充几缂╂潌宸插埌鍘熺偣锛�";
+                    }
+                    else
+                    {
+                        devices.Value.right.Communicator.Write<int>("D1004", rigtpostition);//浼稿嚭浣嶇疆
                         devices.Value.right.Communicator.Write<int>("D1000", ret);//鍙砅LC鎵嬪姩浼稿嚭缂╁洖閫熷害
                         devices.Value.right.Communicator.Write<bool>("M101", true);
                         Thread.Sleep(100); // 绛夊緟100ms锛堟ā鎷熸寜閽寜涓嬶級
                         devices.Value.right.Communicator.Write<bool>("M101", false); // 閲婃斁鎸夐挳
                         Console.WriteLine($"{position}浼哥缉鏉嗘墜鍔ㄧ缉鍥瀧ret}");
                     }
+
                 }
 
-                else
+
+
+                return new WebResponseContent
                 {
-                    return new WebResponseContent { Status = false, Message = "鐘舵�佸弬鏁伴敊璇�" };
-                }
-
-                return new WebResponseContent { Status = true,
-                    Message = string.IsNullOrEmpty(message) ? "鎵ц鎴愬姛" : $"鎵ц澶辫触锛歿message}",
+                    Status = true,
+                    Message = string.IsNullOrEmpty(message) ? "鎵ц鎴愬姛" : $"{message}",
                     Data = new
                     {
                         ManualExtend = ext,
                         ManualRetraction = ret,
                         message
                     }
-
                 };
-
             }
+
+
             catch (Exception ex)
             {
                 return new WebResponseContent { Status = false, Message = ex.Message };
 
             }
+
         }
 
 

--
Gitblit v1.9.3