change - 出库逻辑修改

collectionStore
wenjy 1 year ago
parent b554108d24
commit 1737d3510d

@ -103,17 +103,17 @@ namespace Aucma.Scada.Business
StartPassDown(); StartPassDown();
Task.Run(() => //Task.Run(() =>
{ //{
Thread.Sleep(6000); // Thread.Sleep(6000);
for (int i = 1; i < 4; i++) // for (int i = 1; i < 12; i++)
{ // {
//InStore(appConfig.shellStoreCode, "B23600000781110800" + i.ToString().PadLeft(2, '0')); // InStore(appConfig.shellStoreCode, "B23600000781110900" + i.ToString().PadLeft(2, '0'));
//Thread.Sleep(1000*60*1); // Thread.Sleep(1000 * 30);
InStore(appConfig.linerStoreCode, "L23600000781110800" + i.ToString().PadLeft(2, '0')); // InStore(appConfig.linerStoreCode, "L23600000788110900" + i.ToString().PadLeft(2, '0'));
Thread.Sleep(1000 * 30); // Thread.Sleep(1000 * 30);
} // }
}); //});
} }
@ -235,7 +235,7 @@ namespace Aucma.Scada.Business
{ {
try try
{ {
RealTaskInfo taskInfo = taskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode, appConfig.instoreTaskType); RealTaskInfo taskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode, appConfig.instoreTaskType);
if (taskInfo != null) if (taskInfo != null)
{ {
PrintLogInfoMessage($"下发箱壳入库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}"); PrintLogInfoMessage($"下发箱壳入库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}");
@ -277,7 +277,7 @@ namespace Aucma.Scada.Business
{ {
try try
{ {
RealTaskInfo taskInfo = taskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, appConfig.instoreTaskType); RealTaskInfo taskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, appConfig.instoreTaskType);
if (taskInfo != null) if (taskInfo != null)
{ {
PrintLogInfoMessage($"下发内胆入库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}"); PrintLogInfoMessage($"下发内胆入库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}");

@ -113,7 +113,8 @@ namespace Aucma.Scada.Business
_recordProductfinishService = registerServices.GetService<IRecordProductfinishService>(); _recordProductfinishService = registerServices.GetService<IRecordProductfinishService>();
assemblyPlanBusiness.NextPassExecutePlanInfoEvent += PlanHandle; assemblyPlanBusiness.NextPassExecutePlanInfoEvent += PlanHandle;
taskHandleBusiness.OutStoreFinsihEvent += TaskFeedback; taskHandleBusiness.OutStoreAnswerEvent += OutStoreAnswer;
taskHandleBusiness.OutStoreFinsihEvent += OutStoreFinish;
StartPassDown(); StartPassDown();
} }
@ -305,25 +306,125 @@ namespace Aucma.Scada.Business
private int taskAmount = 2; private int taskAmount = 2;
private SemaphoreSlim shellSemaphore = new SemaphoreSlim(0);
private SemaphoreSlim linerSemaphore = new SemaphoreSlim(0);
private void StartPassDown() private void StartPassDown()
{ {
Task.Run(() => Task.Run(() =>
{ {
while (true) while (true)
{ {
PassDownTaskInfo(); PassDownShellTask();
Thread.Sleep(1000); Thread.Sleep(2000);
}
});
Task.Run(() =>
{
while (true)
{
PassDownLinerTask();
Thread.Sleep(2000);
} }
}); });
} }
/// <summary>
/// 下传箱壳出库任务至PLC
/// </summary>
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);
}
}
/// <summary>
/// 依次获取内胆任务队列进行下发
/// </summary>
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应答后继续下发新任务
/// <summary> /// <summary>
/// 依次获取任务队列进行下发 /// 依次获取任务队列进行下发
/// </summary> /// </summary>
/// <param name="source"></param> /// <param name="source"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void PassDownTaskInfo() /*private void PassDownTaskInfo()
{ {
string shellCode = string.Empty; string shellCode = string.Empty;
string linerCode = string.Empty; string linerCode = string.Empty;
@ -375,31 +476,22 @@ namespace Aucma.Scada.Business
} }
_taskInfoService.UpdateTaskInfo(item); _taskInfoService.UpdateTaskInfo(item);
RefreshScanMateriaCodeEvent?.Invoke(item.materialCode, item.materialType, item.spaceName, item.storeCode);
} }
if (iFlag == taskInfoList.Count) if (iFlag == taskInfoList.Count)
{ {
//if (semaphore.Wait(TimeSpan.FromSeconds(20)))
//{
// // 收到反馈
// PrintLogInfoMessage("收到反馈,继续执行");
//}
//else
//{
// PrintLogInfoMessage("超时未反馈");
//}
semaphore.Wait(); //一直堵塞直到信号量释放 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); Thread.Sleep(3000);
} }*/
/// <summary> /// <summary>
/// 获取待执行的出库任务 /// 获取待执行的出库任务
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
private List<RealTaskInfo> GetAwaitSendTask() /*private List<RealTaskInfo> GetAwaitSendTask()
{ {
List<RealTaskInfo> taskInfos = new List<RealTaskInfo>(); List<RealTaskInfo> taskInfos = new List<RealTaskInfo>();
try try
{ {
RealTaskInfo shellTaskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode, 2); RealTaskInfo shellTaskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode, appConfig.outstoreTaskType);
if (shellTaskInfo != null) if (shellTaskInfo != null)
{ {
@ -433,7 +525,7 @@ namespace Aucma.Scada.Business
} }
else else
{ {
RealTaskInfo linerInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, 2); RealTaskInfo linerInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, appConfig.outstoreTaskType);
if (linerInfo != null) taskInfos.Add(linerInfo); if (linerInfo != null) taskInfos.Add(linerInfo);
} }
@ -448,51 +540,56 @@ namespace Aucma.Scada.Business
PrintLogErrorMessage("获取待执行的出库任务异常", ex); PrintLogErrorMessage("获取待执行的出库任务异常", ex);
} }
return taskInfos; return taskInfos;
} }*/
#endregion
#region PLC应答反馈
/// <summary> /// <summary>
/// PLC任务执行反馈 /// 出库应答
/// </summary> /// </summary>
/// <param name="storeCode"></param> /// <param name="storeCode"></param>
/// <param name="taskCode"></param> /// <param name="taskCode"></param>
private void TaskFeedback(string storeCode, string taskCode) private void OutStoreAnswer(string storeCode, string taskCode)
{ {
if (storeCode == appConfig.shellStoreCode) if (storeCode == appConfig.shellStoreCode)
{ {
ShellTaskFeedback(taskCode); //Interlocked.Increment(ref completedTasks);
//CheckCompletedTasks();
PrintLogInfoMessage("箱壳应答成功,自动释放信号量,进行下发新任务");
shellSemaphore.Release();
} }
else else
{ {
LinerTaskFeedback(taskCode); //Interlocked.Increment(ref completedTasks);
}
}
/// <summary> //CheckCompletedTasks();
/// 箱壳执行反馈
/// </summary>
private void ShellTaskFeedback(string taskCode)
{
Interlocked.Increment(ref completedTasks);
CheckCompletedTasks(); PrintLogInfoMessage("内胆应答成功,自动释放信号量,进行下发新任务");
PrintLogInfoMessage("箱壳执行完成,自动释放信号量"); linerSemaphore.Release();
}
OutStoreFinish(taskCode, appConfig.shellStoreCode);
} }
/// <summary> /// <summary>
/// 内胆执行反馈 /// 出库完成
/// </summary> /// </summary>
private void LinerTaskFeedback(string taskCode) /// <param name="storeCode"></param>
/// <param name="taskCode"></param>
private void OutStoreFinish(string storeCode, string taskCode)
{ {
Interlocked.Increment(ref completedTasks); if (storeCode == appConfig.shellStoreCode)
{
CheckCompletedTasks(); PrintLogInfoMessage($"箱壳任务:{taskCode};执行完成");
OutStoreFinishHandle(taskCode, appConfig.shellStoreCode);
PrintLogInfoMessage("内胆执行完成,自动释放信号量"); }
else
OutStoreFinish(taskCode, appConfig.linerStoreCode); {
PrintLogInfoMessage($"内胆任务:{taskCode};执行完成");
OutStoreFinishHandle(taskCode, appConfig.linerStoreCode);
}
} }
/// <summary> /// <summary>
@ -508,15 +605,13 @@ namespace Aucma.Scada.Business
} }
#endregion #endregion
/// <summary> /// <summary>
/// 出库完成 /// 出库完成
/// </summary> /// </summary>
/// <param name="storeCode"></param> /// <param name="storeCode"></param>
/// <param name="spaceCode"></param> /// <param name="spaceCode"></param>
/// <param name="materialType"></param> /// <param name="materialType"></param>
private void OutStoreFinish(string taskCode, string storeCode) private void OutStoreFinishHandle(string taskCode, string storeCode)
{ {
try try
{ {
@ -524,11 +619,12 @@ namespace Aucma.Scada.Business
if (taskInfo != null) if (taskInfo != null)
{ {
var spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(taskInfo.storeCode, taskInfo.spaceCode); var spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(taskInfo.storeCode, taskInfo.spaceCode);
if (spaceInfo != null) if (spaceInfo != null)
{ {
taskHandleBusiness.WritePlc(spaceInfo.storeCode, spaceInfo.spaceCode);
//读取PLC获取货道信息存放数量、在途数量 //读取PLC获取货道信息存放数量、在途数量
spaceInfo.spaceStock -= 1; spaceInfo.spaceStock -= 1;
spaceInfo.outRouteAmount -= 1; spaceInfo.outRouteAmount -= 1;
@ -557,6 +653,12 @@ namespace Aucma.Scada.Business
_recordOutStoreService.InsertReocrdOutStoreService(recordOutstore); _recordOutStoreService.InsertReocrdOutStoreService(recordOutstore);
#endregion #endregion
} }
//更新计划信息
UpdatePlanInfo(taskInfo.planCode);
RefreshStoreStockEvent?.Invoke();
//清除任务信息 //清除任务信息
_taskInfoService.DeleteTaskInfo(taskCode, storeCode); _taskInfoService.DeleteTaskInfo(taskCode, storeCode);
@ -700,27 +802,6 @@ namespace Aucma.Scada.Business
return result; return result;
} }
/// <summary>
/// 日志输出,界面刷新同时记录文件
/// </summary>
/// <param name="message"></param>
private void PrintLogInfoMessage(string message)
{
RefreshLogMessageEvent?.Invoke(message);
logHelper.Info(message);
}
/// <summary>
/// 异常日志输出
/// </summary>
/// <param name="message"></param>
/// <param name="ex"></param>
private void PrintLogErrorMessage(string message, Exception ex = null)
{
RefreshLogMessageEvent?.Invoke(message);
logHelper.Error(message, ex);
}
/// <summary> /// <summary>
/// 手动释放信号量 /// 手动释放信号量
/// </summary> /// </summary>
@ -751,6 +832,7 @@ namespace Aucma.Scada.Business
return materialName; return materialName;
} }
#region 通过PLC读取货道信息
/// <summary> /// <summary>
/// 通过PLC读取货道信息在库数量、货道状态) /// 通过PLC读取货道信息在库数量、货道状态)
/// </summary> /// </summary>
@ -763,7 +845,7 @@ namespace Aucma.Scada.Business
try try
{ {
List<BaseSpaceInfo> info = _spaceInfoService.GetBaseSpaceInfosByMaterialType(storeCode, materialType); List<BaseSpaceInfo> info = _spaceInfoService.OutStoreGetSpaceInfoByMaterialCode(storeCode, materialType);
if (info != null) if (info != null)
{ {
@ -775,9 +857,21 @@ namespace Aucma.Scada.Business
item.spaceStock = spaceInfo.spaceStock; item.spaceStock = spaceInfo.spaceStock;
item.onRouteAmount = spaceInfo.onRouteAmount; item.onRouteAmount = spaceInfo.onRouteAmount;
item.spaceStatus = spaceInfo.spaceStatus; 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; return result;
} }
#endregion
#region 日志输出
/// <summary>
/// 日志输出,界面刷新同时记录文件
/// </summary>
/// <param name="message"></param>
private void PrintLogInfoMessage(string message)
{
RefreshLogMessageEvent?.Invoke(message);
logHelper.Info(message);
}
/// <summary>
/// 异常日志输出
/// </summary>
/// <param name="message"></param>
/// <param name="ex"></param>
private void PrintLogErrorMessage(string message, Exception ex = null)
{
RefreshLogMessageEvent?.Invoke(message);
logHelper.Error(message, ex);
}
#endregion
} }
} }

