1
yanjinhui
2025-04-27 01c5166aad248cf4de78d7aeb53c31f961835f02
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_TelescopicService/ParametersService.cs
@@ -1,13 +1,18 @@
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using SqlSugar;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseRepository;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_ITelescopicService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
namespace WIDESEAWCS_TelescopicService
{
@@ -17,10 +22,101 @@
        public ParametersService(IRepository<Dt_Parameters> BaseDal) : base(BaseDal)
        {
        }
        /// <summary>
        /// è‡ªåŠ¨æŽ§åˆ¶ä¼¸ç¼©æ†çš„ä¼¸å‡ºå’Œç¼©å›žé€Ÿåº¦
        /// </summary>
        /// <param name="ExtendedState">伸/出状态</param>
        /// <returns></returns>
        public WebResponseContent automation(string  ExtendedState)
        {
            try
            {
                OtherDevice liftotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceName == "左汇川PLC");
                OtherDevice rightotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceName == "右汇川PLC");
                //找到Dt_Parameters中的最新一条数据
                var para=BaseDal.QueryData().OrderBy(x=>x.CreateDate).FirstOrDefault();
                int ext= (int)para.ExtendSpeed;//自动伸出速度
                int ret= (int)para.RetractionSpeed;//自动缩回速度
                if (ExtendedState == "伸出")
                {
                    var values = liftotherDevice.Communicator.Write<int>("D500", ext);//速度
                    var button = liftotherDevice.Communicator.Write<bool>("M100", true);//伸出按钮
                    var rightvalues = rightotherDevice.Communicator.Write<int>("D500", ext);//速度
                    var rightbutton = rightotherDevice.Communicator.Write<bool>("M100", true);//伸出按钮
                    Console.WriteLine($"伸缩杆伸出{ext}");
                }
                if (ExtendedState=="缩回")
                {
                    var values = liftotherDevice.Communicator.Write<int>("D501", ext);//速度
                    var button = liftotherDevice.Communicator.Write<bool>("M101", true);//缩回按钮
                    var rightvalues = rightotherDevice.Communicator.Write<int>("D501", ext);//速度
                    var rightbutton = rightotherDevice.Communicator.Write<bool>("M101", true);//缩回按钮
                    Console.WriteLine($"伸缩杆缩回{ret}");
                }
                return new WebResponseContent { Status = true, Message = "成功" };
            }
            catch (Exception ex)
            {
                return new WebResponseContent { Status = false, Message = ex.Message };
            }
        }
        /// <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.DeviceName == "左汇川PLC");
                OtherDevice rightotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceName == "右汇川PLC");
                //找到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 };
            }
        }
    }
   
}