z8018
2025-06-09 0aac30d1c6f1ca0c2bf7662fb9ca4f0d98b3bca7
project/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
@@ -48,105 +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;//左PLC自动伸出缩回速度
                int ret = (int)para.RetractionSpeed;//右PLC自动伸出缩回速度
                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 += "左PLC已到原点;";
                        }
                    }
                    catch (Exception)
                    {
                    }
                    try
                    {
                        var rightorigin = devices.Value.right.Communicator.Read<bool>("M115");
                        if (rightorigin)
                        {
                            canRightWork = false;
                            message += "右PLC已到原点;";
                        }
                    }
                    catch (Exception)
                    {
                    }
                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 lefttarget = devices.Value.left.Communicator.Read<bool>("M116"); //到达最大位置
                    if (lefttarget)
                    {
                        return new WebResponseContent { Status = false, Message = "已到原始点" };
                        canLeftWork = false;
                        message += "左PLC已到最大值;";
                    }
                }
                catch { }
                try
                {
                    var righttarget = devices.Value.right.Communicator.Read<bool>("M116");
                    if (righttarget)
                    {
                        canRightWork = 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)
                    {
                        return new WebResponseContent { Status = false, Message = "已到最大值" };
                    }
                }
                catch (Exception)
                {
                }
                if (ExtendedState == "伸出")
                {
                    try
                    if (canLeftWork)
                    {
                        devices.Value.left.Communicator.Write<int>("D1001", ext);//左PLC自动伸出缩回速度
                        devices.Value.left.Communicator.Write<bool>("M102", true);//伸出按钮
                        devices.Value.left.Communicator.Write<int>("D1002", liftPosition);//左伸出位置
                        try
                        {
                            devices.Value.left.Communicator.Write<int>("D1001", ext);//左PLC自动动伸出缩回速度
                            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);//右PLC自动伸出缩回速度
                        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);
                            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);//左PLC自动伸出缩回速度
                        devices.Value.left.Communicator.Write<bool>("M103", true);//缩回按钮
                        try
                        {
                            devices.Value.left.Communicator.Write<int>("D1001", ext);//左PLC自动伸=缩回出缩回速度
                            devices.Value.left.Communicator.Write<bool>("M103", true);//左plc缩回按钮
                        }
                        catch { }
                    }
                    catch (Exception)
                    {
                    }
                    try
                    if (canRightWork)
                    {
                        devices.Value.right.Communicator.Write<int>("D1001", ret);//右PLC自动伸出缩回速度
                        devices.Value.right.Communicator.Write<bool>("M103", true);//缩回按钮
                        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)
            {
@@ -183,68 +205,121 @@
                var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault();
                int ext = (int)para.ManualExtend;//左PLC手动伸出缩回速度
                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
                {
                    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)
                    try
                    {
                        return new WebResponseContent { Status = false, Message = "已到最大值" };
                        var lefttarget = devices.Value.left.Communicator.Read<bool>("M116");//左plc到达目标位置
                        if (lefttarget)
                        {
                            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)
                catch (Exception )
                { }
                if (canLeft) //没有到原点或最大值的时候才执行下面的语句
                {
                    if (position == "左" && ExtendedState == "伸出")
                    {
                        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 == "缩回")
                    {
                        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 == "伸出")
                    {
                        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}");
                if (position == "左" && ExtendedState == "伸出")
                {
                    devices.Value.left.Communicator.Write<int>("D1000", ext);//左PLC手动伸出缩回速度
                    devices.Value.left.Communicator.Write<bool>("M100", true);//伸出按钮
                    Console.WriteLine($"{position}伸缩杆手动伸出{ext}");
                }
                else if (position == "左" && ExtendedState == "缩回")
                {
                    devices.Value.left.Communicator.Write<int>("D1000", ext);//左PLC手动伸出缩回速度
                    devices.Value.left.Communicator.Write<bool>("M101", true);
                    Console.WriteLine($"{position}伸缩杆手动缩回{ext}");
                }
                else if (position == "右" && ExtendedState == "伸出")
                {
                    devices.Value.right.Communicator.Write<int>("D1000", ret);//右PLC手动伸出缩回速度
                    devices.Value.right.Communicator.Write<bool>("M100", true);
                    Console.WriteLine($"{position}伸缩杆手动伸出{ret}");
                }
                else if (position == "右" && ExtendedState == "缩回")
                {
                    devices.Value.right.Communicator.Write<int>("D1000", ret);//右PLC手动伸出缩回速度
                    devices.Value.right.Communicator.Write<bool>("M101", true);
                    Console.WriteLine($"{position}伸缩杆手动缩回{ret}");
                }
                    }
                    else if (position == "右" && ExtendedState == "缩回")
                    {
                        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 = "成功" ,
                    Message = string.IsNullOrEmpty(message) ? "执行成功" : $"执行失败:{message}",
                    Data = new
                    {
                        ManualExtend = ext,
                        ManualRetraction = ret
                        ManualRetraction = ret,
                        message
                    }
                };
            }