@ -4,6 +4,7 @@ using HighWayIot.Log4net;
using HighWayIot.Plc; using HighWayIot.Plc;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -53,6 +54,12 @@ namespace Aucma.Scada.Business
/// 内胆任务编号,PLC反馈后进行赋值 /// 内胆任务编号,PLC反馈后进行赋值
/// </summary> /// </summary>
private string linerTaskCode = string.Empty; private string linerTaskCode = string.Empty;
/// <summary>
/// 已下传的任务信息
/// </summary>
private List<RealTaskInfo> shellTaskInfos = new List<RealTaskInfo>();
private List<RealTaskInfo> linerTaskInfos = new List<RealTaskInfo>();
#endregion #endregion
#region 委托事件 #region 委托事件
@ -63,12 +70,26 @@ namespace Aucma.Scada.Business
/// <param name="taskCode"></param> /// <param name="taskCode"></param>
public delegate void OutStoreFinsih(string storeCode, string taskCode); public delegate void OutStoreFinsih(string storeCode, string taskCode);
public event OutStoreFinsih OutStoreFinsihEvent; public event OutStoreFinsih OutStoreFinsihEvent;
/// <summary>
/// PLC应答
/// </summary>
/// <param name="storeCode"></param>
/// <param name="taskCode"></param>
public delegate void OutStoreAnswer(string storeCode, string taskCode);
public event OutStoreAnswer OutStoreAnswerEvent;
#endregion #endregion
private OutStoreTaskHandle() private OutStoreTaskHandle()
{ {
_plcDictionary = _pool.GetAll(); _plcDictionary = _pool.GetAll();
RealReadShellFinish();
RealReadLinerFinish();
RealBindMaterialCode();
} }
#region 箱壳出库任务下发处理 #region 箱壳出库任务下发处理
@ -97,7 +118,7 @@ namespace Aucma.Scada.Business
_plc.writeStringByAddress(plcConfig.out_shell_task, taskInfo.taskCode); _plc.writeStringByAddress(plcConfig.out_shell_task, taskInfo.taskCode);
//写入完成后读取应答字进行复位 //写入完成后读取应答字进行复位
ReadShellAnswer_OutStore(taskInfo.taskCode); ReadShellAnswer_OutStore(taskInfo);
result = true; result = true;
} }
@ -122,104 +143,104 @@ namespace Aucma.Scada.Business
/// <summary> /// <summary>
/// 读取箱壳出库应答 /// 读取箱壳出库应答
/// </summary> /// </summary>
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; Task.Run(() =>
IPlc _plc = _plcDictionary[appConfig.shellStoreCode];
try
{ {
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.writeStringByAddress(plcConfig.out_shell_spaceCode, string.Empty); //写入应答字
//写入出库数量 _plc.writeInt32ByAddress(plcConfig.out_shell_answer, 0);
_plc.writeInt32ByAddress(plcConfig.out_shell_amount, 0); //写入任务号
//写入应答字 _plc.writeStringByAddress(plcConfig.out_shell_task, string.Empty);
_plc.writeInt32ByAddress(plcConfig.out_shell_answer, 0); isFlag = false;
//写入任务号
_plc.writeStringByAddress(plcConfig.out_shell_task, string.Empty); //ReadShellFinish_OutStore(taskInfo.taskCode);
isFlag = false;
OutStoreAnswerEvent?.Invoke(appConfig.shellStoreCode, taskInfo.taskCode);
ReadShellFinish_OutStore(taskCode);
} shellTaskInfos.Add(taskInfo);
}
Thread.Sleep(1000);
} while (isFlag); Thread.Sleep(1000);
} } while (isFlag);
else
{
logHelper.Info($"仓库{appConfig.shellStoreCode}PLC未连接");
}
} }
else else
{ {
logHelper.Info($"PLC信息为空通过{appConfig.shellStoreCode}未获取到该仓库对应的PLC信息"); logHelper.Info($"仓库{appConfig.shellStoreCode}PLC未连接");
} }
}); }
} else
catch (Exception ex) {
{ logHelper.Info($"PLC信息为空通过{appConfig.shellStoreCode}未获取到该仓库对应的PLC信息");
logHelper.Error("读取箱壳出库应答字异常", ex); }
} });
}
catch (Exception ex)
{
logHelper.Error("读取箱壳出库应答字异常", ex);
} }
} }
/// <summary> /// <summary>
/// 读取箱壳出库完成 /// 读取箱壳出库完成
/// </summary> /// </summary>
private void ReadShellFinish_OutStore(string taskCode) private void ReadShellFinish_OutStore(RealTaskInfo taskInfo)
{ {
lock (string.Empty) lock (string.Empty)
{ {
bool isFlag = true; bool isFlag = true;
IPlc _plc = _plcDictionary[appConfig.shellStoreCode]; IPlc _plc = _plcDictionary[appConfig.shellStoreCode];
shellTaskCode = taskCode; shellTaskCode = taskInfo.taskCode;
try 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出库任务完成 _plc.writeInt32ByAddress(plcConfig.out_shell_finish, 0);
if (_plc.readInt32ByAddress(plcConfig.out_shell_finish) == 1)
{
_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); //shellTaskInfos.Remove(taskInfo);
} while (isFlag); }
}
else Thread.Sleep(1000);
{ } while (isFlag);
logHelper.Info($"仓库{appConfig.shellStoreCode}PLC未连接");
}
} }
else else
{ {
logHelper.Info($"PLC信息为空通过{appConfig.shellStoreCode}未获取到该仓库对应的PLC信息"); logHelper.Info($"仓库{appConfig.shellStoreCode}PLC未连接");
} }
}); }
else
{
logHelper.Info($"PLC信息为空通过{appConfig.shellStoreCode}未获取到该仓库对应的PLC信息");
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -255,7 +276,7 @@ namespace Aucma.Scada.Business
_plc.writeStringByAddress(plcConfig.out_liner_task, taskInfo.taskCode); _plc.writeStringByAddress(plcConfig.out_liner_task, taskInfo.taskCode);
//写入完成后读取应答字进行复位 //写入完成后读取应答字进行复位
ReadLinerAnswer_OutStore(taskInfo.taskCode); ReadLinerAnswer_OutStore(taskInfo);
result = true; result = true;
} }
@ -279,106 +300,103 @@ namespace Aucma.Scada.Business
/// <summary> /// <summary>
/// 读取内胆出库应答 /// 读取内胆出库应答
/// </summary> /// </summary>
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; Task.Run(() =>
IPlc _plc = _plcDictionary[appConfig.shellStoreCode];
linerTaskCode = taskCode;
try
{ {
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.writeStringByAddress(plcConfig.out_liner_spaceCode, string.Empty); //写入应答字
//写入出库数量 _plc.writeInt32ByAddress(plcConfig.out_liner_answer, 0);
_plc.writeInt32ByAddress(plcConfig.out_liner_amount, 0); //写入任务号
//写入应答字 _plc.writeStringByAddress(plcConfig.out_liner_task, string.Empty);
_plc.writeInt32ByAddress(plcConfig.out_liner_answer, 0); isFlag = false;
//写入任务号
_plc.writeStringByAddress(plcConfig.out_liner_task, string.Empty); //ReadLinerFinish_OutStore(taskCode);
isFlag = false; OutStoreAnswerEvent?.Invoke(appConfig.linerStoreCode, taskInfo.taskCode);
ReadLinerFinish_OutStore(taskCode); linerTaskInfos.Add(taskInfo);
} }
Thread.Sleep(1000); Thread.Sleep(1000);
} while (isFlag); } while (isFlag);
}
else
{
logHelper.Info($"仓库{appConfig.linerStoreCode}PLC未连接");
}
} }
else else
{ {
logHelper.Info($"PLC信息为空通过{appConfig.linerStoreCode}未获取到该仓库对应的PLC信息"); logHelper.Info($"仓库{appConfig.linerStoreCode}PLC未连接");
} }
}); }
} else
catch (Exception ex) {
{ logHelper.Info($"PLC信息为空通过{appConfig.linerStoreCode}未获取到该仓库对应的PLC信息");
logHelper.Error("读取内胆出库应答字异常", ex); }
} });
}
catch (Exception ex)
{
logHelper.Error("读取内胆出库应答字异常", ex);
} }
} }
/// <summary> /// <summary>
/// 读取内胆出库完成 /// 读取内胆出库完成
/// </summary> /// </summary>
private void ReadLinerFinish_OutStore(string taskCode) private void ReadLinerFinish_OutStore(RealTaskInfo taskInfo)
{ {
lock (string.Empty) lock (string.Empty)
{ {
try try
{ {
Task.Run(() => bool isFlag = true;
IPlc _plc = _plcDictionary[appConfig.linerStoreCode];
if (_plc != null)
{ {
bool isFlag = true; if (_plc.IsConnected)
IPlc _plc = _plcDictionary[appConfig.linerStoreCode];
if (_plc != null)
{ {
if (_plc.IsConnected) do
{ {
do //读取PLC出库任务完成
if (_plc.readInt32ByAddress(plcConfig.out_liner_finish) == 1)
{ {
//读取PLC出库任务完成 _plc.writeInt32ByAddress(plcConfig.out_liner_finish, 0);
if (_plc.readInt32ByAddress(plcConfig.out_liner_finish) == 1)
{
_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); Thread.Sleep(1000);
} while (isFlag); } while (isFlag);
}
else
{
logHelper.Info($"仓库{appConfig.linerStoreCode}PLC未连接");
}
} }
else else
{ {
logHelper.Info($"PLC信息为空通过{appConfig.linerStoreCode}未获取到该仓库对应的PLC信息"); logHelper.Info($"仓库{appConfig.linerStoreCode}PLC未连接");
} }
}); }
else
{
logHelper.Info($"PLC信息为空通过{appConfig.linerStoreCode}未获取到该仓库对应的PLC信息");
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -388,6 +406,95 @@ namespace Aucma.Scada.Business
} }
#endregion #endregion
#region 出库完成
/// <summary>
/// 实时读取箱壳出库完成
/// </summary>
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);
};
});
}
/// <summary>
/// 实时读取内胆出库完成
/// </summary>
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);
};
});
}
/// <summary>
/// 实时绑定箱壳内胆
/// </summary>
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
/// <summary> /// <summary>
/// 通过PLC获取货道信息 /// 通过PLC获取货道信息
/// </summary> /// </summary>
@ -410,5 +517,29 @@ namespace Aucma.Scada.Business
return spaceInfo; return spaceInfo;
} }
/// <summary>
/// 测试方法,联调时不用
/// </summary>
/// <param name="storeCode"></param>
/// <param name="spaceCode"></param>
/// <param name="flag"></param>
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);
}
}
}
} }
} }

