From 2190be42c0d77be84fed82d387f2a34da7fe4acc Mon Sep 17 00:00:00 2001 From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com> Date: 星期四, 07 八月 2025 16:17:07 +0800 Subject: [PATCH] 1 --- 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/Service/DeviceInfoService.cs | 552 ++++++++++++++++++++++++++++++++----------------------- 1 files changed, 322 insertions(+), 230 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 b01298a..7742cf6 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" @@ -22,8 +22,10 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Claims; using System.Text; using System.Threading.Tasks; +using WIDESEA_Common.Log; using WIDESEAWCS_BasicInfoRepository; using WIDESEAWCS_Core; using WIDESEAWCS_Core.BaseRepository; @@ -73,6 +75,7 @@ public WebResponseContent StackerHandTask(HandTask stackerhand) { + WriteLog.GetLog("鍫嗗灈鏈烘墜鍔ㄤ换鍔�").Write(JsonConvert.SerializeObject(stackerhand), "鍫嗗灈鏈烘墜鍔ㄤ换鍔�"); WebResponseContent content = new WebResponseContent(); try { @@ -89,9 +92,9 @@ 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.StartRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(sourceCodes[0]))); + stackerCraneTaskCommand.StartColumn = (byte)Convert.ToSByte(sourceCodes[2]); + stackerCraneTaskCommand.StartLayer = (byte)Convert.ToSByte(sourceCodes[1]); } else { @@ -101,9 +104,9 @@ 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]); + stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(targetCodes[0]))); + stackerCraneTaskCommand.EndColumn = (byte)Convert.ToSByte(targetCodes[2]); + stackerCraneTaskCommand.EndLayer = (byte)Convert.ToSByte(targetCodes[1]); } else { @@ -116,9 +119,9 @@ 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.StartRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(sourceCodes[0]))); + stackerCraneTaskCommand.StartColumn = (byte)Convert.ToSByte(sourceCodes[2]); + stackerCraneTaskCommand.StartLayer = (byte)Convert.ToSByte(sourceCodes[1]); } else { @@ -127,9 +130,9 @@ 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]); + stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(targetCodes[0]))); + stackerCraneTaskCommand.EndColumn = (byte)Convert.ToSByte(targetCodes[2]); + stackerCraneTaskCommand.EndLayer = (byte)Convert.ToSByte(targetCodes[1]); } else { @@ -142,9 +145,9 @@ 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.StartRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(sourceCodes[0]))); + stackerCraneTaskCommand.StartColumn = (byte)Convert.ToSByte(sourceCodes[2]); + stackerCraneTaskCommand.StartLayer = (byte)Convert.ToSByte(sourceCodes[1]); } else { @@ -154,9 +157,9 @@ 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]); + stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(targetCodes[0]))); + stackerCraneTaskCommand.EndColumn = (byte)Convert.ToSByte(targetCodes[2]); + stackerCraneTaskCommand.EndLayer = (byte)Convert.ToSByte(targetCodes[1]); } else { @@ -169,9 +172,9 @@ 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.StartRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(sourceCodes[0]))); + stackerCraneTaskCommand.StartColumn = (byte)Convert.ToSByte(sourceCodes[2]); + stackerCraneTaskCommand.StartLayer = (byte)Convert.ToSByte(sourceCodes[1]); stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(0); stackerCraneTaskCommand.EndColumn = (byte)Convert.ToSByte(0); @@ -192,9 +195,9 @@ 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]); + stackerCraneTaskCommand.EndRow = (byte)Convert.ToSByte(GetRowCode(Convert.ToInt32(targetCodes[0]))); + stackerCraneTaskCommand.EndColumn = (byte)Convert.ToSByte(targetCodes[2]); + stackerCraneTaskCommand.EndLayer = (byte)Convert.ToSByte(targetCodes[1]); } else { @@ -205,8 +208,10 @@ { return content.Error("鏈壘鍒颁换鍔″懡浠�"); } + StackerSendCommand(stackerCraneTaskCommand, stackerhand.DeviceCode); - return content; + + return content.OK("鍛戒护涓嬪彂鎴愬姛锛�"); } catch (Exception ex) { @@ -216,6 +221,7 @@ public WebResponseContent StackerReset(string DeviceCode) { + WriteLog.GetLog("鍫嗗灈鏈烘墜鍔ㄤ换鍔�").Write($"銆愬浣嶅懡浠ゃ�憑JsonConvert.SerializeObject(DeviceCode)}", "鍫嗗灈鏈烘墜鍔ㄤ换鍔�"); WebResponseContent content = new WebResponseContent(); try { @@ -225,7 +231,7 @@ { CommonStackerCrane commonStackerCrane = (CommonStackerCrane)device; - commonStackerCrane.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(2)); + commonStackerCrane.SetValue(StackerCraneDBName.WorkType, Convert.ToSByte(2)); return content.OK(); } else @@ -241,6 +247,7 @@ public WebResponseContent StackerEmergencyStop(string DeviceCode) { + WriteLog.GetLog("鍫嗗灈鏈烘墜鍔ㄤ换鍔�").Write($"銆愭�ュ仠鍛戒护銆憑JsonConvert.SerializeObject(DeviceCode)}", "鍫嗗灈鏈烘墜鍔ㄤ换鍔�"); WebResponseContent content = new WebResponseContent(); try { @@ -250,7 +257,7 @@ { CommonStackerCrane commonStackerCrane = (CommonStackerCrane)device; - commonStackerCrane.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(2)); + commonStackerCrane.SetValue(StackerCraneDBName.WorkType, Convert.ToSByte(2)); return content.OK(); } else @@ -282,7 +289,7 @@ commonStackerCrane.SetValue(StackerCraneDBName.StartColumn, command.StartColumn); Thread.Sleep(100); - commonStackerCrane.SetValue(StackerCraneDBName.StartColumn, command.StartLayer); + commonStackerCrane.SetValue(StackerCraneDBName.StartLayer, command.StartLayer); Thread.Sleep(100); commonStackerCrane.SetValue(StackerCraneDBName.EndRow, command.EndRow); @@ -292,11 +299,11 @@ Thread.Sleep(100); commonStackerCrane.SetValue(StackerCraneDBName.EndLayer, command.EndLayer); Thread.Sleep(100); - commonStackerCrane.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(command.WorkType)); + commonStackerCrane.SetValue(StackerCraneDBName.WorkType, Convert.ToSByte(command.WorkType)); } else { - throw new Exception("璇峰湪鍫嗗灈鏈鸿仈鏈烘ā寮忋�佸緟鏈虹姸鎬併�佹棤鏁呴殰鐨勬儏鍐典笅涓嬪彂浠诲姟"); + throw new Exception($"璇峰湪{commonStackerCrane.DeviceName}鑱旀満妯″紡銆佸緟鏈虹姸鎬併�佹棤鏁呴殰鐨勬儏鍐典笅涓嬪彂浠诲姟"); } } else @@ -305,7 +312,29 @@ } } - + public int GetRowCode(int number) + { + if (number == 1 || number == 15 || number == 11 || number == 19) + { + return 1; + } + else if (number == 2 || number == 5 || number == 8 || number == 12 || number == 16 || number == 20) + { + return 2; + } + else if (number == 3 || number == 6 || number == 9 || number == 13 || number == 17 || number == 21) + { + return 3; + } + else if (number == 4 || number == 7 || number == 10 || number == 14 || number == 18 || number == 22) + { + return 4; + } + else + { + throw new ArgumentOutOfRangeException(nameof(number), "杈撳叆鐨勬暟瀛楀繀椤诲湪1-16鑼冨洿鍐�"); + } + } public class StackerCraneTaskCommand { #region <Public Menber> @@ -495,10 +524,10 @@ if (device != null) { CommonConveyorLine conveyorLine = (CommonConveyorLine)device; - ushort x = conveyorLine.GetValue<ConveyorLineDBName, ushort>(ConveyorLineDBName.InteractiveSignal, stationManager.stationChildCode); + short x = conveyorLine.GetValue<ConveyorLineDBName, short>(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); + uint ConveyorLineAlarm = conveyorLine.GetValue<ConveyorLineDBName, uint>(ConveyorLineDBName.ConveyorLineAlarm, stationManager.stationChildCode); ConveyorLineTaskCommand obj = new() { InStock = structs[2] == true ? "鏈夎揣" : "绌洪棽", @@ -518,6 +547,7 @@ public WebResponseContent ConveyorLineHandTask(HandTask ConveyorLinehand) { + WriteLog.GetLog("杈撻�佺嚎鎵嬪姩浠诲姟").Write(JsonConvert.SerializeObject(ConveyorLinehand), "杈撻�佺嚎鎵嬪姩浠诲姟"); WebResponseContent content = new WebResponseContent(); try { @@ -532,6 +562,12 @@ if (device != null) { CommonConveyorLine conveyorLine = (CommonConveyorLine)device; + short x = conveyorLine.GetValue<ConveyorLineDBName, short>(ConveyorLineDBName.InteractiveSignal, stationManager.stationChildCode); + var structs = BitConverter.GetBytes(x).ToArray().ToBoolArray(); + if (!structs[2]) + { + return content.Error($"璇峰湪{stationManager.stationChildCode}杈撻�佺嚎灏辩华鎯呭喌涓嬩笅鍙戝懡浠�"); + } //鍏ュ簱 if (ConveyorLinehand.TaskType == "1") { @@ -568,6 +604,7 @@ public WebResponseContent ConveyorLineReset(string DeviceChildCode) { + WriteLog.GetLog("杈撻�佺嚎鎵嬪姩浠诲姟").Write($"銆愬浣嶅懡浠ゃ�憑JsonConvert.SerializeObject(DeviceChildCode)}", "杈撻�佺嚎鎵嬪姩浠诲姟"); WebResponseContent content = new WebResponseContent(); try { @@ -592,6 +629,7 @@ public WebResponseContent ConveyorLineEmergencyStop(string DeviceChildCode) { + WriteLog.GetLog("杈撻�佺嚎鎵嬪姩浠诲姟").Write($"銆愭�ュ仠鍛戒护銆憑JsonConvert.SerializeObject(DeviceChildCode)}", "杈撻�佺嚎鎵嬪姩浠诲姟"); WebResponseContent content = new WebResponseContent(); try { @@ -615,6 +653,7 @@ } public WebResponseContent ConveyorLineReturn(string DeviceChildCode) { + WriteLog.GetLog("杈撻�佺嚎鎵嬪姩浠诲姟").Write($"銆愰��鍥炲懡浠ゃ�憑JsonConvert.SerializeObject(DeviceChildCode)}", "杈撻�佺嚎鎵嬪姩浠诲姟"); WebResponseContent content = new WebResponseContent(); try { @@ -638,6 +677,7 @@ } public WebResponseContent ConveyorLineCancel(string DeviceChildCode) { + WriteLog.GetLog("杈撻�佺嚎鎵嬪姩浠诲姟").Write($"銆愬彇娑堝懡浠ゃ�憑JsonConvert.SerializeObject(DeviceChildCode)}", "杈撻�佺嚎鎵嬪姩浠诲姟"); WebResponseContent content = new WebResponseContent(); try { @@ -661,6 +701,7 @@ } public WebResponseContent ConveyorLineInitialize(string DeviceChildCode) { + WriteLog.GetLog("杈撻�佺嚎鎵嬪姩浠诲姟").Write($"銆愬垵濮嬪寲鍛戒护銆憑JsonConvert.SerializeObject(DeviceChildCode)}", "杈撻�佺嚎鎵嬪姩浠诲姟"); WebResponseContent content = new WebResponseContent(); try { @@ -683,7 +724,7 @@ } } - string AlarmInfo(int Alarm) => Alarm switch + string AlarmInfo(uint Alarm) => Alarm switch { 0 => "鎬ュ仠", 1 => "鍙橀鍣ㄦ姤璀�1", @@ -701,6 +742,7 @@ 13 => "棰勭暀4", 14 => "棰勭暀5", 15 => "棰勭暀6", + _ => $"鏈煡鎶ヨ({Alarm})" }; public enum ConveyorLineDBName @@ -728,6 +770,7 @@ #region RGV鎵嬪姩鍛戒护 public WebResponseContent RGVHandTask(HandTask RGVhand) { + WriteLog.GetLog("RGV鎵嬪姩浠诲姟").Write(JsonConvert.SerializeObject(RGVhand), "RGV鎵嬪姩浠诲姟"); WebResponseContent content = new WebResponseContent(); try { @@ -741,227 +784,241 @@ if (RGVhand.DeviceCode == "RGV01" || RGVhand.DeviceCode == "RGV02") { CommonRGV_FirstFloor RGVcommand = (CommonRGV_FirstFloor)device; - if (RGVhand.TaskType == "1") + if (RGVcommand.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !RGVcommand.GetValue<RGVDBName, bool>(RGVDBName.Fault) && !RGVcommand.GetValue<RGVDBName, bool>(RGVDBName.Running)) { - if (RGVhand.SourceAddress != null) + if (RGVhand.TaskType == "1") { - RGVTaskCommand command = new RGVTaskCommand() + if (RGVhand.SourceAddress != null) { - 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}鍙栧畾浣嶅懡浠ゅ彇璐т綅涓嶈兘涓虹┖"); - } + 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) + } + else if (RGVhand.TaskType == "2") { - RGVTaskCommand command = new RGVTaskCommand() + if (RGVhand.TargetAddress != null) { - PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress), - TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), - }; - SendCommandFirstFloor(RGVcommand, command); - return content.OK($"{device.DeviceName}鏀惧畾浣嶅懡浠や笅鍙戞垚鍔�"); + 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(4), + }; + SendCommandFirstFloor(RGVcommand, command); + return content.OK($"{device.DeviceName}閫�鍛戒护涓嬪彂鎴愬姛"); + } + else + { + return content.Error($"{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}閫�鍥炲懡浠ゆ斁璐т綅涓嶈兘涓虹┖"); + return content.Error($"{device.DeviceName}鏈煡浠诲姟鍛戒护"); } } else { - return content.Error($"{device.DeviceName}鏈煡浠诲姟鍛戒护"); + return content.Error($"璇峰湪鑱旀満妯″紡銆佹棤鏁呴殰銆佸緟鏈虹姸鎬佹椂鍐嶄笅鍙憑RGVcommand.DeviceName}鍛戒护"); } } else { CommonRGV RGVcommand = (CommonRGV)device; - if (RGVhand.TaskType == "1") + if (RGVcommand.GetValue<RGVDBName, bool>(RGVDBName.Automatic) && !RGVcommand.GetValue<RGVDBName, bool>(RGVDBName.Fault) && !RGVcommand.GetValue<RGVDBName, bool>(RGVDBName.Running)) { - if (RGVhand.SourceAddress != null) + if (RGVhand.TaskType == "1") { - RGVTaskCommand command = new RGVTaskCommand() + if (RGVhand.SourceAddress != null) { - 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}鍙栧畾浣嶅懡浠ゅ彇璐т綅涓嶈兘涓虹┖"); - } + 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) + } + else if (RGVhand.TaskType == "2") { - RGVTaskCommand command = new RGVTaskCommand() + if (RGVhand.TargetAddress != null) { - PutcargoLocation = (byte)Convert.ToSByte(RGVhand.TargetAddress), - TaskType = (byte)Convert.ToSByte(RGVhand.TaskType), - }; - SendCommandSecondFloor(RGVcommand, command); - return content.OK($"{device.DeviceName}鏀惧畾浣嶅懡浠や笅鍙戞垚鍔�"); + 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}鏀惧畾浣嶅懡浠ゆ斁璐т綅涓嶈兘涓虹┖"); - } - } - 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}閫�鍥炲懡浠ゆ斁璐т綅涓嶈兘涓虹┖"); + return content.Error($"{device.DeviceName}鏈煡浠诲姟鍛戒护"); } } else { - return content.Error($"{device.DeviceName}鏈煡浠诲姟鍛戒护"); + return content.Error($"璇峰湪鑱旀満妯″紡銆佹棤鏁呴殰銆佸緟鏈虹姸鎬佹椂鍐嶄笅鍙憑RGVcommand.DeviceName}鍛戒护"); } - } + } } return content.Error("鏈壘鍒拌澶囦俊鎭鑱旂郴IT"); } @@ -973,6 +1030,7 @@ public WebResponseContent RGVReset(string DeviceCode) { + WriteLog.GetLog("RGV鎵嬪姩浠诲姟").Write($"銆愬浣嶅懡浠ゃ�憑JsonConvert.SerializeObject(DeviceCode)}", "RGV鎵嬪姩浠诲姟"); WebResponseContent content = new WebResponseContent(); try { @@ -982,12 +1040,12 @@ if (DeviceCode == "RGV01" || DeviceCode == "RGV02") { CommonRGV_FirstFloor commonRGV = (CommonRGV_FirstFloor)device; - commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9)); + commonRGV.SetValue(RGVDBName.TaskType, Convert.ToSByte(9)); } else { CommonRGV commonRGV = (CommonRGV)device; - commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9)); + commonRGV.SetValue(RGVDBName.TaskType, Convert.ToSByte(9)); } return content.OK($"{device.DeviceName}澶嶄綅鎴愬姛"); } @@ -1001,6 +1059,7 @@ public WebResponseContent RGVEmergencyStop(string DeviceCode) { + WriteLog.GetLog("RGV鎵嬪姩浠诲姟").Write($"銆愭�ュ仠鍛戒护銆憑JsonConvert.SerializeObject(DeviceCode)}", "RGV鎵嬪姩浠诲姟"); WebResponseContent content = new WebResponseContent(); try { @@ -1028,6 +1087,7 @@ } public WebResponseContent RGVCancel(string DeviceCode) { + WriteLog.GetLog("RGV鎵嬪姩浠诲姟").Write($"銆愬彇娑堜换鍔″懡浠ゃ�憑JsonConvert.SerializeObject(DeviceCode)}", "RGV鎵嬪姩浠诲姟"); WebResponseContent content = new WebResponseContent(); try { @@ -1037,12 +1097,12 @@ if (DeviceCode == "RGV01" || DeviceCode == "RGV02") { CommonRGV_FirstFloor commonRGV = (CommonRGV_FirstFloor)device; - commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9)); + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(7)); } else { CommonRGV commonRGV = (CommonRGV)device; - commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9)); + commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(7)); } return content.OK($"{device.DeviceName}涓柇鎴愬姛"); } @@ -1055,21 +1115,33 @@ } public WebResponseContent RGVInitialize(string DeviceCode) { + WriteLog.GetLog("RGV鎵嬪姩浠诲姟").Write($"銆愬垵濮嬪寲鍛戒护銆憑JsonConvert.SerializeObject(DeviceCode)}", "RGV鎵嬪姩浠诲姟"); 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)); + DeviceProDTO? devicePro = commonRGV.DeviceProDTOs.Where(x => x.DeviceChildCode == commonRGV.DeviceCode && x.DeviceProParamName == "TaskType").FirstOrDefault(); + //byte[] byt = Encoding.UTF8.GetBytes("08"); + byte valueToWrite = 8; + + byte[] buffer = new byte[] { valueToWrite }; + + commonRGV.Communicator.Write(devicePro.DeviceProAddress, buffer); } else { CommonRGV commonRGV = (CommonRGV)device; - commonRGV.SetValue(StackerCraneDBName.TaskType, Convert.ToSByte(9)); + DeviceProDTO? devicePro = commonRGV.DeviceProDTOs.Where(x => x.DeviceChildCode == commonRGV.DeviceCode && x.DeviceProParamName == "TaskType").FirstOrDefault(); + byte valueToWrite = 8; + + byte[] buffer = new byte[] { valueToWrite }; + commonRGV.Communicator.Write(devicePro.DeviceProAddress, buffer); } return content.OK($"{device.DeviceName}鍒濆鍖栨垚鍔�"); } @@ -1083,6 +1155,7 @@ public WebResponseContent RGVPause(string DeviceCode) { + WriteLog.GetLog("RGV鎵嬪姩浠诲姟").Write($"銆愬仠姝㈠懡浠ゃ�憑JsonConvert.SerializeObject(DeviceCode)}", "RGV鎵嬪姩浠诲姟"); WebResponseContent content = new WebResponseContent(); try { @@ -1113,7 +1186,7 @@ public void SendCommandFirstFloor(CommonRGV_FirstFloor commonRGV, RGVTaskCommand? rgvTaskCommand) { - commonRGV.SetValue(StackerCraneDBName.TaskNum, Convert.ToInt16(1)); + commonRGV.SetValue(RGVDBName.TaskNum, Convert.ToInt16(1)); Thread.Sleep(100); commonRGV.SetValue(StackerCraneDBName.PutcargoLocation, (byte)Convert.ToSByte(rgvTaskCommand.PutcargoLocation)); Thread.Sleep(100); @@ -1167,6 +1240,25 @@ #endregion <Public Menber> } + public enum RGVDBName + { + SendTask, + Automatic, + WorkCompleted, + Running, + Fault, + InStock, + RGVTargetAddress, + RGVTaskNum, + PickupLocation, + PutcargoLocation, + TaskType, + TaskNum, + LevelPoint, + CurrentTaskNum, + RGVAlarm, + } + #endregion } } -- Gitblit v1.9.3