#region << 版 本 注 释 >> /*---------------------------------------------------------------- * 命名空间:WIDESEAWCS_TaskInfoService * 创建者:胡童庆 * 创建时间:2024/8/2 16:13:36 * 版本:V1.0.0 * 描述: * * ---------------------------------------------------------------- * 修改人: * 修改时间: * 版本:V1.0.1 * 修改说明: * *----------------------------------------------------------------*/ #endregion << 版 本 注 释 >> using AutoMapper; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using NetTaste; using Newtonsoft.Json; using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using SqlSugar; using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; using WIDESEA_Comm.Http; using WIDESEAWCS_Core; using WIDESEAWCS_Core.BaseServices; using WIDESEAWCS_Core.Enums; using WIDESEAWCS_DTO.Enum; using WIDESEAWCS_DTO.TaskInfo; using WIDESEAWCS_ITaskInfoRepository; using WIDESEAWCS_ITaskInfoService; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob.DTO; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_QuartzJob.Service; using System.Net; using WIDESEAWCS_ISystemServices; using System.Security.Claims; using WIDESEAWCS_Common.TaskEnum; namespace WIDESEAWCS_TaskInfoService { public class RgvOperationService : ServiceBase, IRgvOperationService { private readonly IAgvStationService _gvStationService; private readonly ITaskRepository _taskRepository; public RgvOperationService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService, ITaskRepository taskRepository) : base(BaseDal) { _gvStationService = agvStationService; _taskRepository = taskRepository; } public WebResponseContent WriteInitialization(SaveModel saveModel) { WebResponseContent webResponse = new WebResponseContent(); string DeviceName = saveModel.DelKeys[0].ToString(); //设备名称 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName); SpeStackerCrane Commonstacker = (SpeStackerCrane)device; //获取实例 DeviceProDTO? RGV_RGVtasktypet = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVtasktypet", "DeviceCommand"); //任务类型 //第一步写入任务 RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, (short)3); //复位报警 DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand"); //复位报警信息 RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1); //写入自动 DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand"); //任务id RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, (short)1); //写入清除任务 RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, (short)4); //反馈确认任务 DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_taskcomplete", "RGV_taskcomplete"); //任务id RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, (short)1); return webResponse.OK(); } public WebResponseContent WriteRGVmokuai(SaveModel saveModel) { WebResponseContent webResponse = new WebResponseContent(); string DeviceName = saveModel.DelKeys[0].ToString(); //工作类型 string DBType = saveModel.DelKeys[1].ToString(); //设备名称 short WriteRGVvalue = short.Parse(saveModel.DelKeys[2].ToString()); //写入值 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName); SpeStackerCrane Commonstacker = (SpeStackerCrane)device; switch (DBType) { case "1": // 工作模式(0手动、1自动) //获取实例 DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand"); //任务类型 //第一步写入任务 RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, WriteRGVvalue); break; case "2": //复位操作(0不复位、1复位) DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand"); //任务类型 //第一步写入任务 RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, WriteRGVvalue); break; case "3": //任务确认完成(0不确定,1确定) DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_taskcomplete", "RGV_taskcomplete"); //任务类型 //第一步写入任务 RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, WriteRGVvalue); break; case "4": //任务类型(4清除) DeviceProDTO? RGV_RGVtasktypet = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVtasktypet", "DeviceCommand"); //任务类型 //第一步写入任务 RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, WriteRGVvalue); break; } return webResponse.OK(); } /// /// 手动移动RGV /// /// /// public WebResponseContent ManualmovementRGV(SaveModel saveModel) { WebResponseContent webResponse = new WebResponseContent(); string DeviceName = saveModel.DelKeys[0].ToString(); //设备名称 short Nextaddres = short.Parse(saveModel.DelKeys[1].ToString()); IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName); SpeStackerCrane Commonstacker = (SpeStackerCrane)device; //获取实例 DeviceProDTO? RGV_RGVtasktypet = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVtasktypet", "DeviceCommand"); //任务类型 //第一步写入任务 RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, (short)3); //目标位置 DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVTasklocationt", "DeviceCommand"); //复位报警信息 RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)Nextaddres); //写入自动 DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Rgvtaskidt", "DeviceCommand"); //任务id //任务id RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, (short)30001); //任务id DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Lanjiantaskidt", "DeviceCommand"); //任务id RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, (short)30001); return webResponse.OK(); } /// /// 一键启动入库子母车 /// public WebResponseContent WriteInReset(SaveModel saveModel) { WebResponseContent webResponse = new WebResponseContent(); List rgvdata = _gvStationService.GetInStroller(); foreach (AGVStation rgvstation in rgvdata) { string DeviceName = rgvstation.ChildPosiDeviceCode; //设备名称 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName); if (device == null) continue; SpeStackerCrane Commonstacker = (SpeStackerCrane)device; //获取需要复位的设备 DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand"); //复位报警信息 RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1); } return webResponse.OK(); } /// /// 写入复位(出库端) /// public WebResponseContent WriteOutReset(SaveModel saveModel) { WebResponseContent webResponse = new WebResponseContent(); List rgvdata = _gvStationService.GetOutStroller(); foreach (AGVStation rgvstation in rgvdata) { string DeviceName = rgvstation.ChildPosiDeviceCode; //设备名称 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName); if (device == null) continue; SpeStackerCrane Commonstacker = (SpeStackerCrane)device; //获取需要复位的设备 DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand"); //复位报警信息 RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0); } return webResponse.OK(); } /// /// 一键暂停 /// /// /// public WebResponseContent WriteOutbuttonpause(SaveModel saveModel) { WebResponseContent webResponse = new WebResponseContent(); List rgvdata = _gvStationService.GetOutStroller(); foreach (AGVStation rgvstation in rgvdata) { string DeviceName = rgvstation.ChildPosiDeviceCode; //设备名称 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName); if (device == null) continue; SpeStackerCrane Commonstacker = (SpeStackerCrane)device; //获取需要复位的设备 DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand"); RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0); } return webResponse.OK(); } public WebResponseContent InWriteOutbuttonpause(SaveModel saveModel) { WebResponseContent webResponse = new WebResponseContent(); List rgvdata = _gvStationService.InGetOutStroller(); foreach (AGVStation rgvstation in rgvdata) { string DeviceName = rgvstation.ChildPosiDeviceCode; //设备名称 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName); if (device == null) continue; SpeStackerCrane Commonstacker = (SpeStackerCrane)device; //获取需要复位的设备 DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand"); RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0); } return webResponse.OK(); } /// /// 一键启动 /// /// /// public WebResponseContent WriteOuttouchstart(SaveModel saveModel) { WebResponseContent webResponse = new WebResponseContent(); List rgvdata = _gvStationService.GetOutStroller(); foreach (AGVStation rgvstation in rgvdata) { string DeviceName = rgvstation.ChildPosiDeviceCode; //设备名称 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName); if (device == null) continue; SpeStackerCrane Commonstacker = (SpeStackerCrane)device; //获取需要复位的设备 DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand"); RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1); } return webResponse.OK(); } /// /// 查询RGV设备 /// /// /// /// /// public static DeviceProDTO? GetRGVDeviceProDTO(SpeStackerCrane Commonstacker, string SCAddress, string DeviceProParamName, string DeviceProParamType) { return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == DeviceProParamName && x.DeviceProParamType == DeviceProParamType); } /// /// 读取设备信息 /// /// /// /// public static int GetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock) { return Commonstacker.Communicator.Read(DeviceProDataBlock); } /// /// 写入设备信息 /// /// /// /// public static bool RgvSetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock, short rgvvalues) { return Commonstacker.Communicator.Write(DeviceProDataBlock, rgvvalues); } /// /// 正常入库 /// public WebResponseContent WriteInNormal(SaveModel saveModel) { WebResponseContent content = new WebResponseContent(); Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.TaskState == (int)TaskInStatusEnum.InAbnormalFinish); if (dt_Task == null) { return WebResponseContent.Instance.Error("没有异常入库任务"); } dt_Task.TaskState = (int)TaskInStatusEnum.RGV_InPickupFinish; dt_Task.RGVTaskType = (int)RGVTaskTypeEnum.Placing; dt_Task.NextAddress = "1021"; _taskRepository.UpdateData(dt_Task); return content; } /// /// 入库异常排出 /// public WebResponseContent WriteInAbnormal(SaveModel saveModel) { WebResponseContent content = new WebResponseContent(); Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.TaskState == (int)TaskInStatusEnum.InAbnormalFinish); if (dt_Task == null) { return WebResponseContent.Instance.Error("没有异常入库任务"); } dt_Task.TaskState = (int)TaskInStatusEnum.InexceptionalSelection; dt_Task.RGVTaskType = (int)RGVTaskTypeEnum.Placing; _taskRepository.UpdateData(dt_Task); return content; } public static List OutStationareaList = new List() { "RGV111", "RGV116", "RGV110", "RGV112", "RGV114", "RGV115", "RGV118" }; public static List InStationareaList = new List() { "RGV111", "RGV116", "RGV110", "RGV112", "RGV114", "RGV115", "RGV118" }; /// /// 查看报警 /// public bool AQMReadAlarminform(int tasktype) { var deviceList = tasktype == 1 ? InStationareaList : OutStationareaList; foreach (string deviceName in deviceList) { IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceName); if (device == null) return false; SpeStackerCrane stacker = (SpeStackerCrane)device; DeviceProDTO? faultInfo = GetRGVDeviceProDTO(stacker, deviceName, "RGV_Faultcode", "ReadDeviceCommand"); int alarmCode = GetLine(stacker, faultInfo.DeviceProAddress); if (alarmCode != 0) { return true; } } return false; } /// /// 查看报警 /// public WebResponseContent ReadAlarminformation(SaveModel saveModel) { WebResponseContent webResponse = new WebResponseContent(); string DeviceName = saveModel.DelKeys[0].ToString(); //设备名称 IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName); if (device == null) return webResponse.Error(); SpeStackerCrane Commonstacker = (SpeStackerCrane)device; DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Faultcode", "ReadDeviceCommand"); int baoj = GetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress); string alarmMessage = ""; if (DeviceName == "RGV118") { alarmMessage = GetAlarmMessage(baoj); } else if (DeviceName == "RGV111" || DeviceName == "RGV116") { alarmMessage = GetAlarmMessage2(baoj); } else if (DeviceName == "RGV110" || DeviceName == "RGV112" || DeviceName == "RGV114" || DeviceName == "RGV115") { alarmMessage = GetAlarmMessage3(baoj); } return webResponse.OK(data: alarmMessage); } // 报警代码映射方法 private string GetAlarmMessage(int alarmCode) { var alarmMessages = new Dictionary { {0, "无报警"}, {1, "RGV小车急停被按下"}, {2, "正转雷达报警"}, {3, "反转雷达报警"}, {4, "前进限位报警"}, {5, "后退限位报警"}, {6, ""}, {7, "PLC摸块故障"}, {8, "PLC扩展模块故障"}, {9, "称重模块故障"}, {10, "扫码定位故障"}, {11, "RGV长时间空转故障"}, {12, "目的地不等于实际位置故障"}, {13, "与总控通讯故障"}, {14, "前雷达屏蔽警告"}, {15, "后雷达屏蔽警告"}, {16, "行走变频器故障"}, {17, "伸缩叉变频器故障"}, {18, "液压单元过载保护故障"}, {19, "液压上升超时报警"}, {20, "液压下降超时报警"}, {21, "伸缩叉伸出超时报警"}, {22, "伸缩叉缩回超时报警"}, {23, "外形检测报警"}, {24, "称重超重报警"}, {25, "货叉伸出极限限位报警"}, {26, "货叉缩回极限限位报警"}, {27, "取货时自身有货物报警"}, {28, "放货时自身无货物报警"}, {29, "货叉未回到初始位报警"}, {30, "触发仅移动命令时货叉不在初始位报警"}, {31, "货叉到达初始位但中位传感器未检测到报警"} }; return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码"; } private string GetAlarmMessage2(int alarmCode) { var alarmMessages = new Dictionary { {0, "无报警"}, {1, "RGV小车急停被按下"}, {2, "前进限位报警"}, {3, "后退限位报警"}, {4, "PLC摸块故障"}, {5, "PLC扩展模块故障"}, {6, "扫码定位故障"}, {7, "RGV长时间空转故障"}, {8, "目的地不等于实际位置故障"}, {9, "与总控通讯故障"}, {10, "行走变频器故障"}, {11, "液压单元过载保护故障"}, {12, "液压上升超时报警"}, {13, "液压下降超时报警"}, {14, "取货时自身有货物报警"}, {15, "放货时自身无货物报警"}, {16, "取货检测不到货物报警"} }; return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码"; } private string GetAlarmMessage3(int alarmCode) { var alarmMessages = new Dictionary { {0, "无报警"}, {1, "RGV小车急停被按下"}, {2, "前进限位报警"}, {3, "后退限位报警"}, {4, "PLC摸块故障"}, {5, "PLC扩展模块故障"}, {6, "RGV长时间空转故障"}, {7, "目的地不等于实际位置故障"}, {8, "与总控通讯故障"}, {9, "行走变频器故障"}, {10, "取货时自身有货物报警"}, {11, "放货时自身无货物报警"}, {12, "停止时位置过冲报警"} }; return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码"; } } }