yanjinhui
2025-06-07 70900e697720bfe657bbf28067caeeb03bfdbf8f
project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
@@ -56,105 +56,119 @@
                int ret = (int)para.RetractionSpeed;//右PLC自动伸出缩回速度
                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");//左plc到原点位置信号
                    var rightorigin = devices.Value.right.Communicator.Read<bool>("M115");//右plc到达原点位置信号
                    if (leftorigin == true || rightorigin == true)
                        var leftorigin = devices.Value.left.Communicator.Read<bool>("M115");  //到达原点位置
                        if (leftorigin)
                    {
                        return new WebResponseContent { Status = false, Message = "已到原始点" };
                            canLeftWork = false;
                            message += "左PLC已到原点;";
                    }
                }
                catch (Exception)
                {
                }
                try
                {
                    var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//左plc到达目标位置
                    var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//右plc到达目标位置
                    if (lefttarget == true || righttarget == true)
                        var rightorigin = devices.Value.right.Communicator.Read<bool>("M115");
                        if (rightorigin)
                    {
                        return new WebResponseContent { Status = false, Message = "已到最大值" };
                            canRightWork = false;
                            message += "右PLC已到原点;";
                    }
                }
                catch (Exception)
                {
                    }
                try
                {
                    var lefttarget = devices.Value.left.Communicator.Read<bool>("M116"); //到达最大位置
                    if (lefttarget)
                    {
                        canLeftWork = false;
                        message += "左PLC已到最大值;";
                    }
                }
                catch { }
                try
                {
                    var righttarget = devices.Value.right.Communicator.Read<bool>("M116");
                    if (righttarget)
                    {
                        canRightWork = false;
                        message += "右PLC已到最大值;";
                    }
                }
                catch (Exception)
                {
                }
                if (ExtendedState == "伸出")
                {
                    if (canLeftWork)
                    {
                    try
                    {
                        devices.Value.left.Communicator.Write<int>("D1001", ext);//左PLC自动伸出缩回速度
                            devices.Value.left.Communicator.Write<int>("D1001", ext);//左PLC自动动伸出缩回速度
                        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);//左伸出位置
                            devices.Value.left.Communicator.Write<int>("D1002", liftPosition);//伸出位置
                    }
                    catch (Exception)
                    {
                        catch { }
                    }
                    }
                    if (canRightWork)
                    {
                    try
                    {
                        devices.Value.right.Communicator.Write<int>("D1001", ret);//右PLC自动伸出缩回速度
                        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);//右伸出位置
                            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 (Exception)
                    {
                        catch { }
                    }
                    Console.WriteLine($"自动伸缩杆伸出 {ext},左伸出位置{liftPosition},右伸出位置{rigtpostition}");
                }
                else if (ExtendedState == "缩回")
                {
                    if (canLeftWork)
                    {
                    try
                    {
                        devices.Value.left.Communicator.Write<int>("D1001", ext);//左PLC自动伸出缩回速度
                        devices.Value.left.Communicator.Write<bool>("M103", true);//缩回按钮
                        Thread.Sleep(100); // 等待100ms(模拟按钮按下)
                        devices.Value.left.Communicator.Write<bool>("M103", false); // 释放按钮
                    }
                    catch (Exception)
                    {
                            devices.Value.left.Communicator.Write<int>("D1001", ext);//左PLC自动伸=缩回出缩回速度
                            devices.Value.left.Communicator.Write<bool>("M103", true);//左plc缩回按钮
                    }
                        catch { }
                    }
                    if (canRightWork)
                    {
                    try
                    {
                        devices.Value.right.Communicator.Write<int>("D1001", ret);//右PLC自动伸出缩回速度
                        devices.Value.right.Communicator.Write<bool>("M103", true);//缩回按钮
                        Thread.Sleep(100); // 等待100ms(模拟按钮按下)
                        devices.Value.right.Communicator.Write<bool>("M103", false); // 释放按钮
                    }
                    catch (Exception)
                    {
                            devices.Value.right.Communicator.Write<int>("D1001", ret);
                            devices.Value.right.Communicator.Write<bool>("M103", true);
                    }
                    Console.WriteLine($"自动伸缩杆缩回 {ret}");
                        catch { }
                }
                }
                else
                {
                    return new WebResponseContent { Status = false, Message = "未知的操作命令" };
                }
                return new WebResponseContent { Status = true, Message = "成功",
                    Data = new
                return new WebResponseContent
                    {
                        ExtendSpeed = ext,
                        RetractionSpeed = ret,
                    }
                    Status = true,
                    Message = string.IsNullOrEmpty(message) ? "执行成功" : $"部分PLC未执行:{message}",
                    Data = new { ExtendSpeed = ext, RetractionSpeed = ret }
                };
            }
            catch (Exception ex)
            {
@@ -193,37 +207,69 @@
                int ret = (int)para.ManualRetraction;//右PLC手动伸出缩回速度
                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");//左plc到原点位置信号
                    var rightorigin = devices.Value.right.Communicator.Read<bool>("M115");//右plc到达原点位置信号
                    if (leftorigin == true || rightorigin == true)
                    var leftOrigin = devices.Value.left.Communicator.Read<bool>("M115");
                    if (leftOrigin)
                    {
                        return new WebResponseContent { Status = false, Message = "已到原始点" };
                        message += "左PLC已到原点;";
                        canLeft=false;
                    }
                }
                catch (Exception )
                {     }
                try
                {
                    var rightOrigin = devices.Value.right.Communicator.Read<bool>("M115");
                    if (rightOrigin)
                    {
                        message += "右PLC已到原点;";
                        canRight = false;
                    }
                }
                catch (Exception)
                {
                }
                try
                {
                try
                {
                    var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//左plc到达目标位置
                    var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//右plc到达目标位置
                    if (lefttarget == true || righttarget == true)
                        if (lefttarget)
                    {
                        return new WebResponseContent { Status = false, Message = "已到最大值" };
                            message += "左plc到达目标位置;";
                            canLeft = false;
                        }
                    }
                    catch (Exception)
                    {
                    }
                    try
                    {
                        var righttarget = devices.Value.right.Communicator.Read<bool>("M116");//右plc到达目标位置
                        if (righttarget)
                        {
                            message += "右plc到达目标位置;";
                            canRight = false;
                    }
                }
                catch (Exception)
                {
                }
                }
                catch (Exception )
                { }
                if (canLeft) //没有到原点或最大值的时候才执行下面的语句
                {
                if (position == "左" && ExtendedState == "伸出")
                {
                    devices.Value.left.Communicator.Write<int>("D1000", ext);//左PLC手动伸出缩回速度
@@ -233,6 +279,7 @@
                    devices.Value.left.Communicator.Write<int>("D1002", liftPosition);//左伸出位置
                    
                    Console.WriteLine($"{position}伸缩杆手动伸出{ext}");
                }
                else if (position == "左" && ExtendedState == "缩回")
                {
@@ -242,7 +289,12 @@
                    devices.Value.left.Communicator.Write<bool>("M101", false); // 释放按钮
                    Console.WriteLine($"{position}伸缩杆手动缩回{ext}");
                }
                else if (position == "右" && ExtendedState == "伸出")
                }
                if (canRight)
                {
                    if (position == "右" && ExtendedState == "伸出")
                {
                    devices.Value.right.Communicator.Write<int>("D1000", ret);//右PLC手动伸出缩回速度
                    devices.Value.right.Communicator.Write<bool>("M100", true);
@@ -250,6 +302,7 @@
                    devices.Value.right.Communicator.Write<bool>("M100", false); // 释放按钮
                    devices.Value.right.Communicator.Write<int>("D1002", liftPosition);//左伸出位置
                    Console.WriteLine($"{position}伸缩杆手动伸出{ret}");
                }
                else if (position == "右" && ExtendedState == "缩回")
                {
@@ -259,12 +312,14 @@
                    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
                    }
                };
            }