| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using AutoMapper; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using SqlSugar; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO.Telescopic; |
| | | using WIDESEAWCS_ITelescopicService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using static WIDESEAWCS_Common.Face.TH_Faces; |
| | | |
| | | |
| | | namespace WIDESEAWCS_TelescopicService |
| | |
| | | /// <returns></returns> |
| | | public WebResponseContent automation(string ExtendedState) |
| | | { |
| | | |
| | | try |
| | | { |
| | | |
| | |
| | | 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; |
| | | int ret = (int)para.RetractionSpeed; |
| | | int ext = (int)para.ExtendSpeed;//左PLC自动伸出缩回速度 |
| | | int ret = (int)para.RetractionSpeed;//右PLC自动伸出缩回速度 |
| | | int liftPosition = (int)para.LeftPosition;//左伸出位置 |
| | | int rigtpostition = (int)para.RightPosition;//右伸出位置 |
| | | string message = ""; |
| | | |
| | | try |
| | | { |
| | | if (devices.Value.left.Communicator.Read<bool>("M117")) |
| | | { |
| | | |
| | | return new WebResponseContent { Status = true, Message = "现在正在进行中,等待操作完成" }; |
| | | } |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | try |
| | | { |
| | | if (devices.Value.right.Communicator.Read<bool>("M117")) |
| | | { |
| | | return new WebResponseContent { Status = true, Message = "现在正在进行中,等待操作完成" }; |
| | | } |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | |
| | | if (ExtendedState == "伸出") |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D500", ext);//伸出速度 |
| | | devices.Value.left.Communicator.Write<bool>("M100", true);//伸出按钮 |
| | | devices.Value.right.Communicator.Write<int>("D500", ext);//伸出速度 |
| | | devices.Value.right.Communicator.Write<bool>("M100", true);//伸出按钮 |
| | | Console.WriteLine($"自动伸缩杆伸出 {ext}"); |
| | | |
| | | try |
| | | { |
| | | if (devices.Value.left.Communicator.Read<float>("D80")>= liftPosition-5)//到达最大位置) |
| | | { |
| | | 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>("M102", true);//伸出按钮 |
| | | |
| | | } |
| | | } |
| | | catch { } |
| | | |
| | | try |
| | | { |
| | | if (devices.Value.right.Communicator.Read<float>("D80") >= rigtpostition-5) |
| | | { |
| | | message += "右伸缩杆到达目标位置;"; |
| | | } |
| | | 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 == "缩回") |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D501", ext);//伸出速度 |
| | | devices.Value.left.Communicator.Write<bool>("M101", true);//伸出按钮 |
| | | devices.Value.right.Communicator.Write<int>("D501", ext);//伸出速度 |
| | | devices.Value.right.Communicator.Write<bool>("M101", true);//伸出按钮 |
| | | Console.WriteLine($"自动伸缩杆缩回 {ret}"); |
| | | |
| | | try |
| | | { |
| | | 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 { } |
| | | |
| | | |
| | | try |
| | | { |
| | | 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 |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "未知的操作命令" }; |
| | | } |
| | | |
| | | return new WebResponseContent { Status = true, Message = "成功" }; |
| | | return new WebResponseContent |
| | | { |
| | | Status = true, |
| | | Message = string.IsNullOrEmpty(message) ? "执行成功" : $"{message}", |
| | | Data = new { ExtendSpeed = ext, RetractionSpeed = ret,liftweiz= liftPosition,rightweiz= rigtpostition } |
| | | }; |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | //俩个plc左右各一个 |
| | | //OtherDevice liftotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG001"); |
| | | //OtherDevice rightotherDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == "SSG002"); |
| | | |
| | | //找到Dt_Parameters中的最新一条数据根据当前的deid |
| | | var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault(); |
| | | int ext = (int)para.ManualExtend;//手动伸出速度 |
| | | int ret = (int)para.ManualRetraction;//手动缩回速度 |
| | | 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 |
| | | { |
| | | if (devices.Value.left.Communicator.Read<bool>("M117")) //默认是flase |
| | | { |
| | | |
| | | return new WebResponseContent { Status = true, Message = "现在正在进行中,等待操作完成" }; |
| | | } |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | try |
| | | { |
| | | if (devices.Value.right.Communicator.Read<bool>("M117")) |
| | | { |
| | | return new WebResponseContent { Status = true, Message = "现在正在进行中,等待操作完成" }; |
| | | } |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | } |
| | | if (position == "左" && ExtendedState == "伸出") |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D500", ext);//伸出速度 |
| | | devices.Value.left.Communicator.Write<bool>("M100", true);//伸出按钮 |
| | | Console.WriteLine($"{position}伸缩杆手动伸出{ext}"); |
| | | 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); // 释放按钮 |
| | | |
| | | |
| | | Console.WriteLine($"{position}伸缩杆手动伸出{ext}"); |
| | | } |
| | | |
| | | } |
| | | else if (position == "左" && ExtendedState == "缩回") |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D501", ret);//缩回速度 |
| | | devices.Value.left.Communicator.Write<bool>("M101", true); |
| | | Console.WriteLine($"{position}伸缩杆手动缩回{ret}"); |
| | | if (devices.Value.left.Communicator.Read<bool>("M115"))//缩回的时候判断) |
| | | { |
| | | 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>("M101", true); |
| | | Thread.Sleep(100); // 等待100ms(模拟按钮按下) |
| | | devices.Value.left.Communicator.Write<bool>("M101", false); // 释放按钮 |
| | | Console.WriteLine($"{position}伸缩杆手动缩回{ext}"); |
| | | } |
| | | |
| | | } |
| | | else if (position == "右" && ExtendedState == "伸出") |
| | | |
| | | if (position == "右" && ExtendedState == "伸出") |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D500", ext); |
| | | devices.Value.right.Communicator.Write<bool>("M100", true); |
| | | Console.WriteLine($"{position}伸缩杆手动伸出{ext}"); |
| | | 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); // 释放按钮 |
| | | Console.WriteLine($"{position}伸缩杆手动伸出{ret}"); |
| | | } |
| | | |
| | | |
| | | } |
| | | else if (position == "右" && ExtendedState == "缩回") |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D501", ret); |
| | | devices.Value.right.Communicator.Write<bool>("M101", true); |
| | | Console.WriteLine($"{position}伸缩杆手动缩回{ret}"); |
| | | 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 = "成功" }; |
| | | |
| | | |
| | | |
| | | return new WebResponseContent |
| | | { |
| | | Status = true, |
| | | Message = string.IsNullOrEmpty(message) ? "执行成功" : $"{message}", |
| | | Data = new |
| | | { |
| | | ManualExtend = ext, |
| | | ManualRetraction = ret, |
| | | message |
| | | } |
| | | }; |
| | | } |
| | | |
| | | |
| | | catch (Exception ex) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = ex.Message }; |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 根据用户添加速度 |
| | | /// </summary> |
| | | /// <param name="entity"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent AddSpeed(SpeedDTO entity) |
| | | { |
| | | try |
| | | { |
| | | // 获取当前登录用户 |
| | | var user = _user.QueryData(x => x.UserName == entity.account).FirstOrDefault(); |
| | | // 判断:如果不是管理员 && Dept_Id 为空,则提示错误 |
| | | if (user.UserName != "admin" && user.Dept_Id == null) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "你的账号没有设置轨道站号,无法添加,请联系管理员" }; |
| | | } |
| | | |
| | | var dept = user.Dept_Id; |
| | | |
| | | // 获取配置文件中的 DepartmentID(管理员专用) |
| | | if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid)) |
| | | { |
| | | return new WebResponseContent |
| | | { |
| | | Status = false, |
| | | Message = "配置项 DepartmentID 无法转换为整数" |
| | | }; |
| | | } |
| | | |
| | | |
| | | // 判断是否为管理员账号 |
| | | bool isAdmin = user?.UserName?.Equals("admin") == true; //如果当前用户不为空,且用户名是 "admin",就认为这个用户是管理员 |
| | | |
| | | // 根据是否是管理员决定使用哪个 Deptid |
| | | var parmet = new Dt_Parameters |
| | | { |
| | | ExtendSpeed = entity.ExtendSpeed, |
| | | RetractionSpeed = entity.RetractionSpeed, |
| | | ManualExtend = entity.ManualExtend, |
| | | ManualRetraction = entity.ManualRetraction, |
| | | LeftPosition = entity.LeftPosition, |
| | | RightPosition = entity.RightPosition, |
| | | Deptid = isAdmin ? deid : dept.GetValueOrDefault()//如果当前用户是管理员,就用配置文件中的 DepartmentID,否则用传入的 entity 参数中的 Deptid |
| | | }; |
| | | // 添加数据 |
| | | AddData(parmet); |
| | | |
| | | |
| | | return new WebResponseContent |
| | | { |
| | | Status = true, |
| | | Message = "添加成功", |
| | | Data = parmet |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | return new WebResponseContent { Status = false, Message = ex.Message }; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | ///当自动伸出需要暂停时,暂停按钮 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent PauseButton() |
| | | { |
| | | try |
| | | { |
| | | //根据int.TryParse(AppSettings.Get("DepartmentID")读取到当前是轨道几,所有人都只能操作当前 |
| | | if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid)) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "配置项 DepartmentID 无法转换为整数" }; |
| | | }; |
| | | var devices = GetDevicesByDeptId(deid); |
| | | try |
| | | { |
| | | devices.Value.left.Communicator.Write<bool>("M104", true); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | |
| | | } |
| | | try |
| | | { |
| | | devices.Value.right.Communicator.Write<bool>("M104", true); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | return new WebResponseContent { Status =true,Message="暂停成功",Data = devices}; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | return new WebResponseContent { Status = false, Message = ex.Message }; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取当前程序最新的伸缩杆速度 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent BackfillSpeed() |
| | | { |
| | | try |
| | | { |
| | | if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid)) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "配置项 DepartmentID 无法转换为整数" }; |
| | | |
| | | } |
| | | var para = BaseDal.QueryData().Where(x => x.Deptid == deid).OrderByDescending(x => x.CreateDate).FirstOrDefault(); |
| | | if (para == null) |
| | | { |
| | | return new WebResponseContent { Message = "你还没有配置速度" }; |
| | | } |
| | | return new WebResponseContent { Status = true, Data = para }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | return new WebResponseContent { Status = false, Message = ex.Message }; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取当前伸缩杆的位置(自动) |
| | | /// </summary> |
| | | /// <param name="ExtendedState"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent CurrentLocation() |
| | | { |
| | | try |
| | | { |
| | | if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid)) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "配置项 DepartmentID 无法转换为整数" }; |
| | | |
| | | } |
| | | var devices = GetDevicesByDeptId(deid); |
| | | |
| | | |
| | | 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 }; |
| | | } |
| | | } |
| | | |
| | |
| | | return (left, right); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | } |