From b4083a6b047fc9e0964133c87227213c5154e37a Mon Sep 17 00:00:00 2001 From: IPC-610 <IPC-610@DESKTOP-6LEOOS3> Date: 星期三, 15 一月 2025 15:47:44 +0800 Subject: [PATCH] 11111111 --- Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs | 768 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 760 insertions(+), 8 deletions(-) diff --git a/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs b/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs index 612c67d..c0c19d2 100644 --- a/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs +++ b/Admin.NET/WCS.Application/Service/WcsDevice/WcsDeviceService.cs @@ -1,7 +1,9 @@ 锘� using Admin.NET.Core.Service; using Elastic.Clients.Elasticsearch; +using Microsoft.CodeAnalysis.Text; using StackExchange.Profiling.Internal; +using System.Drawing.Drawing2D; using WCS.Application.Entity; using WCS.Application.Service.WcsDevice.Dto; @@ -13,13 +15,708 @@ [ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)] public class WcsDeviceService : IDynamicApiController, ITransient { + private readonly SqlSugarRepository<WcsPlc> _wcsPlcRep; private readonly SqlSugarRepository<WcsDevice> _wcsDeviceRep; private readonly SysCacheService _sysCacheService; - public WcsDeviceService(SqlSugarRepository<WcsDevice> wcsDeviceRep, SysCacheService sysCacheService) + public WcsDeviceService(SqlSugarRepository<WcsPlc> wcsPlcRep, SqlSugarRepository<WcsDevice> wcsDeviceRep, SysCacheService sysCacheService) { + _wcsPlcRep = wcsPlcRep; _wcsDeviceRep = wcsDeviceRep; _sysCacheService = sysCacheService; } + + #region 宸ヤ綔鍙版搷浣� + + + /// <summary> + /// 鎵嬪姩鎿嶄綔PLC閿佸畾鍐欏叆宸ヤ綅淇℃伅 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost] + [ApiDescriptionSettings(Name = "WriteLocationInfo")] + [DisplayName("鎵嬪姩鎿嶄綔PLC閿佸畾鍐欏叆宸ヤ綅淇℃伅")] + public async Task WriteLocationInfo(WcsDeviceUpInfo input) + { + WcsPlc modPlc; + string DbNum = "";// DB鍧� + + if (string.IsNullOrWhiteSpace(input.LocatNo))//濡傛灉宸ヤ綅涓虹┖ + { + throw Oops.Bah("宸ヤ綅涓嶈兘涓虹┖"); + } + var plcList = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine && s.IsDelete == false).ToListAsync(); + switch (input.Layer) + { + case "1": + modPlc = plcList.FirstOrDefault(m => m.Text == "1灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = ""; + break; + case "2": + modPlc = plcList.FirstOrDefault(m => m.Text == "2灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = "DB91"; + break; + case "3": + modPlc = plcList.FirstOrDefault(m => m.Text == "3灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = ""; + break; + default: + throw Oops.Bah("妤煎眰淇℃伅閿欒"); + } + + var device = await _wcsDeviceRep.Context.Queryable<WcsDevice>().FirstAsync(s => s.PlcId == modPlc.Id && s.StationNum == input.LocatNo && s.IsDelete == false && s.DeviceType == DeviceTypeEnum.Show); + if (device == null) + { + throw Oops.Bah("褰撳墠妤煎眰鏈煡璇㈠埌璇ュ伐浣嶄俊鎭�"); + } + PLCUtil modUtil = new PLCUtil(modPlc); + + switch (input.TypeName) + { + case "suoding": // 閿佸畾 + modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "48.0", input.LocatNo); + break; + + default: + break; + } + + modUtil.Close(); + } + + + /// <summary> + /// 鑾峰彇宸ヤ綅涓婁俊鎭� + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost] + [ApiDescriptionSettings(Name = "GetLocationInfo")] + [DisplayName("鑾峰彇宸ヤ綅涓婁俊鎭�")] + public async Task<WcsDeviceUpInfo> GetLocationInfo(WcsDeviceUpInfo input) + { + WcsPlc modPlc; + string DbNum = "";// DB鍧� + + if (string.IsNullOrWhiteSpace(input.LocatNo))//濡傛灉宸ヤ綅涓虹┖ + { + throw Oops.Bah("宸ヤ綅涓嶈兘涓虹┖"); + } + var plcList = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine && s.IsDelete == false).ToListAsync(); + switch (input.Layer) + { + case "1": + modPlc = plcList.FirstOrDefault(m => m.Text == "1灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = ""; + break; + case "2": + modPlc = plcList.FirstOrDefault(m => m.Text == "2灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = "DB1100"; + break; + case "3": + modPlc = plcList.FirstOrDefault(m => m.Text == "3灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = ""; + break; + default: + throw Oops.Bah("妤煎眰淇℃伅閿欒"); + } + + var device = await _wcsDeviceRep.Context.Queryable<WcsDevice>().FirstAsync(s => s.PlcId == modPlc.Id && s.StationNum == input.LocatNo && s.IsDelete == false && s.DeviceType == DeviceTypeEnum.Show); + if (device == null) + { + throw Oops.Bah("褰撳墠妤煎眰鏈煡璇㈠埌璇ュ伐浣嶄俊鎭�"); + } + PLCUtil modUtil = new PLCUtil(modPlc); + WcsDeviceUpInfo data = new WcsDeviceUpInfo(); + data.FuncName = ""; + data.Layer = ""; + data.LocatNo = input.LocatNo; + data.TypeName = ""; + var (result2, value2) = modUtil.GetPlcDBValue(PLCDataTypeEnum.String, DbNum, "4"); + data.PalletNo = value2; + var (result3, value3) = modUtil.GetPlcDBValue(PLCDataTypeEnum.String, DbNum, "14"); + data.TaskNo = value3; + var (result4, value4) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "34"); + data.StartLoction = value4.ToString(); + var (result5, value5) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "36"); + data.EndLoction = value5.ToString(); + + var (result6, value6) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "38"); + data.StartPai = value6.ToString(); + var (result7, value7) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "40"); + data.StartLie = value7.ToString(); + var (result8, value8) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "42"); + data.StartCeng = value8.ToString(); + + + var (result9, value9) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "44"); + data.EndPai = value9.ToString(); + var (result10, value10) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "46"); + data.EndLie = value10.ToString(); + var (result11, value11) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "48"); + data.EndCeng = value11.ToString(); + + modUtil.Close(); + return data; + } + /// <summary> + /// 鎵嬪姩鎿嶄綔PLC淇℃伅 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost] + [ApiDescriptionSettings(Name = "WriteInfo")] + [DisplayName("鎵嬪姩鎿嶄綔Plc")] + public async Task WriteInfo(WcsDeviceUpInfo input) + { + WcsPlc modPlc; + string DbNum = "DB91";// DB鍧� + + if (string.IsNullOrWhiteSpace(input.LocatNo))//濡傛灉宸ヤ綅涓虹┖ + { + throw Oops.Bah("宸ヤ綅涓嶈兘涓虹┖"); + } + var plcList = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine).ToListAsync(); + switch (input.Layer) + { + case "1": + modPlc = plcList.FirstOrDefault(m => m.Text == "1灞傛墭鐩樿緭閫佺嚎"); + //DbNum = ""; + break; + case "2": + modPlc = plcList.FirstOrDefault(m => m.Text == "2灞傛墭鐩樿緭閫佺嚎"); + //DbNum = "DB91"; + break; + case "3": + modPlc = plcList.FirstOrDefault(m => m.Text == "3灞傛墭鐩樿緭閫佺嚎"); + //DbNum = ""; + break; + default: + throw Oops.Bah("妤煎眰淇℃伅閿欒"); + } + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + + var device = await _wcsDeviceRep.Context.Queryable<WcsDevice>().FirstAsync(s => s.PlcId == modPlc.Id && s.StationNum == input.LocatNo && s.DeviceType == DeviceTypeEnum.Show); + if (device == null) + { + throw Oops.Bah("褰撳墠妤煎眰鏈煡璇㈠埌璇ュ伐浣嶄俊鎭�"); + } + PLCUtil modUtil = new PLCUtil(modPlc); + + + // true 锛� 鎵嬪姩妯″紡 false:鑷姩妯″紡 + var (result, value) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.4"); + if (result.IsSucceed) + { + if (input.TypeName != "shoudong" && value.ToString().ToLower() == "false" && input.TypeName != "huifu" && input.TypeName != "UpTask") + { + throw Oops.Bah("褰撳墠涓鸿嚜鍔ㄦā寮忥紝璇峰厛鍒囨崲涓烘墜鍔ㄦā寮�"); + } + } + else + { + throw Oops.Bah("璇诲彇PLC鎵嬭嚜鍔ㄥ�煎け璐�"); + } + + switch (input.TypeName) + { + case "zidong": // 鑷姩 + //modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "48.0", input.LocatNo); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.4", "false"); + break; + case "shoudong": // 鎵嬪姩 + //modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "48.0", input.LocatNo); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.4", "true"); + break; + case "huifu": // 鎶ヨ鎭㈠ + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "47.0", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "47.0", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + + break; + case "1diandong": // 1鐐瑰姩 + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.7", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.7", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "1liandong": // 1鑱斿姩 + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.3", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.3", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "2diandong": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.0", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.0", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "2liandong": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.4", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.4", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "3diandong": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.5", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.5", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "3liandong": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.1", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.1", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "4diandong": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.6", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.6", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "4liandong": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.2", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.2", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "yizaisheng": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.5", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.5", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "yizaijiang": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.6", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "51.6", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "fanzhuansheng": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "59.0", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "59.0", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "fanzhuanjiang": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "59.1", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "59.1", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "UpTask": + var (result1, value2) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.0"); + if (result.IsSucceed) + { + if (value2 == true) + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.0", "false"); + } + else + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.0", "true"); + } + } + else + { + throw Oops.Bah("璇诲彇PLC鍊煎け璐�"); + } + + + break; + default: + break; + } + + modUtil.Close(); + } + + + /// <summary> + /// 鎵嬪姩鍐欏叆PLC浠诲姟淇℃伅 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost] + [ApiDescriptionSettings(Name = "WriteTaskInfo")] + [DisplayName("鍐欏叆Plc浠诲姟淇℃伅")] + public async Task WriteTaskInfo(WcsDeviceUpInfo input) + { + WcsPlc modPlc; + string DbNum = "";// DB鍧� + string TaskDbNum = "";// DB鍧� + + if (string.IsNullOrWhiteSpace(input.LocatNo))//濡傛灉宸ヤ綅涓虹┖ + { + throw Oops.Bah("宸ヤ綅涓嶈兘涓虹┖"); + } + var plcList = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine && s.IsDelete == false).ToListAsync(); + switch (input.Layer) + { + case "1": + modPlc = plcList.FirstOrDefault(m => m.Text == "1灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = ""; + break; + case "2": + modPlc = plcList.FirstOrDefault(m => m.Text == "2灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = "DB91"; + TaskDbNum = "DB1100"; + break; + case "3": + modPlc = plcList.FirstOrDefault(m => m.Text == "3灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌{input.Layer}妤煎眰PLC淇℃伅"); + DbNum = ""; + break; + default: + throw Oops.Bah("妤煎眰淇℃伅閿欒"); + } + + var device = await _wcsDeviceRep.Context.Queryable<WcsDevice>().FirstAsync(s => s.PlcId == modPlc.Id && s.StationNum == input.LocatNo && s.IsDelete == false && s.DeviceType == DeviceTypeEnum.Show); + if (device == null) + { + throw Oops.Bah("褰撳墠妤煎眰鏈煡璇㈠埌璇ュ伐浣嶄俊鎭�"); + } + + PLCUtil modUtil = new PLCUtil(modPlc); + //var (result, value) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.0"); + //if (result.IsSucceed) + //{ + // if (value.ToString().ToLower() != "false") + // { + // throw Oops.Bah("璇峰厛鍒囨崲涓烘洿鏀逛换鍔℃ā寮�"); + // } + //} + //else + //{ + // throw Oops.Bah("璇诲彇PLC鎵嬭嚜鍔ㄥ�煎け璐�"); + //} + //modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, DbNum, "48.0", input.LocatNo); + switch (input.TypeName) + { + case "writeTask": + modUtil.SetPlcDBValue(PLCDataTypeEnum.String, TaskDbNum, "4", input.PalletNo); + modUtil.SetPlcDBValue(PLCDataTypeEnum.String, TaskDbNum, "14", input.TaskNo); + //modUtil.SetPlcDBValue(PLCDataTypeEnum.Int, TaskDbNum, "34", input.StartLoction); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "36.0", input.EndLoction); + + + modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "38", input.StartPai); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "40", input.StartLie); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "42", input.StartCeng); + + + modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "44", input.EndPai); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "46", input.EndLie); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Short, TaskDbNum, "48", input.EndCeng); + + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.3", "true"); + Thread.Sleep(1000); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.3", "false"); + break; + case "writeTaskDelete": + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.2", "true"); + Thread.Sleep(1000); + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "50.2", "false"); + break; + + default: + break; + } + + modUtil.Close(); + } + + + + /// <summary> + /// 鎵嬪姩鍐欏叆PLC鍚仠淇℃伅 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost] + [ApiDescriptionSettings(Name = "WriteStartStop")] + [DisplayName("鍐欏叆PLC鍚仠淇℃伅")] + public async Task WriteStartStop(WcsDeviceStartStop input) + { + WcsPlc modPlc; + string DbNum = "";// DB鍧� + + + var plcList = await _wcsPlcRep.Context.Queryable<WcsPlc>().Where(s => s.Type == PLCTypeEnum.ConveyorLine && s.IsDelete == false).ToListAsync(); + if (input.Layer == "1") + { + modPlc = plcList.FirstOrDefault(m => m.Text == "1灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌1妤煎眰PLC淇℃伅"); + DbNum = ""; + } + else if (input.Layer == "2") + { + modPlc = plcList.FirstOrDefault(m => m.Text == "2灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌2妤煎眰PLC淇℃伅"); + DbNum = "DB91"; + PLCUtil modUtil = new PLCUtil(modPlc); + switch (input.Type) + { + case "TwoPalletStart": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.0", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.0", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "TwoPalletStop": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.1", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.1", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "TwoMaStart": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.0", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.0", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "TwoMaStop": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.1", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.1", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "TwoMaTwoStart": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.2", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.2", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "TwoMaTwoStop": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.3", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "58.3", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "TwoBoxStart": + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.2", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.2", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + case "TwoBoxStop": + + if (input.FuncName == "true") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.3", "true"); + } + else if (input.FuncName == "false") + { + modUtil.SetPlcDBValue(PLCDataTypeEnum.Bit, DbNum, "46.3", "false"); + } + else + { + throw Oops.Bah("浜嬩欢缁撴灉閿欒"); + } + break; + default: + break; + } + modUtil.Close(); + } + else if (input.Layer == "3") + { + modPlc = plcList.FirstOrDefault(m => m.Text == "3灞傛墭鐩樿緭閫佺嚎"); + if (modPlc == null) + throw Oops.Bah($"鏈煡璇㈠埌3妤煎眰PLC淇℃伅"); + DbNum = ""; + } + else + { + throw Oops.Bah("鎿嶄綔绫诲瀷淇℃伅閿欒"); + } + + } + + #endregion /// <summary> /// 鍒嗛〉鏌ヨ璁惧淇℃伅 @@ -269,7 +966,7 @@ (result, var palletNo) = modConn.GetPlcDBValue(modPositionPalletNo.PosType, modDevice.DbNumber, modPositionPalletNo.PlcPos, modPositionPalletNo.StringLength); modDevice.PalletNo = Convert.ToString(palletNo); Console.WriteLine(modDevice.DbNumber + "." + modPositionPalletNo.PlcPos + "----------"); - } + } if (cachePlc.Type == PLCTypeEnum.ConveyorLine || cachePlc.Type == PLCTypeEnum.StackingMachine) { //鏀捐揣鎺� @@ -314,11 +1011,11 @@ (result, var pickStorey) = modConn.GetPlcDBValue(modPositionPickStorey.PosType, modDevice.DbNumber, modPositionPickStorey.PlcPos); modDevice.PickStorey = Convert.ToInt32(pickStorey); } - + if (cachePlc.Type == PLCTypeEnum.StackingMachine) { //璺烘満鐨勮捣濮嬪伐浣嶇敤鍙栬揣鎺掑垪灞� - modDevice.StartLocatNo = $"{modDevice.PickRow.ToString().PadLeft(2,'0')}{modDevice.PickCol.ToString().PadLeft(2, '0')}{modDevice.PickStorey.ToString().PadLeft(2, '0')}"; + modDevice.StartLocatNo = $"{modDevice.PickRow.ToString().PadLeft(2, '0')}{modDevice.PickCol.ToString().PadLeft(2, '0')}{modDevice.PickStorey.ToString().PadLeft(2, '0')}"; //璺烘満鐨勭洰鐨勫伐浣嶇敤鏀捐揣鎺掑垪灞� modDevice.EndLocatNo = $"{modDevice.ReleaseRow.ToString().PadLeft(2, '0')}{modDevice.ReleaseCol.ToString().PadLeft(2, '0')}{modDevice.ReleaseStorey.ToString().PadLeft(2, '0')}"; } @@ -456,7 +1153,7 @@ var modPositionEndLocatNo = listPosition.FirstOrDefault(s => s.Text == "鐩殑宸ヤ綅"); if (modPositionEndLocatNo != null) result = modUtil.SetPlcDBValue(modPositionEndLocatNo.PosType, modDbDevice.DbNumber, modPositionEndLocatNo.PlcPos, modDevice.EndLocatNo.ToString()); - } + } } //鎵樼洏鐮� if (modDevice.PalletNo != null) @@ -536,7 +1233,7 @@ public async Task<dynamic> WcsPackPlcList() { return await _wcsDeviceRep.Context.Queryable<WcsPlc>() - .Where(w => w.Type == PLCTypeEnum.RobotPalletizer || w.Type == PLCTypeEnum.StackingRobot) + .Where(w => w.Type == PLCTypeEnum.RobotPalletizer /*|| w.Type == PLCTypeEnum.StackingRobot*/) .OrderByDescending(o => o.Type) .Select(u => new { @@ -581,7 +1278,7 @@ PZNo = task.PZNo, Qty = task.Qty, - PlcId=device.PlcId, + PlcId = device.PlcId, Type = plc.Type }) .ToListAsync(); @@ -593,7 +1290,62 @@ if (modUtil.Connected) { connStatus = true; - } + } + foreach (var item in list) + { + item.PlcStatus = connStatus; + } + return list; + } + /// <summary> + /// 鑾峰彇璁惧瀵瑰簲宸ヤ綅鍒楄〃 + /// </summary> + /// <param name="entry"></param> + /// <returns></returns> + [HttpGet] + [ApiDescriptionSettings(Name = "WcsStackingRobotList")] + [DisplayName("鑾峰彇璁惧瀵瑰簲宸ヤ綅鍒楄〃")] + public async Task<List<WcsDeviceTaskOrderDto>> WcsStackingRobotList() + { + //var list = await _wcsDeviceRep.AsQueryable() + // .LeftJoin<WcsPlc>((a, b) => a.PlcId == b.Id) + // .Where((a, b) => a.DeviceType == DeviceTypeEnum.Business) + // .Select<WcsDeviceOutput>((a, b) => new WcsDeviceOutput() { Type = b.Type }, true) + // .ToListAsync(); + + + var list = await _wcsDeviceRep.Context.Queryable<WcsCheckTask>() + .LeftJoin<WcsDevice>((task, device) => device.StationNum == task.Port) + .InnerJoin<WcsPlc>((task, device, plc) => device.PlcId == plc.Id) + .Where((task, device, plc) => task.Id <= 3) + .OrderBy((task, device, plc) => device.CreateTime) + .Select((task, device, plc) => new WcsDeviceTaskOrderDto() + { + Id = device.Id, + TaskId = task.Id, + Text = task.Id.ToString() + "鍙峰嚭搴撳垎鎷g嚎", + TaskNo = task.TaskNo, + OrderNo = task.OrderNo, + LotNo = task.LotNo, + SkuNo = task.SkuNo, + SkuName = task.SkuName, + LineNo = task.LineNo, + Status = task.Status, + PZNo = task.PZNo, + Qty = task.Qty, + PlcId = device.PlcId, + Type = plc.Type + }) + .ToListAsync(); + + bool connStatus = false; + //鑾峰彇璁惧鐨勭姸鎬� + var modPlc = await _wcsDeviceRep.Context.Queryable<WcsPlc>().FirstAsync(s => s.Id == list[0].PlcId); + PLCUtil modUtil = new PLCUtil(modPlc); + if (modUtil.Connected) + { + connStatus = true; + } foreach (var item in list) { item.PlcStatus = connStatus; -- Gitblit v1.8.0