@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{43123E0B-B3B0-4FB4-A508-007D644B3E7C}</ProjectGuid> <ProjectGuid>{43123E0B-B3B0-4FB4-A508-007D644B3E7C}</ProjectGuid>
<OutputType>WinExe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>Aucma.Scada.UI</RootNamespace> <RootNamespace>Aucma.Scada.UI</RootNamespace>
<AssemblyName>Aucma.Scada.UI</AssemblyName> <AssemblyName>Aucma.Scada.UI</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>

@ -23,7 +23,7 @@ namespace HighWayIot.Repository.service
/// <param name="store"></param> /// <param name="store"></param>
/// <param name="materialType"></param> /// <param name="materialType"></param>
/// <returns></returns> /// <returns></returns>
BaseSpaceInfo OutStoreGetSpaceInfoByMaterialCode(string store, string materialCode); List<BaseSpaceInfo> OutStoreGetSpaceInfoByMaterialCode(string store, string materialCode);
/// <summary> /// <summary>
/// 通过货道编号获取货道信息 /// 通过货道编号获取货道信息

@ -106,26 +106,25 @@ namespace HighWayIot.Repository.service.Impl
/// <param name="store"></param> /// <param name="store"></param>
/// <param name="materialType"></param> /// <param name="materialType"></param>
/// <returns></returns> /// <returns></returns>
public BaseSpaceInfo OutStoreGetSpaceInfoByMaterialCode(string store, string materialType) public List<BaseSpaceInfo> OutStoreGetSpaceInfoByMaterialCode(string store, string materialType)
{ {
BaseSpaceInfo spaceInfo = null; List<BaseSpaceInfo> spaceInfos = null;
List<BaseSpaceInfo> spaceInfos;
try try
{ {
Expression<Func<BaseSpaceInfo, bool>> exp = s1 => true; Expression<Func<BaseSpaceInfo, bool>> 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); spaceInfos = _mesRepository.GetList(exp);
logHelper.Info($"根据仓库{store};物料:{materialType};获取到的货道信息:{jsonChange.ModeToJson(spaceInfos)}"); logHelper.Info($"根据仓库{store};物料:{materialType};获取到的货道信息:{jsonChange.ModeToJson(spaceInfos)}");
spaceInfo = outStoreFilter(spaceInfos); //spaceInfo = outStoreFilter(spaceInfos);
logHelper.Info($"仓库{store};物料:{materialType};匹配的入库货道信息:{jsonChange.ModeToJson(spaceInfo)}"); //logHelper.Info($"仓库{store};物料:{materialType};匹配的入库货道信息:{jsonChange.ModeToJson(spaceInfo)}");
} }
catch (Exception ex) catch (Exception ex)
{ {
logHelper.Error("出库通过物料类型获取货道信息异常", ex); logHelper.Error("出库通过物料类型获取货道信息异常", ex);
} }
return spaceInfo; return spaceInfos;
} }
/// <summary> /// <summary>

Loading…
Cancel
Save