diff --git a/Sln.Wcs.HikRoBotServer/appsettings.json b/Sln.Wcs.HikRoBotServer/appsettings.json index aa175c1..6af4e2d 100644 --- a/Sln.Wcs.HikRoBotServer/appsettings.json +++ b/Sln.Wcs.HikRoBotServer/appsettings.json @@ -10,9 +10,9 @@ "apollo": { "AppId": "SlnWcs", "Env": "DEV", - "MetaServer": "http://119.45.202.115:4320", //配置网址 4310 + "MetaServer": "http://172.16.12.20:7320", //配置网址 4310 "ConfigServer": [ - "http://119.45.202.115:4320" + "http://172.16.12.20:7320" ] } } \ No newline at end of file diff --git a/Sln.Wcs.HoistAdapter/Service/Impl/HoistService.cs b/Sln.Wcs.HoistAdapter/Service/Impl/HoistService.cs index f316f7f..a1e176d 100644 --- a/Sln.Wcs.HoistAdapter/Service/Impl/HoistService.cs +++ b/Sln.Wcs.HoistAdapter/Service/Impl/HoistService.cs @@ -69,6 +69,7 @@ public class HoistService:IHoistService { hoistCode = setHoistActionDto.hoistCode, action = (HoistSdk.Enum.ControlAction)setHoistActionDto.action, + deviceSerialNo = setHoistActionDto.deviceSerialNo, }; var resp = this.hoistSdk.SetHoistAction(data); diff --git a/Sln.Wcs.HoistDispatcher/HoistDispatchHub.cs b/Sln.Wcs.HoistDispatcher/HoistDispatchHub.cs index f9796ab..22970b9 100644 --- a/Sln.Wcs.HoistDispatcher/HoistDispatchHub.cs +++ b/Sln.Wcs.HoistDispatcher/HoistDispatchHub.cs @@ -79,7 +79,7 @@ public class HoistDispatchHub { hoistCode = deviceInfo.hostCode, deviceSerialNo = deviceInfo.deviceSerialNo, - action = ControlAction.Start + action = ControlAction.Start, }); if (res.code == HoistStatusEnum.成功) @@ -146,18 +146,21 @@ public class HoistDispatchHub { while (true) { - RefreshDeviceParams(hostCode, out List deviceInfos); + lock (string.Empty) + { + RefreshDeviceParams(hostCode, out List deviceInfos); - var freeHoist = deviceInfos?.FirstOrDefault(info => - info.deviceParams.Any(item => - item.paramName.Contains("提升机反馈任务状态") && item.paramValue == 0 - ) - ); + var freeHoist = deviceInfos?.FirstOrDefault(info => + info.deviceParams.Any(item => + item.paramName.Contains("提升机反馈任务状态") && item.paramValue == 0 + ) + ); - if (freeHoist != null) - return freeHoist; + if (freeHoist != null) + return freeHoist; - await Task.Delay(1000); + Thread.Sleep(1000); + } } } diff --git a/Sln.Wcs.HoistSdk/Config/HoistConfig.cs b/Sln.Wcs.HoistSdk/Config/HoistConfig.cs index 2866f7b..f877005 100644 --- a/Sln.Wcs.HoistSdk/Config/HoistConfig.cs +++ b/Sln.Wcs.HoistSdk/Config/HoistConfig.cs @@ -40,18 +40,11 @@ public class HoistConfig /// public HoistConfig(IConfiguration configuration) { - if (string.IsNullOrEmpty(configuration["提升机控制地址"])) - { - throw new Exception("提升机控制地址 配置不正确,请检查Apollo配置."); - } - if (string.IsNullOrEmpty(configuration["PLC参数"])) { throw new Exception("PLC参数 配置不正确,请检查Apollo配置."); } - hoist_control_addr = configuration["提升机控制地址"]; - hoist_plc_param = configuration["PLC参数"]; } } \ No newline at end of file diff --git a/Sln.Wcs.HoistSdk/HoistSdk.cs b/Sln.Wcs.HoistSdk/HoistSdk.cs index 8f3fb65..4849ec0 100644 --- a/Sln.Wcs.HoistSdk/HoistSdk.cs +++ b/Sln.Wcs.HoistSdk/HoistSdk.cs @@ -138,20 +138,31 @@ public class HoistSdk:IHoistSdk if (item.hostCode == hoistStatusDto.hoistCode) { - var plc = _plcs.Where(x => x.ConfigKey.Equals(item.hostCode)).FirstOrDefault(); + string plcKey = string.Empty; + var plc = _plcs.Where(x => x.ConfigKey.Equals(hoistStatusDto.hoistCode)).FirstOrDefault(); if (plc == null) { + + foreach (var plcItem in _plcs) + { + if (plcItem.ConfigKey.Equals(item.hostCode)) + { + plcItem.ConfigKey = plcItem.ConfigKey + "相同"; + } + plcKey += plcItem.ConfigKey + ","; + } + result.code = "99"; - result.message = $"未找到PLC: {item.hostCode}"; + result.message = $"未找到PLC: {item.hostCode};现有PLC链接:{plcKey}"; result.hoistCode = hoistStatusDto.hoistCode; return result; } foreach (var param in item.deviceParams) { - int value = plc.readInt16ByAddress(param.paramAddress); + int value = plc.readInt16ByAddress(Convert.ToString(param.paramAddress)); - param.paramValue = param.objId; + param.paramValue = value; } } diff --git a/Sln.Wcs.HoistServer/Program.cs b/Sln.Wcs.HoistServer/Program.cs index 627f599..22f074b 100644 --- a/Sln.Wcs.HoistServer/Program.cs +++ b/Sln.Wcs.HoistServer/Program.cs @@ -94,14 +94,17 @@ var api = app.MapGroup("/api"); api.MapPost("/hoist/receive-pallet", (ReceivePalletRequest req, IBaseDeviceInfoService devSvc) => { var device = devSvc.Query(x => x.deviceType == 2 && x.isFlag == 1) - .FirstOrDefault(d => d.hostCode == req.HostCode); + .FirstOrDefault(d => d.hostCode == req.HostCode && d.deviceSerialNo == req.SerialNo); if (device == null) return Results.Ok(new { success = false, msg = "设备不存在" }); var detail = new LiveTaskDetail { - taskCode = req.TaskCode, palletBarcode = req.PalletBarcode, - startPoint = req.StartPoint, endPoint = req.EndPoint, - deviceType = 2, taskStatus = 1 + taskCode = req.TaskCode, + palletBarcode = req.PalletBarcode, + startPoint = req.StartPoint, + endPoint = req.EndPoint, + deviceType = 2, + taskStatus = 1 }; hub.ReceivePallet(detail, device); return Results.Ok(new { success = true }); @@ -111,9 +114,9 @@ api.MapPost("/hoist/receive-pallet", (ReceivePalletRequest req, IBaseDeviceInfoS api.MapPost("/hoist/task-run", (TaskRunRequest req, IBaseDeviceInfoService devSvc) => { var device = devSvc.Query(x => x.deviceType == 2 && x.isFlag == 1) - .FirstOrDefault(d => d.hostCode == req.HostCode); + .FirstOrDefault(d => d.hostCode == req.HostCode && d.deviceSerialNo == req.SerialNo); if (device == null) return Results.Ok(new { success = false, msg = "设备不存在" }); - device.deviceSerialNo = req.SerialNo; + hub.TaskRun(device); return Results.Ok(new { success = true }); }); @@ -122,13 +125,16 @@ api.MapPost("/hoist/task-run", (TaskRunRequest req, IBaseDeviceInfoService devSv api.MapPost("/task/dispatch", (TaskDispatchRequest req, IBaseDeviceInfoService devSvc) => { var device = devSvc.Query(x => x.deviceType == 2 && x.isFlag == 1) - .FirstOrDefault(d => d.hostCode == req.HostCode); + .FirstOrDefault(d => d.hostCode == req.HostCode && d.deviceSerialNo == req.SerialNo); if (device == null) return Results.Ok(new { success = false, msg = "设备不存在" }); var detail = new LiveTaskDetail { - taskCode = req.TaskCode, startPoint = req.StartPoint, endPoint = req.EndPoint, - deviceType = 2, taskStatus = 1 + taskCode = req.TaskCode, + startPoint = req.StartPoint, + endPoint = req.EndPoint, + deviceType = 2, + taskStatus = 1 }; hub.TaskDispatch(device, detail); return Results.Ok(new { success = true }); diff --git a/Sln.Wcs.HoistServer/appsettings.json b/Sln.Wcs.HoistServer/appsettings.json index aa175c1..6af4e2d 100644 --- a/Sln.Wcs.HoistServer/appsettings.json +++ b/Sln.Wcs.HoistServer/appsettings.json @@ -10,9 +10,9 @@ "apollo": { "AppId": "SlnWcs", "Env": "DEV", - "MetaServer": "http://119.45.202.115:4320", //配置网址 4310 + "MetaServer": "http://172.16.12.20:7320", //配置网址 4310 "ConfigServer": [ - "http://119.45.202.115:4320" + "http://172.16.12.20:7320" ] } } \ No newline at end of file diff --git a/Sln.Wcs.Plc/Service/Impl/InovanceImpl.cs b/Sln.Wcs.Plc/Service/Impl/InovanceImpl.cs index 5091cad..48fbf21 100644 --- a/Sln.Wcs.Plc/Service/Impl/InovanceImpl.cs +++ b/Sln.Wcs.Plc/Service/Impl/InovanceImpl.cs @@ -44,6 +44,7 @@ public class InovanceImpl:IPlc _stringChange = stringChange; this.inovanceTcp = new InovanceTcpNet(); + this.inovanceTcp.Series = InovanceSeries.H3U; this.inovanceTcp.ConnectTimeOut = 2000; } @@ -166,56 +167,7 @@ public class InovanceImpl:IPlc { try { - OperateResult operateResult = new OperateResult(); - int s = 0; - string[] strArry = address.Split('.'); - - //先读取整个块的内容 - var info = inovanceTcp.ReadInt16(strArry[0]); - if (info.Content == 0) - { - int length = _stringChange.ParseToInt(strArry[1]) + 1; - string[] array = new string[length]; - for (int i = 0; i < length; i++) - { - if (i == _stringChange.ParseToInt(strArry[1])) - { - array[i] = value.ToString(); - } - else - { - array[i] = "0"; - } - } - //反转 - Array.Reverse(array); - byte[] buffer = new byte[array.Length]; - string result = ""; - for (int i = 0; i < array.Length; i++) - { - result += (byte)Convert.ToInt32(array[i], 16); - } - s = Convert.ToInt32(result.Trim(), 2); - operateResult = inovanceTcp.Write(strArry[0], (ushort)s); - } - else - { - var inf2 = Convert.ToString(info.Content, 2); - string[] infoArray = new string[inf2.Length]; - for (int i = 0; i < inf2.Length; i++) - { - infoArray[i] = inf2.Substring(i, 1); - } - Array.Reverse(infoArray); - infoArray[_stringChange.ParseToInt(strArry[1])] = value.ToString(); - string result = ""; - foreach (var item in infoArray) - { - result = result + item; - } - s = Convert.ToInt32(result.Trim(), 10); - operateResult = inovanceTcp.Write(strArry[0], s); - } + OperateResult operateResult = inovanceTcp.Write(address, value); if (!operateResult.IsSuccess) { throw new InvalidOperationException($"根据地址:{address};写入int16数据失败:{operateResult.Message}"); @@ -226,6 +178,68 @@ public class InovanceImpl:IPlc { throw new InvalidOperationException($"根据地址:{address};写入int16数据异常:{ex.Message}"); } + // try + // { + // OperateResult operateResult = new OperateResult(); + // int s = 0; + // string[] strArry = address.Split('.'); + // + // //先读取整个块的内容 + // var info = inovanceTcp.ReadInt16(strArry[0]); + // if (info.Content == 0) + // { + // int length = _stringChange.ParseToInt(strArry[1]) + 1; + // string[] array = new string[length]; + // for (int i = 0; i < length; i++) + // { + // if (i == _stringChange.ParseToInt(strArry[1])) + // { + // array[i] = value.ToString(); + // } + // else + // { + // array[i] = "0"; + // } + // } + // //反转 + // Array.Reverse(array); + // byte[] buffer = new byte[array.Length]; + // string result = ""; + // for (int i = 0; i < array.Length; i++) + // { + // result += (byte)Convert.ToInt32(array[i], 16); + // } + // s = Convert.ToInt32(result.Trim(), 2); + // operateResult = inovanceTcp.Write(strArry[0], (ushort)s); + // } + // else + // { + // var inf2 = Convert.ToString(info.Content, 2); + // string[] infoArray = new string[inf2.Length]; + // for (int i = 0; i < inf2.Length; i++) + // { + // infoArray[i] = inf2.Substring(i, 1); + // } + // Array.Reverse(infoArray); + // infoArray[_stringChange.ParseToInt(strArry[1])] = value.ToString(); + // string result = ""; + // foreach (var item in infoArray) + // { + // result = result + item; + // } + // s = Convert.ToInt32(result.Trim(), 10); + // operateResult = inovanceTcp.Write(strArry[0], s); + // } + // if (!operateResult.IsSuccess) + // { + // throw new InvalidOperationException($"根据地址:{address};写入int16数据失败:{operateResult.Message}"); + // } + // return operateResult.IsSuccess; + // } + // catch (Exception ex) + // { + // throw new InvalidOperationException($"根据地址:{address};写入int16数据异常:{ex.Message}"); + // } } /// diff --git a/Sln.Wcs.UI/appsettings.json b/Sln.Wcs.UI/appsettings.json index ebaa832..a6a5ad6 100644 --- a/Sln.Wcs.UI/appsettings.json +++ b/Sln.Wcs.UI/appsettings.json @@ -10,9 +10,9 @@ "apollo": { "AppId": "SlnWcs", "Env": "DEV", - "MetaServer": "http://119.45.202.115:4320", + "MetaServer": "http://172.16.12.20:7320", "ConfigServer": [ - "http://119.45.202.115:4320" + "http://172.16.12.20:7320" ] } } diff --git a/Sln.Wcs/HoistDispatchHubTest.cs b/Sln.Wcs/HoistDispatchHubTest.cs new file mode 100644 index 0000000..c6554e9 --- /dev/null +++ b/Sln.Wcs/HoistDispatchHubTest.cs @@ -0,0 +1,56 @@ +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- +* 版权所有 (c) 2026 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:Mr.Wen's MacBook Pro +* 命名空间:Sln.Wcs +* 唯一标识:CD7CB56F-3972-40A5-A811-880CFE6EC557 +* +* 创建者:WenJY +* 电子邮箱: +* 创建时间:2026-06-18 14:57:01 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +using Sln.Wcs.HoistDispatcher; +using Sln.Wcs.Model.Domain; + +namespace Sln.Wcs; + +public class HoistDispatchHubTest +{ + private readonly HoistDispatchHub _hub; + + public HoistDispatchHubTest(HoistDispatchHub hub) + { + _hub = hub; + } + + public async void Run() + { + BaseDeviceInfo info = await _hub.GetFreeHoistAsync("1#Host"); + + _hub.TaskDispatch(info,new LiveTaskDetail() + { + deviceType = 2, + startPoint = "15#_L1_HOIST", + endPoint = "15#_L2_HOIST", + materialBarcode = "202606180001", + taskCode = "202606180001", + taskType = 1 + }); + + _hub.TaskRun(info); + } +} \ No newline at end of file diff --git a/Sln.Wcs/appsettings.json b/Sln.Wcs/appsettings.json index aa175c1..c01ba47 100644 --- a/Sln.Wcs/appsettings.json +++ b/Sln.Wcs/appsettings.json @@ -10,9 +10,9 @@ "apollo": { "AppId": "SlnWcs", "Env": "DEV", - "MetaServer": "http://119.45.202.115:4320", //配置网址 4310 + "MetaServer": "http://172.16.12.20:7320", //服务器地址http://119.45.202.115:4320配置网址 4310 "ConfigServer": [ - "http://119.45.202.115:4320" + "http://172.16.12.20:7320" ] } } \ No newline at end of file diff --git a/TODO.md b/TODO.md index c8ebdc9..2058eec 100644 --- a/TODO.md +++ b/TODO.md @@ -17,7 +17,11 @@ 等待步骤执行WAIT => 筛选提升机、下发提升机任务 FINISHED/MANUALED => 完成/手动完成,可以进行后序任务 CANCELLED => 任务取消,终止调度任务 -- [ ] Strategy执行到提升机任务时进行读取托盘条码,验证物料并下发提升机启动信号 +- [ ] Strategy执行到提升机任务时判断接驳位状态,如果接驳位状态占用则说明有物料进行读取托盘条码,验证物料并下发提升机启动信号 + +### 任务创建修改 +- [ ] 添加手动放、手动取操作,如果是手动放,任务从提升机开始,手动取也是以提升机结束 +- [ ] 手动放:任务执行则下发提升机任务 ### 2. 任务执行引擎(分组并行方案) - [ ] 包材入库逻辑测试