diff --git a/Aucma.Scada.Business/InStoreBusiness.cs b/Aucma.Scada.Business/InStoreBusiness.cs index 672d5915..2d9d8f21 100644 --- a/Aucma.Scada.Business/InStoreBusiness.cs +++ b/Aucma.Scada.Business/InStoreBusiness.cs @@ -103,17 +103,17 @@ namespace Aucma.Scada.Business StartPassDown(); - Task.Run(() => - { - Thread.Sleep(6000); - for (int i = 1; i < 4; i++) - { - //InStore(appConfig.shellStoreCode, "B23600000781110800" + i.ToString().PadLeft(2, '0')); - //Thread.Sleep(1000*60*1); - InStore(appConfig.linerStoreCode, "L23600000781110800" + i.ToString().PadLeft(2, '0')); - Thread.Sleep(1000 * 30); - } - }); + //Task.Run(() => + //{ + // Thread.Sleep(6000); + // for (int i = 1; i < 12; i++) + // { + // InStore(appConfig.shellStoreCode, "B23600000781110900" + i.ToString().PadLeft(2, '0')); + // Thread.Sleep(1000 * 30); + // InStore(appConfig.linerStoreCode, "L23600000788110900" + i.ToString().PadLeft(2, '0')); + // Thread.Sleep(1000 * 30); + // } + //}); } @@ -235,7 +235,7 @@ namespace Aucma.Scada.Business { try { - RealTaskInfo taskInfo = taskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode, appConfig.instoreTaskType); + RealTaskInfo taskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode, appConfig.instoreTaskType); if (taskInfo != null) { PrintLogInfoMessage($"下发箱壳入库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}"); @@ -277,7 +277,7 @@ namespace Aucma.Scada.Business { try { - RealTaskInfo taskInfo = taskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, appConfig.instoreTaskType); + RealTaskInfo taskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, appConfig.instoreTaskType); if (taskInfo != null) { PrintLogInfoMessage($"下发内胆入库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}"); diff --git a/Aucma.Scada.Business/OutStoreBusiness.cs b/Aucma.Scada.Business/OutStoreBusiness.cs index b180e43b..db452434 100644 --- a/Aucma.Scada.Business/OutStoreBusiness.cs +++ b/Aucma.Scada.Business/OutStoreBusiness.cs @@ -113,7 +113,8 @@ namespace Aucma.Scada.Business _recordProductfinishService = registerServices.GetService(); assemblyPlanBusiness.NextPassExecutePlanInfoEvent += PlanHandle; - taskHandleBusiness.OutStoreFinsihEvent += TaskFeedback; + taskHandleBusiness.OutStoreAnswerEvent += OutStoreAnswer; + taskHandleBusiness.OutStoreFinsihEvent += OutStoreFinish; StartPassDown(); } @@ -305,25 +306,125 @@ namespace Aucma.Scada.Business private int taskAmount = 2; + private SemaphoreSlim shellSemaphore = new SemaphoreSlim(0); + + private SemaphoreSlim linerSemaphore = new SemaphoreSlim(0); + private void StartPassDown() { Task.Run(() => { while (true) { - PassDownTaskInfo(); - Thread.Sleep(1000); + PassDownShellTask(); + Thread.Sleep(2000); + } + }); + + Task.Run(() => + { + while (true) + { + PassDownLinerTask(); + Thread.Sleep(2000); } }); } + /// + /// 下传箱壳出库任务至PLC + /// + private void PassDownShellTask() + { + try + { + //获取箱壳出库任务 + RealTaskInfo taskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode, appConfig.outstoreTaskType); + + if(taskInfo != null) + { + PrintLogInfoMessage($"下发箱壳出库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}"); + + if (taskHandleBusiness.SendShellTask_OutStore(taskInfo)) + { + PrintLogInfoMessage($"箱壳出库任务:{taskInfo.taskCode};下发成功,等待PLC执行反馈"); + + shellSemaphore.Wait(); //一直堵塞直到信号量释放 + + PrintLogInfoMessage($"箱壳入库任务:{taskInfo.taskCode};开始执行"); + + taskInfo.taskStatus = 2; + + _taskInfoService.UpdateTaskInfo(taskInfo); + + RefreshScanMateriaCodeEvent?.Invoke(taskInfo.materialCode, taskInfo.materialType, taskInfo.spaceName, taskInfo.storeCode); + } + else + { + PrintLogInfoMessage($"箱壳出库任务:{taskInfo.taskCode};下发失败,请排除PLC连接"); + } + } + else + { + PrintLogInfoMessage("未获取到需要下发的箱壳出库任务"); + } + }catch(Exception ex) + { + PrintLogErrorMessage("下传箱壳出库任务逻辑处理异常", ex); + } + } + + /// + /// 依次获取内胆任务队列进行下发 + /// + private void PassDownLinerTask() + { + try + { + RealTaskInfo taskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, appConfig.outstoreTaskType); + if (taskInfo != null) + { + PrintLogInfoMessage($"下发内胆出库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}"); + + if (taskHandleBusiness.SendLinerTask_OutStore(taskInfo)) + { + PrintLogInfoMessage($"内胆出库任务:{taskInfo.taskCode};下发成功,等待PLC执行反馈"); + + linerSemaphore.Wait(); //一直堵塞直到信号量释放 + + PrintLogInfoMessage($"内胆出库任务:{taskInfo.taskCode};开始执行"); + + taskInfo.taskStatus = 2; + + _taskInfoService.UpdateTaskInfo(taskInfo); + + RefreshScanMateriaCodeEvent?.Invoke(taskInfo.materialCode, taskInfo.materialType, taskInfo.spaceName, taskInfo.storeCode); + } + else + { + PrintLogInfoMessage($"内胆出库任务:{taskInfo.taskCode};下发失败,请排除PLC连接"); + } + } + else + { + PrintLogInfoMessage("未获取到需要下发的内胆出库任务"); + } + } + catch (Exception ex) + { + PrintLogErrorMessage("下传内胆出库任务逻辑处理异常", ex); + } + } + #endregion + + #region 原任务下发逻辑 Delete By wenjy 2023-11-09 10:20:00 箱壳、内胆任务改为分别下发处理,PLC应答后继续下发新任务 /// /// 依次获取任务队列进行下发 /// /// /// - private void PassDownTaskInfo() + /*private void PassDownTaskInfo() { string shellCode = string.Empty; string linerCode = string.Empty; @@ -375,31 +476,22 @@ namespace Aucma.Scada.Business } _taskInfoService.UpdateTaskInfo(item); - RefreshScanMateriaCodeEvent?.Invoke(item.materialCode, item.materialType, item.spaceName, item.storeCode); + } if (iFlag == taskInfoList.Count) { - - //if (semaphore.Wait(TimeSpan.FromSeconds(20))) - //{ - // // 收到反馈 - // PrintLogInfoMessage("收到反馈,继续执行"); - //} - //else - //{ - // PrintLogInfoMessage("超时未反馈"); - //} - semaphore.Wait(); //一直堵塞直到信号量释放 - PrintLogInfoMessage($"出库任务:{taskCode};执行完成,绑定箱壳条码:{shellCode};内胆条码:{linerCode}"); + //PrintLogInfoMessage($"出库任务:{taskCode};应答成功,继续下发新任务"); + var item = taskInfoList.First(); + RefreshScanMateriaCodeEvent?.Invoke(item.materialCode, item.materialType, item.spaceName, item.storeCode); - UpdatePlanInfo(executePlanCode); + //UpdatePlanInfo(executePlanCode); - RefreshStoreStockEvent?.Invoke(); + //RefreshStoreStockEvent?.Invoke(); } } @@ -410,19 +502,19 @@ namespace Aucma.Scada.Business } Thread.Sleep(3000); - } + }*/ /// /// 获取待执行的出库任务 /// /// - private List GetAwaitSendTask() + /*private List GetAwaitSendTask() { List taskInfos = new List(); try { - RealTaskInfo shellTaskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode, 2); + RealTaskInfo shellTaskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode, appConfig.outstoreTaskType); if (shellTaskInfo != null) { @@ -433,7 +525,7 @@ namespace Aucma.Scada.Business } else { - RealTaskInfo linerInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, 2); + RealTaskInfo linerInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, appConfig.outstoreTaskType); if (linerInfo != null) taskInfos.Add(linerInfo); } @@ -448,51 +540,56 @@ namespace Aucma.Scada.Business PrintLogErrorMessage("获取待执行的出库任务异常", ex); } return taskInfos; - } + }*/ + #endregion + #region PLC应答反馈 /// - /// PLC任务执行反馈 + /// 出库应答 /// /// /// - private void TaskFeedback(string storeCode, string taskCode) + private void OutStoreAnswer(string storeCode, string taskCode) { if (storeCode == appConfig.shellStoreCode) { - ShellTaskFeedback(taskCode); + //Interlocked.Increment(ref completedTasks); + + //CheckCompletedTasks(); + + PrintLogInfoMessage("箱壳应答成功,自动释放信号量,进行下发新任务"); + + shellSemaphore.Release(); } else { - LinerTaskFeedback(taskCode); - } - } + //Interlocked.Increment(ref completedTasks); - /// - /// 箱壳执行反馈 - /// - private void ShellTaskFeedback(string taskCode) - { - Interlocked.Increment(ref completedTasks); + //CheckCompletedTasks(); - CheckCompletedTasks(); + PrintLogInfoMessage("内胆应答成功,自动释放信号量,进行下发新任务"); - PrintLogInfoMessage("箱壳执行完成,自动释放信号量"); - - OutStoreFinish(taskCode, appConfig.shellStoreCode); + linerSemaphore.Release(); + } } /// - /// 内胆执行反馈 + /// 出库完成 /// - private void LinerTaskFeedback(string taskCode) + /// + /// + private void OutStoreFinish(string storeCode, string taskCode) { - Interlocked.Increment(ref completedTasks); - - CheckCompletedTasks(); - - PrintLogInfoMessage("内胆执行完成,自动释放信号量"); - - OutStoreFinish(taskCode, appConfig.linerStoreCode); + if (storeCode == appConfig.shellStoreCode) + { + PrintLogInfoMessage($"箱壳任务:{taskCode};执行完成"); + OutStoreFinishHandle(taskCode, appConfig.shellStoreCode); + } + else + { + PrintLogInfoMessage($"内胆任务:{taskCode};执行完成"); + OutStoreFinishHandle(taskCode, appConfig.linerStoreCode); + } } /// @@ -508,15 +605,13 @@ namespace Aucma.Scada.Business } #endregion - - /// /// 出库完成 /// /// /// /// - private void OutStoreFinish(string taskCode, string storeCode) + private void OutStoreFinishHandle(string taskCode, string storeCode) { try { @@ -524,11 +619,12 @@ namespace Aucma.Scada.Business if (taskInfo != null) { var spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(taskInfo.storeCode, taskInfo.spaceCode); - + if (spaceInfo != null) { + taskHandleBusiness.WritePlc(spaceInfo.storeCode, spaceInfo.spaceCode); //读取PLC获取货道信息:存放数量、在途数量 - + spaceInfo.spaceStock -= 1; spaceInfo.outRouteAmount -= 1; @@ -557,6 +653,12 @@ namespace Aucma.Scada.Business _recordOutStoreService.InsertReocrdOutStoreService(recordOutstore); #endregion } + + //更新计划信息 + UpdatePlanInfo(taskInfo.planCode); + + RefreshStoreStockEvent?.Invoke(); + //清除任务信息 _taskInfoService.DeleteTaskInfo(taskCode, storeCode); @@ -700,27 +802,6 @@ namespace Aucma.Scada.Business return result; } - /// - /// 日志输出,界面刷新同时记录文件 - /// - /// - private void PrintLogInfoMessage(string message) - { - RefreshLogMessageEvent?.Invoke(message); - logHelper.Info(message); - } - - /// - /// 异常日志输出 - /// - /// - /// - private void PrintLogErrorMessage(string message, Exception ex = null) - { - RefreshLogMessageEvent?.Invoke(message); - logHelper.Error(message, ex); - } - /// /// 手动释放信号量 /// @@ -751,6 +832,7 @@ namespace Aucma.Scada.Business return materialName; } + #region 通过PLC读取货道信息 /// /// 通过PLC读取货道信息(在库数量、货道状态) /// @@ -763,7 +845,7 @@ namespace Aucma.Scada.Business try { - List info = _spaceInfoService.GetBaseSpaceInfosByMaterialType(storeCode, materialType); + List info = _spaceInfoService.OutStoreGetSpaceInfoByMaterialCode(storeCode, materialType); if (info != null) { @@ -775,9 +857,21 @@ namespace Aucma.Scada.Business item.spaceStock = spaceInfo.spaceStock; item.onRouteAmount = spaceInfo.onRouteAmount; item.spaceStatus = spaceInfo.spaceStatus; + PrintLogInfoMessage($"通过PLC读取货道信息,货道:{spaceInfo.spaceName};在库数量:{item.spaceStock};货道状态:{item.spaceStatus}"); } - result = info.Where(x => x.spaceStatus == 1 && x.spaceStock > 0).OrderBy(x => x.spaceStock).OrderBy(x => x.spaceCode).First(); + //result = info.Where(x => x.spaceStatus == 1 && x.spaceStock > 0).OrderBy(x => x.spaceStock).OrderBy(x => x.spaceCode).First(); + + var list = info.Where(x => x.spaceStatus == 1 && x.spaceStock > 0).ToList(); + + if(list.Count > 0) + { + result = info.OrderBy(x => x.spaceStock).OrderBy(x => x.spaceCode).First(); + } + else + { + PrintLogInfoMessage("未获取到匹配的货道,请排查货道库存及货道状态是否可用"); + } } } @@ -789,5 +883,29 @@ namespace Aucma.Scada.Business return result; } + #endregion + + #region 日志输出 + /// + /// 日志输出,界面刷新同时记录文件 + /// + /// + private void PrintLogInfoMessage(string message) + { + RefreshLogMessageEvent?.Invoke(message); + logHelper.Info(message); + } + + /// + /// 异常日志输出 + /// + /// + /// + private void PrintLogErrorMessage(string message, Exception ex = null) + { + RefreshLogMessageEvent?.Invoke(message); + logHelper.Error(message, ex); + } + #endregion } } diff --git a/Aucma.Scada.Business/OutStoreTaskHandle.cs b/Aucma.Scada.Business/OutStoreTaskHandle.cs index 0dc94665..eee542a3 100644 --- a/Aucma.Scada.Business/OutStoreTaskHandle.cs +++ b/Aucma.Scada.Business/OutStoreTaskHandle.cs @@ -4,6 +4,7 @@ using HighWayIot.Log4net; using HighWayIot.Plc; using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -53,6 +54,12 @@ namespace Aucma.Scada.Business /// 内胆任务编号,PLC反馈后进行赋值 /// private string linerTaskCode = string.Empty; + + /// + /// 已下传的任务信息 + /// + private List shellTaskInfos = new List(); + private List linerTaskInfos = new List(); #endregion #region 委托事件 @@ -63,12 +70,26 @@ namespace Aucma.Scada.Business /// public delegate void OutStoreFinsih(string storeCode, string taskCode); public event OutStoreFinsih OutStoreFinsihEvent; + + /// + /// PLC应答 + /// + /// + /// + public delegate void OutStoreAnswer(string storeCode, string taskCode); + public event OutStoreAnswer OutStoreAnswerEvent; #endregion private OutStoreTaskHandle() { _plcDictionary = _pool.GetAll(); + + RealReadShellFinish(); + + RealReadLinerFinish(); + + RealBindMaterialCode(); } #region 箱壳出库任务下发处理 @@ -97,7 +118,7 @@ namespace Aucma.Scada.Business _plc.writeStringByAddress(plcConfig.out_shell_task, taskInfo.taskCode); //写入完成后读取应答字进行复位 - ReadShellAnswer_OutStore(taskInfo.taskCode); + ReadShellAnswer_OutStore(taskInfo); result = true; } @@ -122,104 +143,104 @@ namespace Aucma.Scada.Business /// /// 读取箱壳出库应答 /// - private void ReadShellAnswer_OutStore(string taskCode) + private void ReadShellAnswer_OutStore(RealTaskInfo taskInfo) { - lock (string.Empty) + bool isFlag = true; + IPlc _plc = _plcDictionary[appConfig.shellStoreCode]; + try { - bool isFlag = true; - IPlc _plc = _plcDictionary[appConfig.shellStoreCode]; - try + Task.Run(() => { - Task.Run(() => + if (_plc != null) { - if (_plc != null) + if (_plc.IsConnected) { - if (_plc.IsConnected) + do { - do + //读取PLC应答字为2时,上位机清空写入的出库内容 + if (_plc.readInt32ByAddress(plcConfig.out_shell_answer) == 2) { - //读取PLC应答字为2时,上位机清空写入的出库内容 - if (_plc.readInt32ByAddress(plcConfig.out_shell_answer) == 2) - { - //写入货道号 - _plc.writeStringByAddress(plcConfig.out_shell_spaceCode, string.Empty); - //写入出库数量 - _plc.writeInt32ByAddress(plcConfig.out_shell_amount, 0); - //写入应答字 - _plc.writeInt32ByAddress(plcConfig.out_shell_answer, 0); - //写入任务号 - _plc.writeStringByAddress(plcConfig.out_shell_task, string.Empty); - isFlag = false; - - ReadShellFinish_OutStore(taskCode); - } - - Thread.Sleep(1000); - } while (isFlag); - } - else - { - logHelper.Info($"仓库{appConfig.shellStoreCode};PLC未连接"); - } + //写入货道号 + _plc.writeStringByAddress(plcConfig.out_shell_spaceCode, string.Empty); + //写入出库数量 + _plc.writeInt32ByAddress(plcConfig.out_shell_amount, 0); + //写入应答字 + _plc.writeInt32ByAddress(plcConfig.out_shell_answer, 0); + //写入任务号 + _plc.writeStringByAddress(plcConfig.out_shell_task, string.Empty); + isFlag = false; + + //ReadShellFinish_OutStore(taskInfo.taskCode); + + OutStoreAnswerEvent?.Invoke(appConfig.shellStoreCode, taskInfo.taskCode); + + shellTaskInfos.Add(taskInfo); + } + + Thread.Sleep(1000); + } while (isFlag); } else { - logHelper.Info($"PLC信息为空,通过{appConfig.shellStoreCode}未获取到该仓库对应的PLC信息"); + logHelper.Info($"仓库{appConfig.shellStoreCode};PLC未连接"); } - }); - } - catch (Exception ex) - { - logHelper.Error("读取箱壳出库应答字异常", ex); - } + } + else + { + logHelper.Info($"PLC信息为空,通过{appConfig.shellStoreCode}未获取到该仓库对应的PLC信息"); + } + }); + } + catch (Exception ex) + { + logHelper.Error("读取箱壳出库应答字异常", ex); } } /// /// 读取箱壳出库完成 /// - private void ReadShellFinish_OutStore(string taskCode) + private void ReadShellFinish_OutStore(RealTaskInfo taskInfo) { lock (string.Empty) { bool isFlag = true; IPlc _plc = _plcDictionary[appConfig.shellStoreCode]; - shellTaskCode = taskCode; + shellTaskCode = taskInfo.taskCode; try { - Task.Run(() => + if (_plc != null) { - if (_plc != null) + if (_plc.IsConnected) { - if (_plc.IsConnected) + do { - do + //读取PLC出库任务完成 + if (_plc.readInt32ByAddress(plcConfig.out_shell_finish) == 1) { - //读取PLC出库任务完成 - if (_plc.readInt32ByAddress(plcConfig.out_shell_finish) == 1) - { - _plc.writeInt32ByAddress(plcConfig.out_shell_finish, 0); + _plc.writeInt32ByAddress(plcConfig.out_shell_finish, 0); - //string taskCode = _plc.readStringByAddress(plcConfig.out_shell_task, 10); + //string taskCode = _plc.readStringByAddress(plcConfig.out_shell_task, 10); - OutStoreFinsihEvent?.Invoke(appConfig.shellStoreCode, taskCode); + OutStoreFinsihEvent?.Invoke(appConfig.shellStoreCode, taskInfo.taskCode); - isFlag = false; - } + isFlag = false; - Thread.Sleep(1000); - } while (isFlag); - } - else - { - logHelper.Info($"仓库{appConfig.shellStoreCode};PLC未连接"); - } + //shellTaskInfos.Remove(taskInfo); + } + + Thread.Sleep(1000); + } while (isFlag); } else { - logHelper.Info($"PLC信息为空,通过{appConfig.shellStoreCode}未获取到该仓库对应的PLC信息"); + logHelper.Info($"仓库{appConfig.shellStoreCode};PLC未连接"); } - }); + } + else + { + logHelper.Info($"PLC信息为空,通过{appConfig.shellStoreCode}未获取到该仓库对应的PLC信息"); + } } catch (Exception ex) { @@ -255,7 +276,7 @@ namespace Aucma.Scada.Business _plc.writeStringByAddress(plcConfig.out_liner_task, taskInfo.taskCode); //写入完成后读取应答字进行复位 - ReadLinerAnswer_OutStore(taskInfo.taskCode); + ReadLinerAnswer_OutStore(taskInfo); result = true; } @@ -279,106 +300,103 @@ namespace Aucma.Scada.Business /// /// 读取内胆出库应答 /// - private void ReadLinerAnswer_OutStore(string taskCode) + private void ReadLinerAnswer_OutStore(RealTaskInfo taskInfo) { - lock (string.Empty) + bool isFlag = true; + IPlc _plc = _plcDictionary[appConfig.linerStoreCode]; + try { - bool isFlag = true; - IPlc _plc = _plcDictionary[appConfig.shellStoreCode]; - linerTaskCode = taskCode; - try + Task.Run(() => { - Task.Run(() => - { - if (_plc != null) + if (_plc != null) + { + if (_plc.IsConnected) { - if (_plc.IsConnected) + do { - do + //读取PLC应答字为2时,上位机清空写入的出库内容 + if (_plc.readInt32ByAddress(plcConfig.out_liner_answer) == 2) { - //读取PLC应答字为2时,上位机清空写入的出库内容 - if (_plc.readInt32ByAddress(plcConfig.out_liner_answer) == 2) - { - //写入货道号 - _plc.writeStringByAddress(plcConfig.out_liner_spaceCode, string.Empty); - //写入出库数量 - _plc.writeInt32ByAddress(plcConfig.out_liner_amount, 0); - //写入应答字 - _plc.writeInt32ByAddress(plcConfig.out_liner_answer, 0); - //写入任务号 - _plc.writeStringByAddress(plcConfig.out_liner_task, string.Empty); - isFlag = false; - - ReadLinerFinish_OutStore(taskCode); - } - - Thread.Sleep(1000); - } while (isFlag); - } - else - { - logHelper.Info($"仓库{appConfig.linerStoreCode};PLC未连接"); - } + //写入货道号 + _plc.writeStringByAddress(plcConfig.out_liner_spaceCode, string.Empty); + //写入出库数量 + _plc.writeInt32ByAddress(plcConfig.out_liner_amount, 0); + //写入应答字 + _plc.writeInt32ByAddress(plcConfig.out_liner_answer, 0); + //写入任务号 + _plc.writeStringByAddress(plcConfig.out_liner_task, string.Empty); + isFlag = false; + + //ReadLinerFinish_OutStore(taskCode); + OutStoreAnswerEvent?.Invoke(appConfig.linerStoreCode, taskInfo.taskCode); + + linerTaskInfos.Add(taskInfo); + } + + Thread.Sleep(1000); + } while (isFlag); } else { - logHelper.Info($"PLC信息为空,通过{appConfig.linerStoreCode}未获取到该仓库对应的PLC信息"); + logHelper.Info($"仓库{appConfig.linerStoreCode};PLC未连接"); } - }); - } - catch (Exception ex) - { - logHelper.Error("读取内胆出库应答字异常", ex); - } + } + else + { + logHelper.Info($"PLC信息为空,通过{appConfig.linerStoreCode}未获取到该仓库对应的PLC信息"); + } + }); + } + catch (Exception ex) + { + logHelper.Error("读取内胆出库应答字异常", ex); } } /// /// 读取内胆出库完成 /// - private void ReadLinerFinish_OutStore(string taskCode) + private void ReadLinerFinish_OutStore(RealTaskInfo taskInfo) { lock (string.Empty) { try { - Task.Run(() => + bool isFlag = true; + IPlc _plc = _plcDictionary[appConfig.linerStoreCode]; + if (_plc != null) { - bool isFlag = true; - IPlc _plc = _plcDictionary[appConfig.linerStoreCode]; - if (_plc != null) + if (_plc.IsConnected) { - if (_plc.IsConnected) + do { - do + //读取PLC出库任务完成 + if (_plc.readInt32ByAddress(plcConfig.out_liner_finish) == 1) { - //读取PLC出库任务完成 - if (_plc.readInt32ByAddress(plcConfig.out_liner_finish) == 1) - { - _plc.writeInt32ByAddress(plcConfig.out_liner_finish, 0); + _plc.writeInt32ByAddress(plcConfig.out_liner_finish, 0); - //string taskCode = _plc.readStringByAddress(plcConfig.out_liner_task, 10); + //string taskCode = _plc.readStringByAddress(plcConfig.out_liner_task, 10); - OutStoreFinsihEvent?.Invoke(appConfig.linerStoreCode, taskCode); + OutStoreFinsihEvent?.Invoke(appConfig.linerStoreCode, taskInfo.taskCode); - isFlag = false; + isFlag = false; - } + //linerTaskInfos.Remove(taskInfo); + } - Thread.Sleep(1000); - } while (isFlag); - } - else - { - logHelper.Info($"仓库{appConfig.linerStoreCode};PLC未连接"); - } + Thread.Sleep(1000); + } while (isFlag); } else { - logHelper.Info($"PLC信息为空,通过{appConfig.linerStoreCode}未获取到该仓库对应的PLC信息"); + logHelper.Info($"仓库{appConfig.linerStoreCode};PLC未连接"); } - }); + } + else + { + logHelper.Info($"PLC信息为空,通过{appConfig.linerStoreCode}未获取到该仓库对应的PLC信息"); + } } catch (Exception ex) { @@ -388,6 +406,95 @@ namespace Aucma.Scada.Business } #endregion + #region 出库完成 + /// + /// 实时读取箱壳出库完成 + /// + private void RealReadShellFinish() + { + Task.Run(() => + { + while (true) + { + var info = shellTaskInfos.Where(x => x.taskStatus != 3).ToList(); + for (int i = 0; i < info.Count; i++) + { + var item = info[i]; + ReadShellFinish_OutStore(item); + Console.WriteLine($"箱壳任务:{item.taskCode};物料:{item.materialCode};出库完成"); + item.taskStatus = 3; + } + + Thread.Sleep(1000); + }; + }); + } + + /// + /// 实时读取内胆出库完成 + /// + private void RealReadLinerFinish() + { + Task.Run(() => + { + while (true) + { + var info = linerTaskInfos.Where(x => x.taskStatus != 3).ToList(); + for (int i = 0; i < info.Count; i++) + { + var item = info[i]; + ReadLinerFinish_OutStore(item); + Console.WriteLine($"内胆任务:{item.taskCode};物料:{item.materialCode};出库完成"); + item.taskStatus = 3; + } + + Thread.Sleep(1000); + }; + }); + } + + /// + /// 实时绑定箱壳内胆 + /// + private void RealBindMaterialCode() + { + Task.Run(() => + { + while (true) + { + var shellTasks = shellTaskInfos.Where(x => x.taskStatus == 3).ToList(); + + var linerTasks = linerTaskInfos.Where(x => x.taskStatus == 3).ToList(); + + RealTaskInfo shellTask = null; + RealTaskInfo linerTask = null; + + if (shellTasks.Count > 0) + { + shellTask = shellTasks.First(); + } + + if (linerTasks.Count > 0) + { + linerTask = linerTasks.First(); + } + + if (shellTask != null && linerTask != null) + { + Console.WriteLine($"绑定箱壳:{shellTask.materialCode};内胆:{linerTask.materialCode};条码"); + + shellTaskInfos.Remove(shellTask); + linerTaskInfos.Remove(linerTask); + } + + Thread.Sleep(1000); + } + }); + + } + #endregion + + /// /// 通过PLC获取货道信息 /// @@ -410,5 +517,29 @@ namespace Aucma.Scada.Business return spaceInfo; } + + /// + /// 测试方法,联调时不用 + /// + /// + /// + /// + public void WritePlc(string storeCode, string spaceCode) + { + var spaceAddress = spaceConfig.GetSpaceAddress(storeCode, spaceCode); + IPlc _plc = _plcDictionary[storeCode]; + + if (_plc != null) + { + if (_plc.IsConnected) + { + var spaceStock = _plc.readInt32ByAddress(spaceAddress.onStore); + //var onRouteAmount = _plc.readInt32ByAddress(spaceAddress.onRoute); + + _plc.writeInt32ByAddress(spaceAddress.onStore, spaceStock - 1); + + } + } + } } } diff --git a/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.dll b/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.dll index 21955b4c..79da0f1b 100644 Binary files a/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.dll and b/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.dll differ diff --git a/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.pdb b/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.pdb index bab5843c..01fb3b0b 100644 Binary files a/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.pdb and b/Aucma.Scada.Business/bin/Debug/Aucma.Scada.Business.pdb differ diff --git a/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.dll b/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.dll index 2a14061f..97162a7f 100644 Binary files a/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.dll and b/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.dll differ diff --git a/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.pdb b/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.pdb index 20fbb588..e40503b1 100644 Binary files a/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.pdb and b/Aucma.Scada.Business/bin/Debug/HighWayIot.Repository.pdb differ diff --git a/Aucma.Scada.UI/Aucma.Scada.UI.csproj b/Aucma.Scada.UI/Aucma.Scada.UI.csproj index 4816f234..efe46491 100644 --- a/Aucma.Scada.UI/Aucma.Scada.UI.csproj +++ b/Aucma.Scada.UI/Aucma.Scada.UI.csproj @@ -5,7 +5,7 @@ Debug AnyCPU {43123E0B-B3B0-4FB4-A508-007D644B3E7C} - WinExe + Exe Aucma.Scada.UI Aucma.Scada.UI v4.8 diff --git a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.dll b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.dll index 21955b4c..79da0f1b 100644 Binary files a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.dll and b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.dll differ diff --git a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.pdb b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.pdb index bab5843c..01fb3b0b 100644 Binary files a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.pdb and b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.Business.pdb differ diff --git a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.UI.exe b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.UI.exe index a09a9656..670571d1 100644 Binary files a/Aucma.Scada.UI/bin/Debug/Aucma.Scada.UI.exe and b/Aucma.Scada.UI/bin/Debug/Aucma.Scada.UI.exe differ diff --git a/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.dll b/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.dll index 2a14061f..97162a7f 100644 Binary files a/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.dll and b/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.dll differ diff --git a/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.pdb b/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.pdb index 20fbb588..e40503b1 100644 Binary files a/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.pdb and b/Aucma.Scada.UI/bin/Debug/HighWayIot.Repository.pdb differ diff --git a/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.dll b/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.dll index 2a14061f..97162a7f 100644 Binary files a/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.dll and b/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.dll differ diff --git a/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.pdb b/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.pdb index 20fbb588..e40503b1 100644 Binary files a/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.pdb and b/HighWayIot.Repository/bin/Debug/HighWayIot.Repository.pdb differ diff --git a/HighWayIot.Repository/service/IBaseSpaceInfoService.cs b/HighWayIot.Repository/service/IBaseSpaceInfoService.cs index 6483f875..e5911664 100644 --- a/HighWayIot.Repository/service/IBaseSpaceInfoService.cs +++ b/HighWayIot.Repository/service/IBaseSpaceInfoService.cs @@ -23,7 +23,7 @@ namespace HighWayIot.Repository.service /// /// /// - BaseSpaceInfo OutStoreGetSpaceInfoByMaterialCode(string store, string materialCode); + List OutStoreGetSpaceInfoByMaterialCode(string store, string materialCode); /// /// 通过货道编号获取货道信息 diff --git a/HighWayIot.Repository/service/Impl/BaseSpaceInfoServiceImpl.cs b/HighWayIot.Repository/service/Impl/BaseSpaceInfoServiceImpl.cs index ac081286..32a0e4fe 100644 --- a/HighWayIot.Repository/service/Impl/BaseSpaceInfoServiceImpl.cs +++ b/HighWayIot.Repository/service/Impl/BaseSpaceInfoServiceImpl.cs @@ -106,26 +106,25 @@ namespace HighWayIot.Repository.service.Impl /// /// /// - public BaseSpaceInfo OutStoreGetSpaceInfoByMaterialCode(string store, string materialType) + public List OutStoreGetSpaceInfoByMaterialCode(string store, string materialType) { - BaseSpaceInfo spaceInfo = null; - List spaceInfos; + List spaceInfos = null; try { Expression> exp = s1 => true; - exp = exp.And(x => x.storeCode == store && x.materialType == materialType && x.spaceStatus == 1 && x.spaceStock - x.outRouteAmount > 0); //相同型号、启用状态、库存不为空的货道信息 + exp = exp.And(x => x.storeCode == store && x.materialType == materialType && x.spaceStatus == 1); //相同型号、启用状态、库存不为空的货道信息 spaceInfos = _mesRepository.GetList(exp); logHelper.Info($"根据仓库{store};物料:{materialType};获取到的货道信息:{jsonChange.ModeToJson(spaceInfos)}"); - spaceInfo = outStoreFilter(spaceInfos); - logHelper.Info($"仓库{store};物料:{materialType};匹配的入库货道信息:{jsonChange.ModeToJson(spaceInfo)}"); + //spaceInfo = outStoreFilter(spaceInfos); + //logHelper.Info($"仓库{store};物料:{materialType};匹配的入库货道信息:{jsonChange.ModeToJson(spaceInfo)}"); } catch (Exception ex) { logHelper.Error("出库通过物料类型获取货道信息异常", ex); } - return spaceInfo; + return spaceInfos; } /// diff --git a/HighWayIot/bin/Debug/HighWayIot.Repository.dll b/HighWayIot/bin/Debug/HighWayIot.Repository.dll index 2a14061f..97162a7f 100644 Binary files a/HighWayIot/bin/Debug/HighWayIot.Repository.dll and b/HighWayIot/bin/Debug/HighWayIot.Repository.dll differ diff --git a/HighWayIot/bin/Debug/HighWayIot.Repository.pdb b/HighWayIot/bin/Debug/HighWayIot.Repository.pdb index 20fbb588..e40503b1 100644 Binary files a/HighWayIot/bin/Debug/HighWayIot.Repository.pdb and b/HighWayIot/bin/Debug/HighWayIot.Repository.pdb differ