yanjinhui
2025-06-09 9f3858dd723a69c56dbab909e0c7e6c5ef8b85a8
project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
@@ -15,6 +15,7 @@
using WIDESEAWCS_ITelescopicService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using static WIDESEAWCS_Common.Face.TH_Faces;
namespace WIDESEAWCS_TelescopicService
@@ -37,6 +38,7 @@
        /// <returns></returns>
        public WebResponseContent automation(string ExtendedState)
        {
            try
            {
@@ -56,54 +58,27 @@
                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");  //到达原点位置
                        if (leftorigin)
                        {
                            canLeftWork = false;
                            message += "左PLC已到原点;";
                        }
                    }
                    catch (Exception)
                    {
                    }
                    try
                    {
                        var rightorigin = devices.Value.right.Communicator.Read<bool>("M115");
                        if (rightorigin)
                        {
                            canRightWork = false;
                            message += "右PLC已到原点;";
                        }
                    }
                    catch (Exception)
                    {
                    }
                try
                {
                    var lefttarget = devices.Value.left.Communicator.Read<bool>("M116"); //到达最大位置
                    if (lefttarget)
                    if (devices.Value.left.Communicator.Read<bool>("M117"))
                    {
                        canLeftWork = false;
                        message += "左PLC已到最大值;";
                        return new WebResponseContent { Status = true, Message = "现在正在进行中,等待操作完成" };
                    }
                }
                catch { }
                catch (Exception)
                {
                }
                try
                {
                    var righttarget = devices.Value.right.Communicator.Read<bool>("M116");
                    if (righttarget)
                    if (devices.Value.right.Communicator.Read<bool>("M117"))
                    {
                        canRightWork = false;
                        message += "右PLC已到最大值;";
                        return new WebResponseContent { Status = true, Message = "现在正在进行中,等待操作完成" };
                    }
                }
                catch (Exception)
                {
@@ -111,51 +86,79 @@
                if (ExtendedState == "伸出")
                {
                    if (canLeftWork)
                    {
                        try
                        {
                            devices.Value.left.Communicator.Write<int>("D1001", ext);//左PLC自动动伸出缩回速度
                        if (devices.Value.left.Communicator.Read<float>("D80")>= liftPosition-5)//到达最大位置)
                        {
                            message += "左PLC已到最大位置;";
                        }
                        else
                        {
                            devices.Value.left.Communicator.Write<int>("D1022", liftPosition);//伸出位置
                            devices.Value.left.Communicator.Write<int>("D1002", ext);//左PLC自动动伸出缩回速度
                            devices.Value.left.Communicator.Write<bool>("M102", true);//伸出按钮
                            devices.Value.left.Communicator.Write<int>("D1002", liftPosition);//伸出位置
                        }
                        }
                        catch { }
                    }
                    if (canRightWork)
                    {
                        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);
                        if (devices.Value.right.Communicator.Read<float>("D80") >= rigtpostition-5)
                        {
                            message += "右PLC已到最大位置;";
                        }
                        else
                        {
                            devices.Value.right.Communicator.Write<int>("D1022", rigtpostition);
                            devices.Value.right.Communicator.Write<int>("D1002", ret);
                            devices.Value.right.Communicator.Write<bool>("M102", true);
                        }                        }
                        catch { }
                    }
                }
                else if (ExtendedState == "缩回")
                {
                    if (canLeftWork)
                    {
                        try
                        {
                            devices.Value.left.Communicator.Write<int>("D1001", ext);//左PLC自动伸=缩回出缩回速度
                        if (devices.Value.left.Communicator.Read<bool>("M115")) //到达原点位
                        {
                            message += "左伸缩杆已到原点;";
                        }
                        else
                        {
                            devices.Value.left.Communicator.Write<int>("D1022", liftPosition);
                            devices.Value.left.Communicator.Write<int>("D1002", ext);//左PLC自动伸=缩回出缩回速度
                            devices.Value.left.Communicator.Write<bool>("M103", true);//左plc缩回按钮
                            
                        }
                        catch { }
                        }
                    }
                        catch { }
                    if (canRightWork)
                    {
                        try
                        {
                            devices.Value.right.Communicator.Write<int>("D1001", ret);
                        if (devices.Value.right.Communicator.Read<bool>("M115"))
                        {
                            message += "右伸缩杆已到原点;";
                        }
                        else
                        {
                            devices.Value.right.Communicator.Write<int>("D1022", rigtpostition);
                            devices.Value.right.Communicator.Write<int>("D1002", ret);
                            devices.Value.right.Communicator.Write<bool>("M103", true);
                        }
                          
                        }
                        catch { }
                    }
                }
                else
                {
@@ -165,8 +168,8 @@
                return new WebResponseContent
                {
                    Status = true,
                    Message = string.IsNullOrEmpty(message) ? "执行成功" : $"部分PLC未执行:{message}",
                    Data = new { ExtendSpeed = ext, RetractionSpeed = ret }
                    Message = string.IsNullOrEmpty(message) ? "执行成功" : $"{message}",
                    Data = new { ExtendSpeed = ext, RetractionSpeed = ret,liftweiz= liftPosition,rightweiz= rigtpostition }
                };
            }
@@ -207,114 +210,112 @@
                int ret = (int)para.ManualRetraction;//右PLC手动伸出缩回速度
                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 (devices.Value.left.Communicator.Read<bool>("M117")) //默认是flase
                    {
                    if (leftOrigin)
                    {
                        message += "左PLC已到原点;";
                        canLeft=false;
                        return new WebResponseContent { Status = true, Message = "现在正在进行中,等待操作完成" };
                    }
                }
                catch (Exception )
                {     }
                try
                {
                    var rightOrigin = devices.Value.right.Communicator.Read<bool>("M115");
                    if (rightOrigin)
                    {
                        message += "右PLC已到原点;";
                        canRight = false;
                    }
                }
                catch (Exception)
                {
                }
                try
                {
                    try
                    if (devices.Value.right.Communicator.Read<bool>("M117"))
                    {
                        var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//左plc到达目标位置
                        if (lefttarget)
                        {
                            message += "左plc到达目标位置;";
                            canLeft = false;
                        }
                        return new WebResponseContent { Status = false, Message = "现在正在进行中,等待操作完成" };
                    }
                    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) //没有到原点或最大值的时候才执行下面的语句
                catch (Exception)
                {
                    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);//左PLC手动伸出缩回速度
                        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 += "左PLC已到原点;";
                    }
                    else
                    {
                        devices.Value.left.Communicator.Write<int>("D1004", liftPosition);//伸出位置
                        devices.Value.left.Communicator.Write<int>("D1000", ext);//左PLC手动伸出缩回速度
                        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);//右PLC手动伸出缩回速度
                        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);//右PLC手动伸出缩回速度
                        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 = string.IsNullOrEmpty(message) ? "执行成功" : $"执行失败:{message}",
                }
                return new WebResponseContent
                {
                    Status = true,
                    Message = string.IsNullOrEmpty(message) ? "执行成功" : $"{message}",
                    Data = new
                    {
                        ManualExtend = ext,
@@ -323,6 +324,8 @@
                    }
                };
            }
            catch (Exception ex)
            {
                return new WebResponseContent { Status = false, Message = ex.Message };