yanjinhui
2025-06-05 fcd49db2ee33ee2e1d33e5a41e53d9897a8a3b0f
project/ºǫ́¹ÜÀí/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
@@ -60,25 +60,93 @@
                    int ext = (int)para.ExtendSpeed;//å·¦PLC自动伸出缩回速度
                    int ret = (int)para.RetractionSpeed;//右PLC自动伸出缩回速度
                    int liftPosition = (int)para.LeftPosition;//左伸出位置
                    int rigtpostition = (int)para.RightPosition;//右伸出位置
                    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)
                        {
                            return new WebResponseContent { Status = false, Message = "已到原始点" };
                        }
                    }
                    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 == "伸出")
                    {
                        devices.Value.left.Communicator.Write<int>("D1001", ext);//伸出速度
                        devices.Value.left.Communicator.Write<bool>("M102", true);//伸出按钮
                        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 (Exception)
                        {
                        devices.Value.right.Communicator.Write<int>("D1001", ret);
                        devices.Value.right.Communicator.Write<bool>("M102", true);
                        }
                        try
                        {
                            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);//右伸出位置
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                        Console.WriteLine($"DeptId={deptId} ï¼Œå·¦é€Ÿåº¦={ext},右速度={ret}");
                    }
                    else if (extendedState == "缩回")
                    {
                        devices.Value.left.Communicator.Write<int>("D1001", ext);//缩回速度
                        devices.Value.left.Communicator.Write<bool>("M103", true);//缩回按钮
                        try
                        {
                            devices.Value.left.Communicator.Write<int>("D1001", ext);//缩回速度
                            devices.Value.left.Communicator.Write<bool>("M103", true);//缩回按钮
                        }
                        catch (Exception)
                        {
                        devices.Value.right.Communicator.Write<int>("D1001", ret);
                        devices.Value.right.Communicator.Write<bool>("M103", true);
                            throw;
                        }
                        try
                        {
                            devices.Value.right.Communicator.Write<int>("D1001", ret);
                            devices.Value.right.Communicator.Write<bool>("M103", true);
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                        Console.WriteLine($"DeptId={deptId} ç¼©å›žæ“ä½œï¼Œå·¦é€Ÿåº¦={ext},右速度={ret}");
                    }
                    else
@@ -97,61 +165,6 @@
        }
        /// <summary>
        /// æ‰‹åŠ¨æŽ§åˆ¶ï¼Œä¼¸ç¼©æ†çš„ç¼©å›žå’Œä¼¸å‡ºé€Ÿåº¦
        /// </summary>
        /// <param name="position">伸缩杆的位置(左右)</param>
        /// <param name="ExtendedState">伸/缩状态</param>
        /// <returns></returns>
        ///
        //public WebResponseContent ManualOperation(string position, string ExtendedState)
        //{
        //    try
        //    {
        //        //俩个plc左右各一个
        //        OtherDevice liftotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG001");
        //        OtherDevice rightotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG002");
        //        //找到Dt_Parameters中的最新一条数据
        //        var para = BaseDal.QueryData().OrderBy(x => x.CreateDate).FirstOrDefault();
        //        int ext = (int)para.ManualExtend;//自动伸出速度
        //        int ret = (int)para.ManualRetraction;//自动缩回速度
        //            if (position == "å·¦" && ExtendedState == "伸出")
        //            {
        //                var values = liftotherDevice.Communicator.Write<int>("D500", ext);//速度
        //    var button = liftotherDevice.Communicator.Write<bool>("M100", true);//伸出按钮
        //    Console.WriteLine($"{position}伸缩杆伸出{ext}");
        //            }
        //            if (position == "å·¦" && ExtendedState == "缩回")
        //            {
        //                var values = liftotherDevice.Communicator.Write<int>("D501", ret);
        //var button = liftotherDevice.Communicator.Write<bool>("M101", true);//缩回按钮
        //Console.WriteLine($"{position}伸缩杆缩回{ret}");
        //            }
        //        if (position == "右" && ExtendedState == "伸出")
        //        {
        //            var values = rightotherDevice.Communicator.Write<int>("D500", ext);//速度
        //            var button = rightotherDevice.Communicator.Write<bool>("M100", true);//伸出按钮
        //            Console.WriteLine($"{position}伸缩杆伸出{ext}");
        //        }
        //        if (position == "右" && ExtendedState == "缩回")
        //        {
        //            var values = rightotherDevice.Communicator.Write<int>("D501", ret);
        //            var button = rightotherDevice.Communicator.Write<bool>("M101", true);//缩回按钮
        //            Console.WriteLine($"{position}伸缩杆缩回{ret}");
        //        }
        //        return new WebResponseContent { Status = true, Message = "成功" };
        //    }
        //    catch (Exception ex)
        //    {
        //        return new WebResponseContent { Status = false, Message = ex.Message };
        //    }
        //}
@@ -177,6 +190,36 @@
                int ext = (int)para.ManualExtend;//å·¦PLC手动伸出缩回速度
                int ret = (int)para.ManualRetraction;//右PLC手动伸出缩回速度
                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)
                    {
                        return new WebResponseContent { Status = false, Message = "已到原始点" };
                    }
                }
                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 (position == "å·¦" && ExtendedState == "伸出")
                {
@@ -227,6 +270,72 @@
        /// <summary>
        ///当自动伸出需要暂停时,暂停按钮
        /// </summary>
        /// <returns></returns>
        public WebResponseContent PauseButton(int deptid)
        {
            try
            {
                //根据int.TryParse(AppSettings.Get("DepartmentID")读取到当前是轨道几,所有人都只能操作当前
                var devices = GetDevicesByDeptId(deptid);
                try
                {
                    devices.Value.left.Communicator.Write<bool>("M104", true);
                }
                catch (Exception)
                {
                    throw;
                }
                try
                {
                    devices.Value.right.Communicator.Write<bool>("M104", true);
                }
                catch (Exception)
                {
                    throw;
                }
                return new WebResponseContent { Status = true, Message = "暂停成功", Data = devices };
            }
            catch (Exception ex)
            {
                return new WebResponseContent { Status = false, Message = ex.Message };
            }
        }
        /// <summary>
        /// ä¼¸ç¼©æ†å½“前位置(这个没有用)
        /// <param name="deptid">轨道站号</param>
        public WebResponseContent CurrentLocation(int deptid)
        {
            try
            {
                var devices = GetDevicesByDeptId(deptid);
                if (devices == null)
                    return new WebResponseContent { Status = false, Message = "设备未找到" };
                var deviceslift = devices.Value.left.Communicator.Read<float>("D80");
                var devicesright = devices.Value.right.Communicator.Read<float>("D80");
                Console.WriteLine($"当前左右伸缩杆返回速度分别为为{deviceslift}");
                return new WebResponseContent
                {
                    Status = true,
                    Data = new { lift = deviceslift, Right = devicesright }
                };
            }
            catch (Exception ex)
            {
                return new WebResponseContent { Status=false,Message=ex.Message};
            }
        }
        /// <summary>
        /// èŽ·å–è®¾å¤‡å·
        /// </summary>
        /// <param name="deptId"></param>
@@ -247,7 +356,7 @@
            return (left, right);
        }
    }
}