| | |
| | | |
| | | 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; |
| | | using static SKIT.FlurlHttpClient.Wechat.Api.Models.CgibinComponentApiGetAuthorizerInfoResponse.Types.Authorizer.Types; |
| | | |
| | | namespace WCS.Application; |
| | | |
| | |
| | | [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 = "DB1100"; |
| | | 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 = "DB1100"; |
| | | 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(); |
| | | |
| | | var (result12, value12) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Byte, DbNum, "50"); |
| | | data.ChanMo = value12.ToString(); |
| | | var (result13, value13) = modUtil.GetPlcDBValue(PLCDataTypeEnum.Byte, DbNum, "51"); |
| | | data.ChaiMo = value13.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> |
| | | /// 分页查询设备信息 |
| | |
| | | var query = _wcsDeviceRep.AsQueryable() |
| | | .WhereIF(!string.IsNullOrEmpty(input.SearchKey), u => |
| | | u.Text.Contains(input.SearchKey) |
| | | || u.StationNum.Contains(input.SearchKey) |
| | | ) |
| | | .WhereIF(input.PlcId > 0, u => u.PlcId == input.PlcId) |
| | | .WhereIF(!string.IsNullOrWhiteSpace(input.StationNum), u => u.StationNum.Contains(input.StationNum.Trim())) |
| | | .WhereIF(!string.IsNullOrWhiteSpace(input.Text), u => u.Text.Contains(input.Text.Trim())) |
| | | .WhereIF(input.DeviceType.HasValue, u => u.DeviceType == input.DeviceType) |
| | | //处理外键和TreeSelector相关字段的连接 |
| | | .LeftJoin<WcsPlc>((u, plcid) => u.PlcId == plcid.Id) |
| | | .Select((u, plcid) => new WcsDeviceOutput |
| | |
| | | //获取跺机的状态 |
| | | foreach (var modDevice in list) |
| | | { |
| | | if (_sysCacheService.ExistKey("PLCCONN" + modDevice.PlcId)) |
| | | if (_sysCacheService.ExistKey("PLCCONN:" + modDevice.PlcId)) |
| | | { |
| | | var cachePlc = _sysCacheService.Get<WcsPlc>("PLCCONN" + modDevice.PlcId); |
| | | var cachePlc = _sysCacheService.Get<WcsPlc>("PLCCONN:" + modDevice.PlcId); |
| | | modDevice.Status = cachePlc.IsConn; |
| | | if (modDevice.Status) |
| | | { |
| | |
| | | modDevice.Wcs = Convert.ToString(wcs); |
| | | //任务号 |
| | | var modPositionTask = listPosition.FirstOrDefault(s => s.Text == "任务号"); |
| | | (result, var taskNo) = modConn.GetPlcDBValue(modPositionTask.PosType, modDevice.DbNumber, modPositionTask.PlcPos, modPositionTask.StringLength); |
| | | modDevice.TaskNo = Convert.ToString(taskNo); |
| | | if (modPositionTask != null) |
| | | { |
| | | (result, var taskNo) = modConn.GetPlcDBValue(modPositionTask.PosType, modDevice.DbNumber, modPositionTask.PlcPos, modPositionTask.StringLength); |
| | | modDevice.TaskNo = Convert.ToString(taskNo); |
| | | } |
| | | //任务类型 |
| | | var modPositionTaskType = listPosition.FirstOrDefault(s => s.Text == "任务类型"); |
| | | (result, var taskType) = modConn.GetPlcDBValue(modPositionTaskType.PosType, modDevice.DbNumber, modPositionTaskType.PlcPos); |
| | | modDevice.TaskType = (TaskTypeEnum)Convert.ToInt32(taskType); |
| | | if (modPositionTaskType != null) |
| | | { |
| | | (result, var taskType) = modConn.GetPlcDBValue(modPositionTaskType.PosType, modDevice.DbNumber, modPositionTaskType.PlcPos); |
| | | modDevice.TaskType = (TaskTypeEnum)Convert.ToInt32(taskType); |
| | | } |
| | | //起始工位 |
| | | var modPositionStartLocatNo = listPosition.FirstOrDefault(s => s.Text == "起始工位"); |
| | | (result, var startLocatNo) = modConn.GetPlcDBValue(modPositionStartLocatNo.PosType, modDevice.DbNumber, modPositionStartLocatNo.PlcPos); |
| | | modDevice.StartLocatNo = Convert.ToString(startLocatNo); |
| | | if (modPositionStartLocatNo != null) |
| | | { |
| | | (result, var startLocatNo) = modConn.GetPlcDBValue(modPositionStartLocatNo.PosType, modDevice.DbNumber, modPositionStartLocatNo.PlcPos); |
| | | modDevice.StartLocatNo = Convert.ToString(startLocatNo); |
| | | } |
| | | //目的工位 |
| | | var modPositionEndLocatNo = listPosition.FirstOrDefault(s => s.Text == "目的工位"); |
| | | (result, var endLocatNo) = modConn.GetPlcDBValue(modPositionEndLocatNo.PosType, modDevice.DbNumber, modPositionEndLocatNo.PlcPos); |
| | | modDevice.EndLocatNo = Convert.ToString(endLocatNo); |
| | | if (modPositionEndLocatNo != null) |
| | | { |
| | | (result, var endLocatNo) = modConn.GetPlcDBValue(modPositionEndLocatNo.PosType, modDevice.DbNumber, modPositionEndLocatNo.PlcPos); |
| | | modDevice.EndLocatNo = Convert.ToString(endLocatNo); |
| | | } |
| | | //托盘码 |
| | | var modPositionPalletNo = listPosition.FirstOrDefault(s => s.Text == "托盘码"); |
| | | (result, var palletNo) = modConn.GetPlcDBValue(modPositionPalletNo.PosType, modDevice.DbNumber, modPositionPalletNo.PlcPos, modPositionPalletNo.StringLength); |
| | | modDevice.PalletNo = Convert.ToString(palletNo); |
| | | if (cachePlc.Type == PLCTypeEnum.ConveyorLine) |
| | | if (modPositionPalletNo != null) |
| | | { |
| | | (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) |
| | | { |
| | | //放货排 |
| | | var modPositionReleaseRow = listPosition.FirstOrDefault(s => s.Text == "放货排"); |
| | | (result, var releaseRow) = modConn.GetPlcDBValue(modPositionReleaseRow.PosType, modDevice.DbNumber, modPositionReleaseRow.PlcPos); |
| | | modDevice.ReleaseRow = Convert.ToInt32(releaseRow); |
| | | if (modPositionReleaseRow != null) |
| | | { |
| | | (result, var releaseRow) = modConn.GetPlcDBValue(modPositionReleaseRow.PosType, modDevice.DbNumber, modPositionReleaseRow.PlcPos); |
| | | modDevice.ReleaseRow = Convert.ToInt32(releaseRow); |
| | | } |
| | | //放货列 |
| | | var modPositionReleaseCol = listPosition.FirstOrDefault(s => s.Text == "放货列"); |
| | | (result, var releaseCol) = modConn.GetPlcDBValue(modPositionReleaseCol.PosType, modDevice.DbNumber, modPositionReleaseCol.PlcPos); |
| | | modDevice.ReleaseCol = Convert.ToInt32(releaseCol); |
| | | if (modPositionReleaseCol != null) |
| | | { |
| | | (result, var releaseCol) = modConn.GetPlcDBValue(modPositionReleaseCol.PosType, modDevice.DbNumber, modPositionReleaseCol.PlcPos); |
| | | modDevice.ReleaseCol = Convert.ToInt32(releaseCol); |
| | | } |
| | | //放货层 |
| | | var modPositionReleaseStorey = listPosition.FirstOrDefault(s => s.Text == "放货层"); |
| | | (result, var releaseStorey) = modConn.GetPlcDBValue(modPositionReleaseStorey.PosType, modDevice.DbNumber, modPositionReleaseStorey.PlcPos); |
| | | modDevice.ReleaseStorey = Convert.ToInt32(releaseStorey); |
| | | if (modPositionReleaseStorey != null) |
| | | { |
| | | (result, var releaseStorey) = modConn.GetPlcDBValue(modPositionReleaseStorey.PosType, modDevice.DbNumber, modPositionReleaseStorey.PlcPos); |
| | | modDevice.ReleaseStorey = Convert.ToInt32(releaseStorey); |
| | | } |
| | | //取货排 |
| | | var modPositionPickRow = listPosition.FirstOrDefault(s => s.Text == "取货排"); |
| | | (result, var pickRow) = modConn.GetPlcDBValue(modPositionPickRow.PosType, modDevice.DbNumber, modPositionPickRow.PlcPos); |
| | | modDevice.PickRow = Convert.ToInt32(pickRow); |
| | | if (modPositionPickRow != null) |
| | | { |
| | | (result, var pickRow) = modConn.GetPlcDBValue(modPositionPickRow.PosType, modDevice.DbNumber, modPositionPickRow.PlcPos); |
| | | modDevice.PickRow = Convert.ToInt32(pickRow); |
| | | } |
| | | //取货列 |
| | | var modPositionPickCol = listPosition.FirstOrDefault(s => s.Text == "取货列"); |
| | | (result, var pickCol) = modConn.GetPlcDBValue(modPositionPickCol.PosType, modDevice.DbNumber, modPositionPickCol.PlcPos); |
| | | modDevice.PickCol = Convert.ToInt32(pickCol); |
| | | if (modPositionPickCol != null) |
| | | { |
| | | (result, var pickCol) = modConn.GetPlcDBValue(modPositionPickCol.PosType, modDevice.DbNumber, modPositionPickCol.PlcPos); |
| | | modDevice.PickCol = Convert.ToInt32(pickCol); |
| | | } |
| | | //取货层 |
| | | var modPositionPickStorey = listPosition.FirstOrDefault(s => s.Text == "取货层"); |
| | | (result, var pickStorey) = modConn.GetPlcDBValue(modPositionPickStorey.PosType, modDevice.DbNumber, modPositionPickStorey.PlcPos); |
| | | modDevice.PickStorey = Convert.ToInt32(pickStorey); |
| | | if (modPositionPickStorey != null) |
| | | { |
| | | (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.EndLocatNo = $"{modDevice.ReleaseRow.ToString().PadLeft(2, '0')}{modDevice.ReleaseCol.ToString().PadLeft(2, '0')}{modDevice.ReleaseStorey.ToString().PadLeft(2, '0')}"; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception) |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | Console.WriteLine(ex.Message); |
| | | } |
| | | } |
| | | } |
| | |
| | | var modPlc = await _wcsDeviceRep.Context.Queryable<WcsPlc>().FirstAsync(s => s.Id == modDevice.PlcId); |
| | | if (modPlc == null) |
| | | throw Oops.Bah("找不到PLC信息"); |
| | | var modDbDevice = await _wcsDeviceRep.AsQueryable().FirstAsync(s => s.Id == modDevice.Id); |
| | | PLCUtil modUtil = new PLCUtil(modPlc); |
| | | var listPosition = await _wcsDeviceRep.Context.Queryable<WcsPosition>().Where(s => s.DeviceId == modDevice.Id).ToListAsync(); |
| | | //(var result, var plc) = modConn.GetPlcDBValue(modDevice.PosType, modDevice.DbNumber, modDevice.PlcPos); |
| | | //modDevice.Plc = Convert.ToString(plc); |
| | | var result = new IoTClient.Result(); |
| | | //任务号 |
| | | var modPositionTask = listPosition.FirstOrDefault(s => s.Text == "任务号"); |
| | | if (modPositionTask != null) |
| | | modUtil.SetPlcDBValue(modPositionTask.PosType, modPositionTask.PlcPos, modDevice.TaskNo); |
| | | if (modDevice.TaskNo != null) |
| | | { |
| | | var modPositionTask = listPosition.FirstOrDefault(s => s.Text == "任务号"); |
| | | if (modPositionTask != null) |
| | | result = modUtil.SetPlcDBValue(modPositionTask.PosType, modDbDevice.DbNumber, modPositionTask.PlcPos, modDevice.TaskNo); |
| | | } |
| | | //任务类型 |
| | | var modPositionTaskType = listPosition.FirstOrDefault(s => s.Text == "任务类型"); |
| | | if (modPositionTaskType != null) |
| | | modUtil.SetPlcDBValue(modPositionTaskType.PosType, modPositionTaskType.PlcPos, modDevice.TaskType.ToString()); |
| | | if (modDevice.TaskType != null) |
| | | { |
| | | var modPositionTaskType = listPosition.FirstOrDefault(s => s.Text == "任务类型"); |
| | | if (modPositionTaskType != null) |
| | | result = modUtil.SetPlcDBValue(modPositionTaskType.PosType, modDbDevice.DbNumber, modPositionTaskType.PlcPos, ((int)modDevice.TaskType).ToString()); |
| | | } |
| | | //起始工位 |
| | | var modPositionStartLocatNo = listPosition.FirstOrDefault(s => s.Text == "起始工位"); |
| | | if (modPositionStartLocatNo != null) |
| | | modUtil.SetPlcDBValue(modPositionStartLocatNo.PosType, modPositionStartLocatNo.PlcPos, modDevice.StartLocatNo.ToString()); |
| | | if (modDevice.StartLocatNo != null) |
| | | { |
| | | if (modPlc.Type == PLCTypeEnum.StackingMachine) |
| | | { |
| | | if (modDevice.StartLocatNo.Length != 6) |
| | | { |
| | | throw Oops.Bah("起始工位格式输入错误,请输入排列层,例:010203!"); |
| | | } |
| | | modDevice.PickRow = Convert.ToInt32(modDevice.StartLocatNo.Substring(0, 2)); |
| | | modDevice.PickCol = Convert.ToInt32(modDevice.StartLocatNo.Substring(2, 2)); |
| | | modDevice.PickStorey = Convert.ToInt32(modDevice.StartLocatNo.Substring(4, 2)); |
| | | |
| | | //取货排 |
| | | if (modDevice.PickRow != null) |
| | | { |
| | | var modPositionPickRow = listPosition.FirstOrDefault(s => s.Text == "取货排"); |
| | | if (modPositionPickRow != null) |
| | | modUtil.SetPlcDBValue(modPositionPickRow.PosType, modDbDevice.DbNumber, modPositionPickRow.PlcPos, modDevice.PickRow.ToString()); |
| | | } |
| | | //取货列 |
| | | if (modDevice.PickCol != null) |
| | | { |
| | | var modPositionPickCol = listPosition.FirstOrDefault(s => s.Text == "取货列"); |
| | | if (modPositionPickCol != null) |
| | | modUtil.SetPlcDBValue(modPositionPickCol.PosType, modDbDevice.DbNumber, modPositionPickCol.PlcPos, modDevice.PickCol.ToString()); |
| | | } |
| | | //取货层 |
| | | if (modDevice.PickStorey != null) |
| | | { |
| | | var modPositionPickStorey = listPosition.FirstOrDefault(s => s.Text == "取货层"); |
| | | if (modPositionPickStorey != null) |
| | | modUtil.SetPlcDBValue(modPositionPickStorey.PosType, modDbDevice.DbNumber, modPositionPickStorey.PlcPos, modDevice.PickStorey.ToString()); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var modPositionStartLocatNo = listPosition.FirstOrDefault(s => s.Text == "起始工位"); |
| | | if (modPositionStartLocatNo != null) |
| | | result = modUtil.SetPlcDBValue(modPositionStartLocatNo.PosType, modDbDevice.DbNumber, modPositionStartLocatNo.PlcPos, modDevice.StartLocatNo.ToString()); |
| | | } |
| | | } |
| | | //目的工位 |
| | | var modPositionEndLocatNo = listPosition.FirstOrDefault(s => s.Text == "目的工位"); |
| | | if (modPositionEndLocatNo != null) |
| | | modUtil.SetPlcDBValue(modPositionEndLocatNo.PosType, modPositionEndLocatNo.PlcPos, modDevice.EndLocatNo.ToString()); |
| | | if (modDevice.EndLocatNo != null) |
| | | { |
| | | if (modPlc.Type == PLCTypeEnum.StackingMachine) |
| | | { |
| | | if (modDevice.EndLocatNo.Length != 6) |
| | | { |
| | | throw Oops.Bah("目的工位格式输入错误,请输入排列层,例:010203!"); |
| | | } |
| | | modDevice.ReleaseRow = Convert.ToInt32(modDevice.EndLocatNo.Substring(0, 2)); |
| | | modDevice.ReleaseCol = Convert.ToInt32(modDevice.EndLocatNo.Substring(2, 2)); |
| | | modDevice.ReleaseStorey = Convert.ToInt32(modDevice.EndLocatNo.Substring(4, 2)); |
| | | |
| | | //放货排 |
| | | if (modDevice.ReleaseRow != null) |
| | | { |
| | | var modPositionReleaseRow = listPosition.FirstOrDefault(s => s.Text == "放货排"); |
| | | if (modPositionReleaseRow != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseRow.PosType, modDbDevice.DbNumber, modPositionReleaseRow.PlcPos, modDevice.ReleaseRow.ToString()); |
| | | } |
| | | //放货列 |
| | | if (modDevice.ReleaseCol != null) |
| | | { |
| | | var modPositionReleaseCol = listPosition.FirstOrDefault(s => s.Text == "放货列"); |
| | | if (modPositionReleaseCol != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseCol.PosType, modDbDevice.DbNumber, modPositionReleaseCol.PlcPos, modDevice.ReleaseCol.ToString()); |
| | | } |
| | | //放货层 |
| | | if (modDevice.ReleaseStorey != null) |
| | | { |
| | | var modPositionReleaseStorey = listPosition.FirstOrDefault(s => s.Text == "放货层"); |
| | | if (modPositionReleaseStorey != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseStorey.PosType, modDbDevice.DbNumber, modPositionReleaseStorey.PlcPos, modDevice.ReleaseStorey.ToString()); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var modPositionEndLocatNo = listPosition.FirstOrDefault(s => s.Text == "目的工位"); |
| | | if (modPositionEndLocatNo != null) |
| | | result = modUtil.SetPlcDBValue(modPositionEndLocatNo.PosType, modDbDevice.DbNumber, modPositionEndLocatNo.PlcPos, modDevice.EndLocatNo.ToString()); |
| | | } |
| | | } |
| | | //托盘码 |
| | | var modPositionPalletNo = listPosition.FirstOrDefault(s => s.Text == "托盘码"); |
| | | if (modPositionPalletNo != null) |
| | | modUtil.SetPlcDBValue(modPositionPalletNo.PosType, modPositionPalletNo.PlcPos, modDevice.PalletNo.ToString()); |
| | | if (modDevice.PalletNo != null) |
| | | { |
| | | var modPositionPalletNo = listPosition.FirstOrDefault(s => s.Text == "托盘码"); |
| | | if (modPositionPalletNo != null) |
| | | result = modUtil.SetPlcDBValue(modPositionPalletNo.PosType, modDbDevice.DbNumber, modPositionPalletNo.PlcPos, modDevice.PalletNo.ToString()); |
| | | } |
| | | if (modDevice.Plc != null) |
| | | { |
| | | var modPositionPLC = listPosition.FirstOrDefault(s => s.Text == "PLC流程字"); |
| | | if (modPositionPLC != null) |
| | | result = modUtil.SetPlcDBValue(modPositionPLC.PosType, modDbDevice.DbNumber, modPositionPLC.PlcPos, modDevice.Plc); |
| | | } |
| | | if (modDevice.Wcs != null) |
| | | { |
| | | var modPositionWCS = listPosition.FirstOrDefault(s => s.Text == "WCS流程字"); |
| | | if (modPositionWCS != null) |
| | | result = modUtil.SetPlcDBValue(modPositionWCS.PosType, modDbDevice.DbNumber, modPositionWCS.PlcPos, modDevice.Wcs); |
| | | } |
| | | if (modPlc.Type == PLCTypeEnum.ConveyorLine) |
| | | { |
| | | //放货排 |
| | | var modPositionReleaseRow = listPosition.FirstOrDefault(s => s.Text == "放货排"); |
| | | if (modPositionReleaseRow != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseRow.PosType, modPositionReleaseRow.PlcPos, modDevice.ReleaseRow.ToString()); |
| | | if (modDevice.ReleaseRow != null) |
| | | { |
| | | var modPositionReleaseRow = listPosition.FirstOrDefault(s => s.Text == "放货排"); |
| | | if (modPositionReleaseRow != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseRow.PosType, modDbDevice.DbNumber, modPositionReleaseRow.PlcPos, modDevice.ReleaseRow.ToString()); |
| | | } |
| | | //放货列 |
| | | var modPositionReleaseCol = listPosition.FirstOrDefault(s => s.Text == "放货列"); |
| | | if (modPositionReleaseRow != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseCol.PosType, modPositionReleaseCol.PlcPos, modDevice.ReleaseCol.ToString()); |
| | | if (modDevice.ReleaseCol != null) |
| | | { |
| | | var modPositionReleaseCol = listPosition.FirstOrDefault(s => s.Text == "放货列"); |
| | | if (modPositionReleaseCol != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseCol.PosType, modDbDevice.DbNumber, modPositionReleaseCol.PlcPos, modDevice.ReleaseCol.ToString()); |
| | | } |
| | | //放货层 |
| | | var modPositionReleaseStorey = listPosition.FirstOrDefault(s => s.Text == "放货层"); |
| | | if (modPositionReleaseStorey != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseStorey.PosType, modPositionReleaseStorey.PlcPos, modDevice.ReleaseStorey.ToString()); |
| | | if (modDevice.ReleaseStorey != null) |
| | | { |
| | | var modPositionReleaseStorey = listPosition.FirstOrDefault(s => s.Text == "放货层"); |
| | | if (modPositionReleaseStorey != null) |
| | | modUtil.SetPlcDBValue(modPositionReleaseStorey.PosType, modDbDevice.DbNumber, modPositionReleaseStorey.PlcPos, modDevice.ReleaseStorey.ToString()); |
| | | } |
| | | //取货排 |
| | | var modPositionPickRow = listPosition.FirstOrDefault(s => s.Text == "取货排"); |
| | | if (modPositionPickRow != null) |
| | | modUtil.SetPlcDBValue(modPositionPickRow.PosType, modPositionPickRow.PlcPos, modDevice.PickRow.ToString()); |
| | | if (modDevice.PickRow != null) |
| | | { |
| | | var modPositionPickRow = listPosition.FirstOrDefault(s => s.Text == "取货排"); |
| | | if (modPositionPickRow != null) |
| | | modUtil.SetPlcDBValue(modPositionPickRow.PosType, modDbDevice.DbNumber, modPositionPickRow.PlcPos, modDevice.PickRow.ToString()); |
| | | } |
| | | //取货列 |
| | | var modPositionPickCol = listPosition.FirstOrDefault(s => s.Text == "取货列"); |
| | | if (modPositionPickCol != null) |
| | | modUtil.SetPlcDBValue(modPositionPickCol.PosType, modPositionPickCol.PlcPos, modDevice.PickCol.ToString()); |
| | | if (modDevice.PickCol != null) |
| | | { |
| | | var modPositionPickCol = listPosition.FirstOrDefault(s => s.Text == "取货列"); |
| | | if (modPositionPickCol != null) |
| | | modUtil.SetPlcDBValue(modPositionPickCol.PosType, modDbDevice.DbNumber, modPositionPickCol.PlcPos, modDevice.PickCol.ToString()); |
| | | } |
| | | //取货层 |
| | | var modPositionPickStorey = listPosition.FirstOrDefault(s => s.Text == "取货层"); |
| | | if (modPositionPickStorey != null) |
| | | modUtil.SetPlcDBValue(modPositionPickStorey.PosType, modPositionPickStorey.PlcPos, modDevice.PickStorey.ToString()); |
| | | |
| | | if (modDevice.PickStorey != null) |
| | | { |
| | | var modPositionPickStorey = listPosition.FirstOrDefault(s => s.Text == "取货层"); |
| | | if (modPositionPickStorey != null) |
| | | modUtil.SetPlcDBValue(modPositionPickStorey.PosType, modDbDevice.DbNumber, modPositionPickStorey.PlcPos, modDevice.PickStorey.ToString()); |
| | | } |
| | | } |
| | | modUtil.Close(); |
| | | } |
| | |
| | | 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 |
| | | { |
| | |
| | | [DisplayName("获取设备对应工位列表")] |
| | | public async Task<List<WcsDeviceTaskOrderDto>> WcsPackStationPlcList([FromQuery] WcsDeviceBaseInput entry) |
| | | { |
| | | return await _wcsDeviceRep.Context.Queryable<WcsDevice>() |
| | | .LeftJoin<WcsCheckTask>((device, task) => device.StationNum == task.Port) |
| | | .Where((device, task) => device.PlcId == entry.PlcId) |
| | | .OrderBy((device, task) => device.CreateTime) |
| | | .Select((device, task) => new WcsDeviceTaskOrderDto() |
| | | //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<WcsDevice>() |
| | | .InnerJoin<WcsPlc>((device, plc) => device.PlcId == plc.Id) |
| | | .LeftJoin<WcsCheckTask>((device, plc, task) => device.StationNum == task.Port) |
| | | .Where((device, plc, task) => device.PlcId == entry.PlcId) |
| | | .OrderBy((device, plc, task) => device.CreateTime) |
| | | .Select((device, plc, task) => new WcsDeviceTaskOrderDto() |
| | | { |
| | | Id = device.Id, |
| | | Text = device.Text, |
| | | TaskNo = task.TaskNo, |
| | | OrderNo = task.OrderNo, |
| | | LotNo = task.LotNo, |
| | | SkuNo = task.SkuNo, |
| | | SkuName = task.SkuName, |
| | | LineNo = task.LineNo, |
| | | Status = task.Status, |
| | | LineNO = task.LineNO, |
| | | Qty = task.Qty |
| | | 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; |
| | | } |
| | | 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() + "号出库分拣线", |
| | | 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; |
| | | } |
| | | return list; |
| | | } |
| | | #endregion |
| | | } |