From 8e49faa42ff419efa0641478702ce7d5f8455bd9 Mon Sep 17 00:00:00 2001 From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com> Date: 星期三, 30 七月 2025 20:47:56 +0800 Subject: [PATCH] 1 --- 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DeviceInfoService.cs | 1113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 1,112 insertions(+), 1 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DeviceInfoService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DeviceInfoService.cs" index f6551e1..b01298a 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DeviceInfoService.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DeviceInfoService.cs" @@ -16,31 +16,42 @@ #endregion << 鐗� 鏈� 娉� 閲� >> using AutoMapper; +using HslCommunication; using Newtonsoft.Json; +using SixLabors.ImageSharp.ColorSpaces; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using WIDESEAWCS_BasicInfoRepository; using WIDESEAWCS_Core; using WIDESEAWCS_Core.BaseRepository; using WIDESEAWCS_Core.BaseServices; using WIDESEAWCS_Core.Helper; +using WIDESEAWCS_DTO.StackerHandTask; +using WIDESEAWCS_IBasicInfoRepository; +using WIDESEAWCS_Model.BasicInfo; +using WIDESEAWCS_QuartzJob.DeviceBase; using WIDESEAWCS_QuartzJob.DeviceEnum; using WIDESEAWCS_QuartzJob.DTO; using WIDESEAWCS_QuartzJob.Models; using WIDESEAWCS_QuartzJob.Repository; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; +using static WIDESEAWCS_QuartzJob.Service.DeviceInfoService; namespace WIDESEAWCS_QuartzJob.Service { public class DeviceInfoService : ServiceBase<Dt_DeviceInfo, IDeviceInfoRepository>, IDeviceInfoService { private readonly IUnitOfWorkManage _unitOfWorkManage; + private readonly IDt_StationManagerRepository _stationManagerRepository; private readonly IMapper _mapper; - public DeviceInfoService(IDeviceInfoRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IMapper mapper) : base(BaseDal) + public DeviceInfoService(IDeviceInfoRepository BaseDal, IUnitOfWorkManage unitOfWorkManage, IMapper mapper, IDt_StationManagerRepository stationManagerRepository) : base(BaseDal) { _unitOfWorkManage = unitOfWorkManage; _mapper = mapper; + _stationManagerRepository = stationManagerRepository; } public override WebResponseContent AddData(SaveModel saveModel) @@ -57,5 +68,1105 @@ List<Dt_DeviceInfo> deviceInfos = await Db.Queryable<Dt_DeviceInfo>().Where(x => x.DeviceStatus == ((int)DeviceStatusEnum.Enable).ToString()).Includes(x => x.ProtocolList).ToListAsync(); return _mapper.Map<List<DeviceInfoDTO>>(deviceInfos); } + + #region 鍫嗗灈鏈烘墜鍔ㄥ懡浠� + + public WebResponseContent StackerHandTask(HandTask stackerhand) + { + WebResponseContent content = new WebResponseContent(); + try + { + StackerCraneTaskCommand stackerCraneTaskCommand = new StackerCraneTaskCommand(); + + if (stackerhand == null || stackerhand.TaskType == "") + { + return content.Error("璇疯緭鍏ヤ换鍔″懡浠�"); + } + stackerCraneTaskCommand.WorkType = (byte)Convert.ToSByte(stackerhand.TaskType); + //鍏ュ簱 + if (stackerhand.TaskType == "17") + { + string[] sourceCodes = stackerhand.SourceAddress.Split("-"); + if (sourceCodes.Length == 3) + { + stackerCraneTaskCommand.StartRow = (byte)Convert.ToSByte(sourceCodes[0]); + stackerCraneTaskCommand.StartColumn = (byte)Convert.ToSByte(sourceCodes[1]); + stackerCraneTaskCommand.StartLayer = (byte)Convert.ToSByte(sourceCodes[2]); + } + else + { + return content.Error($"璧风偣閿欒锛氥�恵stackerhand.SourceAddress}銆�"); + } + + string[] targetCodes = stackerhand.TargetAddress.Split("-"); + if (targetCodes.Length == 3) + { + stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(targetCodes[0]); + stackerCraneTaskCommand.EndColumn = (byte)Convert.ToSByte(targetCodes[1]); + stackerCraneTaskCommand.EndLayer = (byte)Convert.ToSByte(targetCodes[2]); + } + else + { + return content.Error($"缁堢偣閿欒锛氥�恵stackerhand.TargetAddress}銆�"); + } + } + //鍑哄簱 + else if (stackerhand.TaskType == "18") + { + string[] sourceCodes = stackerhand.SourceAddress.Split("-"); + if (sourceCodes.Length == 3) + { + stackerCraneTaskCommand.StartRow = (byte)Convert.ToSByte(sourceCodes[0]); + stackerCraneTaskCommand.StartColumn = (byte)Convert.ToSByte(sourceCodes[1]); + stackerCraneTaskCommand.StartLayer = (byte)Convert.ToSByte(sourceCodes[2]); + } + else + { + return content.Error($"璧风偣閿欒锛氥�恵stackerhand.SourceAddress}銆�"); + } + string[] targetCodes = stackerhand.TargetAddress.Split("-"); + if (targetCodes.Length == 3) + { + stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(targetCodes[0]); + stackerCraneTaskCommand.EndColumn = (byte)Convert.ToSByte(targetCodes[1]); + stackerCraneTaskCommand.EndLayer = (byte)Convert.ToSByte(targetCodes[2]); + } + else + { + return content.Error($"缁堢偣閿欒锛氥�恵stackerhand.TargetAddress}銆�"); + } + } + //绉诲簱 + else if (stackerhand.TaskType == "20") + { + string[] sourceCodes = stackerhand.SourceAddress.Split("-"); + if (sourceCodes.Length == 3) + { + stackerCraneTaskCommand.StartRow = (byte)Convert.ToSByte(sourceCodes[0]); + stackerCraneTaskCommand.StartColumn = (byte)Convert.ToSByte(sourceCodes[1]); + stackerCraneTaskCommand.StartLayer = (byte)Convert.ToSByte(sourceCodes[2]); + } + else + { + return content.Error($"璧风偣閿欒锛氥�恵stackerhand.SourceAddress}銆�"); + } + + string[] targetCodes = stackerhand.TargetAddress.Split("-"); + if (targetCodes.Length == 3) + { + stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(targetCodes[0]); + stackerCraneTaskCommand.EndColumn = (byte)Convert.ToSByte(targetCodes[1]); + stackerCraneTaskCommand.EndLayer = (byte)Convert.ToSByte(targetCodes[2]); + } + else + { + return content.Error($"缁堢偣閿欒锛氥�恵stackerhand.TargetAddress}銆�"); + } + } + //鍙栬揣 + else if (stackerhand.TaskType == "24") + { + string[] sourceCodes = stackerhand.SourceAddress.Split("-"); + if (sourceCodes.Length == 3) + { + stackerCraneTaskCommand.StartRow = (byte)Convert.ToSByte(sourceCodes[0]); + stackerCraneTaskCommand.StartColumn = (byte)Convert.ToSByte(sourceCodes[1]); + stackerCraneTaskCommand.StartLayer = (byte)Convert.ToSByte(sourceCodes[2]); + + stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(0); + stackerCraneTaskCommand.EndColumn = (byte)Convert.ToSByte(0); + stackerCraneTaskCommand.EndLayer = (byte)Convert.ToSByte(0); + } + else + { + return content.Error($"璧风偣閿欒锛氥�恵stackerhand.SourceAddress}銆�"); + } + } + //鏀捐揣 + else if (stackerhand.TaskType == "48") + { + string[] targetCodes = stackerhand.TargetAddress.Split("-"); + if (targetCodes.Length == 3) + { + stackerCraneTaskCommand.StartRow = (byte)Convert.ToSByte(0); + stackerCraneTaskCommand.StartColumn = (byte)Convert.ToSByte(0); + stackerCraneTaskCommand.StartLayer = (byte)Convert.ToSByte(0); + + stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(targetCodes[0]); + stackerCraneTaskCommand.EndColumn = (byte)Convert.ToSByte(targetCodes[1]); + stackerCraneTaskCommand.EndLayer = (byte)Convert.ToSByte(targetCodes[2]); + } + else + { + return content.Error($"缁堢偣閿欒锛氥�恵stackerhand.SourceAddress}銆�"); + } + } + else + { + return content.Error("鏈壘鍒颁换鍔″懡浠�"); + } + StackerSendCommand(stackerCraneTaskCommand, stackerhand.DeviceCode); + return content; + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + + public WebResponseContent StackerReset(string DeviceCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode); + + if (device != null) + { + CommonStackerCrane commonStackerCrane = (CommonStackerCrane)device; + + commonStackerCrane.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(2)); + return content.OK(); + } + else + { + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + + public WebResponseContent StackerEmergencyStop(string DeviceCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode); + + if (device != null) + { + CommonStackerCrane commonStackerCrane = (CommonStackerCrane)device; + + commonStackerCrane.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(2)); + return content.OK(); + } + else + { + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + + public void StackerSendCommand(StackerCraneTaskCommand? command,string DeviceCode) + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode); + + if (device != null) + { + CommonStackerCrane commonStackerCrane = (CommonStackerCrane)device; + if (commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Automatic) && !commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Fault) && !commonStackerCrane.GetValue<StackerCraneDBName, bool>(StackerCraneDBName.Running)) + { + commonStackerCrane.SetValue(StackerCraneDBName.TaskNum, (short)Convert.ToInt16(1)); + Thread.Sleep(100); + + commonStackerCrane.SetValue(StackerCraneDBName.StartRow, command.StartRow); + Thread.Sleep(100); + + commonStackerCrane.SetValue(StackerCraneDBName.StartColumn, command.StartColumn); + Thread.Sleep(100); + + commonStackerCrane.SetValue(StackerCraneDBName.StartColumn, command.StartLayer); + Thread.Sleep(100); + + commonStackerCrane.SetValue(StackerCraneDBName.EndRow, command.EndRow); + Thread.Sleep(100); + + commonStackerCrane.SetValue(StackerCraneDBName.EndColumn, command.EndColumn); + Thread.Sleep(100); + commonStackerCrane.SetValue(StackerCraneDBName.EndLayer, command.EndLayer); + Thread.Sleep(100); + commonStackerCrane.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(command.WorkType)); + } + else + { + throw new Exception("璇峰湪鍫嗗灈鏈鸿仈鏈烘ā寮忋�佸緟鏈虹姸鎬併�佹棤鏁呴殰鐨勬儏鍐典笅涓嬪彂浠诲姟"); + } + } + else + { + throw new Exception("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + } + + + public class StackerCraneTaskCommand + { + #region <Public Menber> + + /// <summary> + /// 璧峰琛� + /// </summary> + public byte StartRow { get; set; } + + /// <summary> + /// 璧峰鍒� + /// </summary> + public byte StartColumn { get; set; } + + /// <summary> + /// 璧峰灞� + /// </summary> + public byte StartLayer { get; set; } + + /// <summary> + /// 鐩爣琛� + /// </summary> + public byte EndRow { get; set; } + + /// <summary> + /// 鐩爣鍒� + /// </summary> + public byte EndColumn { get; set; } + + /// <summary> + /// 鐩爣灞� + /// </summary> + public byte EndLayer { get; set; } + + + /// <summary> + /// 浣滀笟绫诲瀷 + /// </summary> + public byte WorkType { get; set; } + + + /// <summary> + /// 棰勭暀瀛楄妭 + /// </summary> + public byte Spare { get; set; } + + /// <summary> + /// 浠诲姟鍙� + /// </summary> + public short TaskNum { get; set; } + + #endregion <Public Menber> + } + public enum StackerCraneDBName + { + /// <summary> + /// 浠诲姟鍙� + /// </summary> + TaskNum, + + /// <summary> + /// 浣滀笟绫诲瀷 + /// </summary> + WorkType, + + /// <summary> + /// 璧峰琛� + /// </summary> + StartRow, + + /// <summary> + /// 璧峰鍒� + /// </summary> + StartColumn, + + /// <summary> + /// 璧峰灞� + /// </summary> + StartLayer, + + /// <summary> + /// 鐩爣琛� + /// </summary> + EndRow, + + /// <summary> + /// 鐩爣鍒� + /// </summary> + EndColumn, + + /// <summary> + /// 鐩爣灞� + /// </summary> + EndLayer, + + /// <summary> + /// 鎵樼洏鍙� + /// </summary> + Barcode, + + /// <summary> + /// 璧风偣 + /// </summary> + StartAddress, + + /// <summary> + /// 缁堢偣 + /// </summary> + EndAddress, + + /// <summary> + /// 浠诲姟瀹屾垚 + /// </summary> + TaskCompleted, + + /// <summary> + /// 浠诲姟鍙戦�� + /// </summary> + SendTask, + + /// <summary> + /// 鑷姩鐘舵�� + /// </summary> + Automatic, + + /// <summary> + /// 浣滀笟瀹屾垚 + /// </summary> + WorkCompleted, + + /// <summary> + /// 杩愯涓� + /// </summary> + Running, + + /// <summary> + /// 鏁呴殰 + /// </summary> + Fault, + + /// <summary> + /// 浣滀笟绫诲瀷 + /// </summary> + TaskType, + + /// <summary> + /// 褰撳墠浠诲姟鍙� + /// </summary> + CurrentTaskNum, + + /// <summary> + /// 鏈夎揣 + /// </summary> + InStock, + PickupLocation, + PutcargoLocation, + + /// <summary> + /// 褰撳墠鍒� + /// </summary> + CurrentColumn, + + /// <summary> + /// 褰撳墠灞� + /// </summary> + CurrentLayer, + + /// <summary> + /// 姘村钩鐐逛綅 + /// </summary> + LevelPoint, + } + + #endregion + + #region 杈撻�佺嚎鎵嬪姩鍛戒护 + + public WebResponseContent GetConveyorLineInfo(string DeviceChildCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == DeviceChildCode); + if (stationManager != null) + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC); + if (device != null) + { + CommonConveyorLine conveyorLine = (CommonConveyorLine)device; + ushort x = conveyorLine.GetValue<ConveyorLineDBName, ushort>(ConveyorLineDBName.InteractiveSignal, stationManager.stationChildCode); + var structs = BitConverter.GetBytes(x).ToArray().ToBoolArray(); + short ConveyorLineTaskNum = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.ConveyorLineTaskNum, stationManager.stationChildCode); + int ConveyorLineAlarm = conveyorLine.GetValue<ConveyorLineDBName, int>(ConveyorLineDBName.ConveyorLineAlarm, stationManager.stationChildCode); + ConveyorLineTaskCommand obj = new() + { + InStock = structs[2] == true ? "鏈夎揣" : "绌洪棽", + TaskNum = ConveyorLineTaskNum.ToString(), + Alarm = AlarmInfo(ConveyorLineAlarm) + }; + return content.OK(data:obj); + } + } + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + + public WebResponseContent ConveyorLineHandTask(HandTask ConveyorLinehand) + { + WebResponseContent content = new WebResponseContent(); + try + { + if (ConveyorLinehand == null || ConveyorLinehand.TaskType == "") + { + return content.Error("璇疯緭鍏ヤ换鍔″懡浠�"); + } + Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == ConveyorLinehand.DeviceCode); + if (stationManager != null) + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC); + if (device != null) + { + CommonConveyorLine conveyorLine = (CommonConveyorLine)device; + //鍏ュ簱 + if (ConveyorLinehand.TaskType == "1") + { + conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, Convert.ToInt16(ConveyorLinehand.TargetAddress), stationManager.stationChildCode); + Thread.Sleep(100); + conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, Convert.ToInt16(1), stationManager.stationChildCode); + Thread.Sleep(100); + conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(ConveyorLinehand.TaskType), stationManager.stationChildCode); + return content.OK("鍙戦�佽緭閫佺嚎鍏ュ簱浠诲姟鎴愬姛!"); + } + //鍑哄簱 + else if (ConveyorLinehand.TaskType == "2") + { + conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTargetAddress, Convert.ToInt16(ConveyorLinehand.TargetAddress), stationManager.stationChildCode); + Thread.Sleep(100); + conveyorLine.SetValue(ConveyorLineDBName.WriteConveyorLineTaskNum, Convert.ToInt16(1), stationManager.stationChildCode); + Thread.Sleep(100); + conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(ConveyorLinehand.TaskType), stationManager.stationChildCode); + return content.OK("鍙戦�佽緭閫佺嚎鍑哄簱浠诲姟鎴愬姛!"); + } + else + { + return content.Error("鏈壘鍒颁换鍔″懡浠�"); + } + } + } + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + + public WebResponseContent ConveyorLineReset(string DeviceChildCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == DeviceChildCode); + if (stationManager != null) + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC); + if (device != null) + { + CommonConveyorLine conveyorLine = (CommonConveyorLine)device; + conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(7), stationManager.stationChildCode); + return content.OK("澶嶄綅鎴愬姛"); + } + } + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + + public WebResponseContent ConveyorLineEmergencyStop(string DeviceChildCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == DeviceChildCode); + if (stationManager != null) + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC); + if (device != null) + { + CommonConveyorLine conveyorLine = (CommonConveyorLine)device; + conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(7), stationManager.stationChildCode); + return content.OK("鍋滄鎴愬姛"); + } + } + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + public WebResponseContent ConveyorLineReturn(string DeviceChildCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == DeviceChildCode); + if (stationManager != null) + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC); + if (device != null) + { + CommonConveyorLine conveyorLine = (CommonConveyorLine)device; + conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(3), stationManager.stationChildCode); + return content.OK("閫�鍥炴垚鍔�"); + } + } + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + public WebResponseContent ConveyorLineCancel(string DeviceChildCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == DeviceChildCode); + if (stationManager != null) + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC); + if (device != null) + { + CommonConveyorLine conveyorLine = (CommonConveyorLine)device; + conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(4), stationManager.stationChildCode); + return content.OK("鍙栨秷鎴愬姛"); + } + } + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + public WebResponseContent ConveyorLineInitialize(string DeviceChildCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == DeviceChildCode); + if (stationManager != null) + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManager.stationPLC); + if (device != null) + { + CommonConveyorLine conveyorLine = (CommonConveyorLine)device; + conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, Convert.ToSByte(6), stationManager.stationChildCode); + return content.OK("鍒濆鍖栨垚鍔�"); + } + } + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + + string AlarmInfo(int Alarm) => Alarm switch + { + 0 => "鎬ュ仠", + 1 => "鍙橀鍣ㄦ姤璀�1", + 2 => "鍙橀鍣ㄦ姤璀�2", + 3 => "宸﹁秴瀹�", + 4 => "鍙宠秴瀹�", + 5 => "瓒呴珮", + 6 => "璇荤爜澶辫触", + 7 => "璐х墿瓒呴噸", + 8 => "杩愯瓒呮椂", + 9 => "宸ヤ綅浼犳劅鍣ㄥ紓甯�", + 10 => "棰勭暀1", + 11 => "棰勭暀2", + 12 => "棰勭暀3", + 13 => "棰勭暀4", + 14 => "棰勭暀5", + 15 => "棰勭暀6", + }; + + public enum ConveyorLineDBName + { + InteractiveSignal, + ConveyorLineBarcode, + ConveyorLineAlarm, + ConveyorLineTargetAddress, + ConveyorLineTaskNum, + + WriteInteractiveSignal, + WriteConveyorLineTargetAddress, + WriteConveyorLineTaskNum, + } + public class ConveyorLineTaskCommand + { + public string InStock { get; set; } + + public string TaskNum { get; set; } + + public string Alarm { get; set; } + } + #endregion + + #region RGV鎵嬪姩鍛戒护 + public WebResponseContent RGVHandTask(HandTask RGVhand) + { + WebResponseContent content = new WebResponseContent(); + try + { + if (RGVhand == null || RGVhand.TaskType == "") + { + return content.Error("璇疯緭鍏ヤ换鍔″懡浠�"); + } + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == RGVhand.DeviceCode); + if (device != null) + { + if (RGVhand.DeviceCode == "RGV01" || RGVhand.DeviceCode == "RGV02") + { + CommonRGV_FirstFloor RGVcommand = (CommonRGV_FirstFloor)device; + if (RGVhand.TaskType == "1") + { + if (RGVhand.SourceAddress != null) + { + RGVTaskCommand command = new RGVTaskCommand() + { + PickupLocation = (byte)Convert.ToSByte(RGVhand.SourceAddress), + TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), + }; + SendCommandFirstFloor(RGVcommand, command); + return content.OK($"{device.DeviceName}鍙栧畾浣嶅懡浠や笅鍙戞垚鍔�"); + } + else + { + return content.Error($"{device.DeviceName}鍙栧畾浣嶅懡浠ゅ彇璐т綅涓嶈兘涓虹┖"); + } + + } + else if (RGVhand.TaskType == "2") + { + if (RGVhand.TargetAddress != null) + { + RGVTaskCommand command = new RGVTaskCommand() + { + PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress), + TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), + }; + SendCommandFirstFloor(RGVcommand, command); + return content.OK($"{device.DeviceName}鏀惧畾浣嶅懡浠や笅鍙戞垚鍔�"); + } + else + { + return content.Error($"{device.DeviceName}鏀惧畾浣嶅懡浠ゆ斁璐т綅涓嶈兘涓虹┖"); + } + } + else if (RGVhand.TaskType == "3") + { + if (RGVhand.SourceAddress != null) + { + RGVTaskCommand command = new RGVTaskCommand() + { + PickupLocation = (byte)Convert.ToSByte(RGVhand.SourceAddress), + TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), + }; + SendCommandFirstFloor(RGVcommand, command); + return content.OK($"{device.DeviceName}鍙栬揣鍛戒护涓嬪彂鎴愬姛"); + } + else + { + return content.Error($"{device.DeviceName}鍙栬揣鍛戒护鍙栬揣浣嶄笉鑳戒负绌�"); + } + } + else if (RGVhand.TaskType == "4") + { + if (RGVhand.TargetAddress != null) + { + RGVTaskCommand command = new RGVTaskCommand() + { + PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress), + TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), + }; + SendCommandFirstFloor(RGVcommand, command); + return content.OK($"{device.DeviceName}鏀捐揣鍛戒护涓嬪彂鎴愬姛"); + } + else + { + return content.Error($"{device.DeviceName}鏀捐揣鍛戒护鏀捐揣浣嶄笉鑳戒负绌�"); + } + } + else if (RGVhand.TaskType == "5") + { + if (RGVhand.TargetAddress != null && RGVhand.TargetAddress != null) + { + RGVTaskCommand command = new RGVTaskCommand() + { + PickupLocation = (byte)Convert.ToSByte(RGVhand.SourceAddress), + PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress), + TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), + }; + SendCommandFirstFloor(RGVcommand, command); + return content.OK($"{device.DeviceName}鍙栨斁璐у懡浠や笅鍙戞垚鍔�"); + } + else + { + return content.Error($"{device.DeviceName}鍙栨斁璐у懡浠ゆ斁璐т綅鍜屽彇璐т綅涓嶈兘涓虹┖"); + } + } + else if (RGVhand.TaskType == "6") + { + if (RGVhand.TargetAddress != null) + { + RGVTaskCommand command = new RGVTaskCommand() + { + PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress), + TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), + }; + SendCommandFirstFloor(RGVcommand, command); + return content.OK($"{device.DeviceName}閫�鍛戒护涓嬪彂鎴愬姛"); + } + else + { + return content.Error($"{device.DeviceName}閫�鍥炲懡浠ゆ斁璐т綅涓嶈兘涓虹┖"); + } + } + else + { + return content.Error($"{device.DeviceName}鏈煡浠诲姟鍛戒护"); + } + } + else + { + CommonRGV RGVcommand = (CommonRGV)device; + if (RGVhand.TaskType == "1") + { + if (RGVhand.SourceAddress != null) + { + RGVTaskCommand command = new RGVTaskCommand() + { + PickupLocation = (byte)Convert.ToSByte(RGVhand.SourceAddress), + TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), + }; + SendCommandSecondFloor(RGVcommand, command); + return content.OK($"{device.DeviceName}鍙栧畾浣嶅懡浠や笅鍙戞垚鍔�"); + } + else + { + return content.Error($"{device.DeviceName}鍙栧畾浣嶅懡浠ゅ彇璐т綅涓嶈兘涓虹┖"); + } + + } + else if (RGVhand.TaskType == "2") + { + if (RGVhand.TargetAddress != null) + { + RGVTaskCommand command = new RGVTaskCommand() + { + PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress), + TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), + }; + SendCommandSecondFloor(RGVcommand, command); + return content.OK($"{device.DeviceName}鏀惧畾浣嶅懡浠や笅鍙戞垚鍔�"); + } + else + { + return content.Error($"{device.DeviceName}鏀惧畾浣嶅懡浠ゆ斁璐т綅涓嶈兘涓虹┖"); + } + } + else if (RGVhand.TaskType == "3") + { + if (RGVhand.SourceAddress != null) + { + RGVTaskCommand command = new RGVTaskCommand() + { + PickupLocation = (byte)Convert.ToSByte(RGVhand.SourceAddress), + TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), + }; + SendCommandSecondFloor(RGVcommand, command); + return content.OK($"{device.DeviceName}鍙栬揣鍛戒护涓嬪彂鎴愬姛"); + } + else + { + return content.Error($"{device.DeviceName}鍙栬揣鍛戒护鍙栬揣浣嶄笉鑳戒负绌�"); + } + } + else if (RGVhand.TaskType == "4") + { + if (RGVhand.TargetAddress != null) + { + RGVTaskCommand command = new RGVTaskCommand() + { + PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress), + TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), + }; + SendCommandSecondFloor(RGVcommand, command); + return content.OK($"{device.DeviceName}鏀捐揣鍛戒护涓嬪彂鎴愬姛"); + } + else + { + return content.Error($"{device.DeviceName}鏀捐揣鍛戒护鏀捐揣浣嶄笉鑳戒负绌�"); + } + } + else if (RGVhand.TaskType == "5") + { + if (RGVhand.TargetAddress != null && RGVhand.TargetAddress != null) + { + RGVTaskCommand command = new RGVTaskCommand() + { + PickupLocation = (byte)Convert.ToSByte(RGVhand.SourceAddress), + PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress), + TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), + }; + SendCommandSecondFloor(RGVcommand, command); + return content.OK($"{device.DeviceName}鍙栨斁璐у懡浠や笅鍙戞垚鍔�"); + } + else + { + return content.Error("鍙栨斁璐у懡浠ゆ斁璐т綅鍜屽彇璐т綅涓嶈兘涓虹┖"); + } + } + else if (RGVhand.TaskType == "6") + { + if (RGVhand.TargetAddress != null) + { + RGVTaskCommand command = new RGVTaskCommand() + { + PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress), + TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), + }; + SendCommandSecondFloor(RGVcommand, command); + return content.OK($"{device.DeviceName}閫�鍥炲懡浠や笅鍙戞垚鍔�"); + } + else + { + return content.Error($"{device.DeviceName}閫�鍥炲懡浠ゆ斁璐т綅涓嶈兘涓虹┖"); + } + } + else + { + return content.Error($"{device.DeviceName}鏈煡浠诲姟鍛戒护"); + } + } + } + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + + public WebResponseContent RGVReset(string DeviceCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode); + if (device != null) + { + if (DeviceCode == "RGV01" || DeviceCode == "RGV02") + { + CommonRGV_FirstFloor commonRGV = (CommonRGV_FirstFloor)device; + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9)); + } + else + { + CommonRGV commonRGV = (CommonRGV)device; + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9)); + } + return content.OK($"{device.DeviceName}澶嶄綅鎴愬姛"); + } + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + + public WebResponseContent RGVEmergencyStop(string DeviceCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode); + if (device != null) + { + if (DeviceCode == "RGV01" || DeviceCode == "RGV02") + { + CommonRGV_FirstFloor commonRGV = (CommonRGV_FirstFloor)device; + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(11)); + } + else + { + CommonRGV commonRGV = (CommonRGV)device; + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(11)); + } + return content.OK($"{device.DeviceName}鍋滄鎴愬姛"); + } + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + public WebResponseContent RGVCancel(string DeviceCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode); + if (device != null) + { + if (DeviceCode == "RGV01" || DeviceCode == "RGV02") + { + CommonRGV_FirstFloor commonRGV = (CommonRGV_FirstFloor)device; + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9)); + } + else + { + CommonRGV commonRGV = (CommonRGV)device; + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9)); + } + return content.OK($"{device.DeviceName}涓柇鎴愬姛"); + } + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + public WebResponseContent RGVInitialize(string DeviceCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode); + if (device != null) + { + if (DeviceCode == "RGV01" || DeviceCode == "RGV02") + { + CommonRGV_FirstFloor commonRGV = (CommonRGV_FirstFloor)device; + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9)); + } + else + { + CommonRGV commonRGV = (CommonRGV)device; + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9)); + } + return content.OK($"{device.DeviceName}鍒濆鍖栨垚鍔�"); + } + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + + public WebResponseContent RGVPause(string DeviceCode) + { + WebResponseContent content = new WebResponseContent(); + try + { + IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceCode); + if (device != null) + { + if (DeviceCode == "RGV01" || DeviceCode == "RGV02") + { + CommonRGV_FirstFloor commonRGV = (CommonRGV_FirstFloor)device; + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(10)); + } + else + { + CommonRGV commonRGV = (CommonRGV)device; + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(10)); + } + return content.OK($"{device.DeviceName}鏆傚仠鎴愬姛"); + } + return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); + } + catch (Exception ex) + { + return content.Error(ex.Message); + } + } + + + + public void SendCommandFirstFloor(CommonRGV_FirstFloor commonRGV, RGVTaskCommand? rgvTaskCommand) + { + commonRGV.SetValue(StackerCraneDBName.TaskNum, Convert.ToInt16(1)); + Thread.Sleep(100); + commonRGV.SetValue(StackerCraneDBName.PutcargoLocation, (byte)Convert.ToSByte(rgvTaskCommand.PutcargoLocation)); + Thread.Sleep(100); + commonRGV.SetValue(StackerCraneDBName.PickupLocation, (byte)Convert.ToSByte(rgvTaskCommand.PickupLocation)); + Thread.Sleep(100); + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(rgvTaskCommand.TaskType)); + + } + public void SendCommandSecondFloor(CommonRGV commonRGV, RGVTaskCommand? rgvTaskCommand) + { + commonRGV.SetValue(StackerCraneDBName.TaskNum, Convert.ToInt16(1)); + Thread.Sleep(100); + commonRGV.SetValue(StackerCraneDBName.PutcargoLocation, (byte)Convert.ToSByte(rgvTaskCommand.PutcargoLocation)); + Thread.Sleep(100); + commonRGV.SetValue(StackerCraneDBName.PickupLocation, (byte)Convert.ToSByte(rgvTaskCommand.PickupLocation)); + Thread.Sleep(100); + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(rgvTaskCommand.TaskType)); + + } + + public class RGVTaskCommand + { + #region <Public Menber> + + /// <summary> + /// 鍙栬揣浣� + /// </summary> + public byte PickupLocation { get; set; } + + /// <summary> + /// 鏀捐揣浣� + /// </summary> + public byte PutcargoLocation { get; set; } + + /// <summary> + /// 浠诲姟绫诲瀷 + /// </summary> + public byte TaskType { get; set; } + + /// <summary> + /// 棰勭暀 + /// </summary> + public byte Spare { get; set; } + + /// <summary> + /// 浠诲姟鍙� + /// </summary> + public short TaskNum { get; set; } + + + #endregion <Public Menber> + } + + #endregion } } -- Gitblit v1.9.3