From 70900e697720bfe657bbf28067caeeb03bfdbf8f Mon Sep 17 00:00:00 2001 From: yanjinhui <3306209981@qq.com> Date: 星期六, 07 六月 2025 18:57:09 +0800 Subject: [PATCH] 更新伸缩杆的自动和手动接口的提示修改和完善 --- project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs | 299 +++++++++++++++++++++++++++++++++++------------------------ 1 files changed, 177 insertions(+), 122 deletions(-) diff --git a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs index 9f88df3..68f1eda 100644 --- a/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs +++ b/project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs @@ -48,113 +48,127 @@ var devices = GetDevicesByDeptId(deid); //鎵惧埌Dt_Parameters涓殑鏈�鏂颁竴鏉℃暟鎹� - var para = BaseDal.QueryData().Where(x=>x.Deptid== deid).OrderByDescending(x => x.CreateDate).FirstOrDefault(); + var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault(); if (para == null) return new WebResponseContent { Status = false, Message = "鏈壘鍒板弬鏁伴厤缃�" }; int ext = (int)para.ExtendSpeed;//宸LC鑷姩浼稿嚭缂╁洖閫熷害 int ret = (int)para.RetractionSpeed;//鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害 - int liftPosition= (int)para.LeftPosition;//宸︿几鍑轰綅缃� - int rigtpostition= (int)para.RightPosition;//鍙充几鍑轰綅缃� + int liftPosition = (int)para.LeftPosition;//宸︿几鍑轰綅缃� + int rigtpostition = (int)para.RightPosition;//鍙充几鍑轰綅缃� + bool canLeftWork = true; + bool canRightWork = true; + string message = ""; + try + { + var leftorigin = devices.Value.left.Communicator.Read<bool>("M115"); //鍒拌揪鍘熺偣浣嶇疆 + if (leftorigin) + { + canLeftWork = false; + message += "宸LC宸插埌鍘熺偣锛�"; + } + } + catch (Exception) + { + } + try + { + var rightorigin = devices.Value.right.Communicator.Read<bool>("M115"); + if (rightorigin) + { + canRightWork = false; + message += "鍙砅LC宸插埌鍘熺偣锛�"; + } + } + catch (Exception) + { + } + 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) + var lefttarget = devices.Value.left.Communicator.Read<bool>("M116"); //鍒拌揪鏈�澶т綅缃� + + if (lefttarget) { - return new WebResponseContent { Status = false, Message = "宸插埌鍘熷鐐�" }; + canLeftWork = false; + message += "宸LC宸插埌鏈�澶у�硷紱"; + } + + } + catch { } + try + { + var righttarget = devices.Value.right.Communicator.Read<bool>("M116"); + if (righttarget) + { + canRightWork = false; + message += "鍙砅LC宸插埌鏈�澶у�硷紱"; } } 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 == "浼稿嚭") { - try + if (canLeftWork) { - devices.Value.left.Communicator.Write<int>("D1001", ext);//宸LC鑷姩浼稿嚭缂╁洖閫熷害 - devices.Value.left.Communicator.Write<bool>("M102", true);//浼稿嚭鎸夐挳 - Thread.Sleep(100); // 绛夊緟100ms锛堟ā鎷熸寜閽寜涓嬶級 - devices.Value.left.Communicator.Write<bool>("M102", false); // 閲婃斁鎸夐挳 - devices.Value.left.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 { } } - catch (Exception) - { - } - try + if (canRightWork) { - devices.Value.right.Communicator.Write<int>("D1001", ret);//鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害 - devices.Value.right.Communicator.Write<bool>("M102", true);//浼稿嚭鎸夐挳 - Thread.Sleep(100); // 绛夊緟100ms锛堟ā鎷熸寜閽寜涓嬶級 - devices.Value.right.Communicator.Write<bool>("M102", false); // 閲婃斁鎸夐挳 - devices.Value.right.Communicator.Write<int>("D1002", rigtpostition);//鍙充几鍑轰綅缃� + try + { + devices.Value.right.Communicator.Write<int>("D1001", ret); + devices.Value.right.Communicator.Write<bool>("M102", true); + devices.Value.right.Communicator.Write<int>("D1002", rigtpostition); + } + catch { } } - catch (Exception) - { - - } - - Console.WriteLine($"鑷姩浼哥缉鏉嗕几鍑� {ext},宸︿几鍑轰綅缃畕liftPosition}锛屽彸浼稿嚭浣嶇疆{rigtpostition}"); } else if (ExtendedState == "缂╁洖") { - try + if (canLeftWork) { - devices.Value.left.Communicator.Write<int>("D1001", ext);//宸LC鑷姩浼稿嚭缂╁洖閫熷害 - devices.Value.left.Communicator.Write<bool>("M103", true);//缂╁洖鎸夐挳 - Thread.Sleep(100); // 绛夊緟100ms锛堟ā鎷熸寜閽寜涓嬶級 - devices.Value.left.Communicator.Write<bool>("M103", false); // 閲婃斁鎸夐挳 + try + { + devices.Value.left.Communicator.Write<int>("D1001", ext);//宸LC鑷姩浼�=缂╁洖鍑虹缉鍥為�熷害 + devices.Value.left.Communicator.Write<bool>("M103", true);//宸lc缂╁洖鎸夐挳 + + } + catch { } } - catch (Exception) - { - } - try + if (canRightWork) { - devices.Value.right.Communicator.Write<int>("D1001", ret);//鍙砅LC鑷姩浼稿嚭缂╁洖閫熷害 - devices.Value.right.Communicator.Write<bool>("M103", true);//缂╁洖鎸夐挳 - Thread.Sleep(100); // 绛夊緟100ms锛堟ā鎷熸寜閽寜涓嬶級 - devices.Value.right.Communicator.Write<bool>("M103", false); // 閲婃斁鎸夐挳 + try + { + devices.Value.right.Communicator.Write<int>("D1001", ret); + devices.Value.right.Communicator.Write<bool>("M103", true); + + } + catch { } } - catch (Exception) - { - - } - - Console.WriteLine($"鑷姩浼哥缉鏉嗙缉鍥� {ret}"); } - else { return new WebResponseContent { Status = false, Message = "鏈煡鐨勬搷浣滃懡浠�" }; } - return new WebResponseContent { Status = true, Message = "鎴愬姛", - Data = new - { - ExtendSpeed = ext, - RetractionSpeed = ret, - - } + return new WebResponseContent + { + Status = true, + Message = string.IsNullOrEmpty(message) ? "鎵ц鎴愬姛" : $"閮ㄥ垎PLC鏈墽琛岋細{message}", + Data = new { ExtendSpeed = ext, RetractionSpeed = ret } }; + } catch (Exception ex) { @@ -193,78 +207,119 @@ int ret = (int)para.ManualRetraction;//鍙砅LC鎵嬪姩浼稿嚭缂╁洖閫熷害 int liftPosition = (int)para.LeftPosition;//宸︿几鍑轰綅缃� int rigtpostition = (int)para.RightPosition;//鍙充几鍑轰綅缃� + bool canLeft = true, + canRight = true; + string message = ""; + 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) + var leftOrigin = devices.Value.left.Communicator.Read<bool>("M115"); + + + if (leftOrigin) { - return new WebResponseContent { Status = false, Message = "宸插埌鍘熷鐐�" }; + message += "宸LC宸插埌鍘熺偣锛�"; + canLeft=false; + } + + } + catch (Exception ) + { } + try + { + var rightOrigin = devices.Value.right.Communicator.Read<bool>("M115"); + if (rightOrigin) + { + message += "鍙砅LC宸插埌鍘熺偣锛�"; + canRight = false; } } 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) + try { - return new WebResponseContent { Status = false, Message = "宸插埌鏈�澶у��" }; + 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) + { + } } - catch (Exception) + catch (Exception ) + { } + if (canLeft) //娌℃湁鍒板師鐐规垨鏈�澶у�肩殑鏃跺�欐墠鎵ц涓嬮潰鐨勮鍙� + { + if (position == "宸�" && ExtendedState == "浼稿嚭") + { + 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 == "缂╁洖") + { + 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 == "浼稿嚭") + { + 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}"); - if (position == "宸�" && ExtendedState == "浼稿嚭") - { - 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 == "缂╁洖") - { - 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}"); - } - else if (position == "鍙�" && ExtendedState == "浼稿嚭") - { - 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 == "缂╁洖") - { - 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 if (position == "鍙�" && ExtendedState == "缂╁洖") + { + 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}"); + } + } return new WebResponseContent { Status = true, - Message = "鎴愬姛" , + Message = string.IsNullOrEmpty(message) ? "鎵ц鎴愬姛" : $"鎵ц澶辫触锛歿message}", Data = new { ManualExtend = ext, - ManualRetraction = ret + ManualRetraction = ret, + message } }; } -- Gitblit v1.9.3