| | |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_ITelescopicService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | |
| | | /// 自动控制伸缩杆的伸出和缩回速度 |
| | | /// </summary> |
| | | /// <param name="ExtendedState">伸/出状态</param> |
| | | /// <param name="account">用户账号</param> |
| | | /// <returns></returns> |
| | | public WebResponseContent automation(string ExtendedState, string account) |
| | | public WebResponseContent automation(string ExtendedState) |
| | | { |
| | | try |
| | | { |
| | | var loginer = _user.QueryData(x => x.UserName == account).FirstOrDefault(); |
| | | if (loginer == null) |
| | | return new WebResponseContent { Status = false, Message = "登录用户不存在" }; |
| | | |
| | | // 设备编号规则是按部门编号依次为 SSG001~SSG010 |
| | | string liftDeviceCode = $"SSG{(loginer.Dept_Id * 2 - 1):D3}"; |
| | | string rightDeviceCode = $"SSG{(loginer.Dept_Id * 2):D3}"; |
| | | |
| | | OtherDevice liftDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == liftDeviceCode); |
| | | OtherDevice rightDevice = (OtherDevice)Storage.Devices.Find(x => x.DeviceCode == rightDeviceCode); |
| | | |
| | | if (liftDevice == null || rightDevice == null) |
| | | //根据int.TryParse(AppSettings.Get("DepartmentID")读取到当前是轨道几,所有人都只能操作当前 |
| | | if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid)) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = $"设备 {liftDeviceCode} 或 {rightDeviceCode} 未找到" }; |
| | | } |
| | | |
| | | if (liftDevice.Communicator == null || rightDevice.Communicator == null) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "设备通讯未初始化" }; |
| | | } |
| | | return new WebResponseContent { Status = false, Message = "配置项 DepartmentID 无法转换为整数" }; |
| | | }; |
| | | var devices = GetDevicesByDeptId(deid); |
| | | |
| | | //找到Dt_Parameters中的最新一条数据 |
| | | var para = BaseDal.QueryData().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 = "未找到参数配置" }; |
| | | |
| | |
| | | |
| | | if (ExtendedState == "伸出") |
| | | { |
| | | liftDevice.Communicator.Write<int>("D500", ext); |
| | | liftDevice.Communicator.Write<bool>("M100", true); |
| | | rightDevice.Communicator.Write<int>("D500", ext); |
| | | rightDevice.Communicator.Write<bool>("M100", true); |
| | | Console.WriteLine($"伸缩杆伸出 {ext}"); |
| | | 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}"); |
| | | } |
| | | else if (ExtendedState == "缩回") |
| | | { |
| | | liftDevice.Communicator.Write<int>("D501", ret); |
| | | liftDevice.Communicator.Write<bool>("M101", true); |
| | | rightDevice.Communicator.Write<int>("D501", ret); |
| | | rightDevice.Communicator.Write<bool>("M101", true); |
| | | Console.WriteLine($"伸缩杆缩回 {ret}"); |
| | | 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}"); |
| | | } |
| | | else |
| | | { |
| | |
| | | |
| | | |
| | | |
| | | public WebResponseContent ManualOperation(string position, string ExtendedState,string account) |
| | | /// <summary> |
| | | /// 手动控制,伸缩杆的缩回和伸出速度 |
| | | /// </summary> |
| | | /// <param name="position">伸缩杆的位置(左右)</param> |
| | | /// <param name="ExtendedState">伸/缩状态</param> |
| | | /// <returns></returns> |
| | | /// |
| | | public WebResponseContent ManualOperation(string position, string ExtendedState) |
| | | { |
| | | try |
| | | { |
| | | var loginer = _user.QueryData(x => x.UserName == account).FirstOrDefault(); |
| | | if (loginer == null) |
| | | return new WebResponseContent { Status = false, Message = "用户不存在" }; |
| | | if (!int.TryParse(AppSettings.Get("DepartmentID"), out int deid)) |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "配置项 DepartmentID 无法转换为整数" }; |
| | | } |
| | | var devices = GetDevicesByDeptId(deid); |
| | | |
| | | var devices = GetDevicesByDeptId((int)loginer.Dept_Id); |
| | | if (devices == null) |
| | | return new WebResponseContent { Status = false, Message = "设备未找到" }; |
| | | |
| | | var para = BaseDal.QueryData().OrderByDescending(x => x.CreateDate).FirstOrDefault(); |
| | | if (para == null) |
| | | return new WebResponseContent { Status = false, Message = "参数未配置" }; |
| | | |
| | | int ext = (int)para.ExtendSpeed; |
| | | int ret = (int)para.RetractionSpeed; |
| | | |
| | | //俩个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;//手动缩回速度 |
| | | if (position == "左" && ExtendedState == "伸出") |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D500", ext); |
| | | devices.Value.left.Communicator.Write<bool>("M100", true); |
| | | devices.Value.left.Communicator.Write<int>("D500", ext);//伸出速度 |
| | | devices.Value.left.Communicator.Write<bool>("M100", true);//伸出按钮 |
| | | Console.WriteLine($"{position}伸缩杆手动伸出{ext}"); |
| | | } |
| | | else if (position == "左" && ExtendedState == "缩回") |
| | | { |
| | | devices.Value.left.Communicator.Write<int>("D501", ret); |
| | | devices.Value.left.Communicator.Write<int>("D501", ret);//缩回速度 |
| | | devices.Value.left.Communicator.Write<bool>("M101", true); |
| | | Console.WriteLine($"{position}伸缩杆手动缩回{ret}"); |
| | | } |
| | | else if (position == "右" && ExtendedState == "伸出") |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D500", ext); |
| | | devices.Value.right.Communicator.Write<bool>("M100", true); |
| | | Console.WriteLine($"{position}伸缩杆手动伸出{ext}"); |
| | | } |
| | | else if (position == "右" && ExtendedState == "缩回") |
| | | { |
| | | devices.Value.right.Communicator.Write<int>("D501", ret); |
| | | devices.Value.right.Communicator.Write<bool>("M101", true); |
| | | Console.WriteLine($"{position}伸缩杆手动缩回{ret}"); |
| | | } |
| | | |
| | | else |
| | | { |
| | | return new WebResponseContent { Status = false, Message = "状态参数错误" }; |
| | | } |
| | | |
| | | return new WebResponseContent { Status = true, Message = "成功" }; |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |