change - 入库任务下发

foamRearStore
wenjy 1 year ago
parent d6ec9f0764
commit db715ed7bb

Binary file not shown.

@ -30,6 +30,8 @@ namespace Aucma.Scada.Business
private AppConfig appConfig = AppConfig.Instance; private AppConfig appConfig = AppConfig.Instance;
private RegisterServices registerServices = RegisterServices.Instance; private RegisterServices registerServices = RegisterServices.Instance;
private InStoreTaskHandle taskHandle = InStoreTaskHandle.Instance;
#endregion #endregion
#region 接口引用 #region 接口引用
@ -182,18 +184,34 @@ namespace Aucma.Scada.Business
if (taskInfo != null) if (taskInfo != null)
{ {
PrintLogInfoMessage($"下发箱壳入库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}"); PrintLogInfoMessage($"下发箱壳入库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}");
//taskHandle.SendShellTask_InStore(taskInfo);
if (shellSemaphore.Wait(TimeSpan.FromSeconds(10))) if (taskHandle.SendShellTask_InStore(taskInfo))
{ {
// 收到反馈 PrintLogInfoMessage($"箱壳入库任务:{taskInfo.taskCode}下发成功等待PLC执行反馈");
PrintLogInfoMessage("箱壳收到反馈,继续执行"); taskInfo.taskStatus = 2;
_taskInfoService.UpdateTaskInfo(taskInfo);
//if (shellSemaphore.Wait(TimeSpan.FromSeconds(20)))
//{
// // 收到反馈
// PrintLogInfoMessage("收到反馈,继续执行");
//}
//else
//{
// PrintLogInfoMessage("超时未反馈");
//}
shellSemaphore.Wait(); //一直堵塞直到信号量释放
PrintLogInfoMessage($"箱壳入库任务:{taskInfo.taskCode};执行完成");
} }
else else
{ {
PrintLogInfoMessage("超时未反馈"); PrintLogInfoMessage($"箱壳入库任务:{taskInfo.taskCode}下发失败请排除PLC连接");
} }
//shellSemaphore.Wait(); //一直堵塞直到信号量释放
} }
else else
{ {
@ -214,16 +232,31 @@ namespace Aucma.Scada.Business
{ {
PrintLogInfoMessage($"下发内胆入库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}"); PrintLogInfoMessage($"下发内胆入库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}");
if (linerSemaphore.Wait(TimeSpan.FromSeconds(10))) if (taskHandle.SendShellTask_InStore(taskInfo))
{ {
// 收到反馈 PrintLogInfoMessage($"内胆入库任务:{taskInfo.taskCode}下发成功等待PLC执行反馈");
PrintLogInfoMessage("内胆收到反馈,继续执行"); taskInfo.taskStatus = 2;
_taskInfoService.UpdateTaskInfo(taskInfo);
//if (shellSemaphore.Wait(TimeSpan.FromSeconds(20)))
//{
// // 收到反馈
// PrintLogInfoMessage("收到反馈,继续执行");
//}
//else
//{
// PrintLogInfoMessage("超时未反馈");
//}
linerSemaphore.Wait(); //一直堵塞直到信号量释放
PrintLogInfoMessage($"内胆入库任务:{taskInfo.taskCode};执行完成");
} }
else else
{ {
PrintLogInfoMessage("超时未反馈"); PrintLogInfoMessage($"内胆入库任务:{taskInfo.taskCode}下发失败请排除PLC连接");
} }
//semaphore.Wait(); //一直堵塞直到信号量释放
} }
else else
{ {

@ -1,4 +1,11 @@
using System; using Aucma.Scada.Model.domain;
using HighWayIot.Config;
using HighWayIot.Log4net;
using HighWayIot.Plc;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Aucma.Scada.Business namespace Aucma.Scada.Business
{ {
@ -18,9 +25,347 @@ namespace Aucma.Scada.Business
} }
#endregion #endregion
#region 对象引用
private LogHelper logHelper = LogHelper.Instance;
private AppConfig appConfig = AppConfig.Instance;
private PlcConfig plcConfig = PlcConfig.Instance;
private PlcPool _pool = PlcPool.Instance;
#endregion
#region 私有变量
private Dictionary<string, IPlc> _plcDictionary = new Dictionary<string, IPlc>();
/// <summary>
/// 箱壳任务编号,PLC反馈后进行赋值
/// </summary>
private string shellTaskCode = string.Empty;
/// <summary>
/// 内胆任务编号,PLC反馈后进行赋值
/// </summary>
private string linerTaskCode = string.Empty;
#endregion
#region 委托事件
/// <summary>
/// 入库完成
/// </summary>
/// <param name="storeCode"></param>
/// <param name="taskCode"></param>
public delegate void InStoreFinsih(string storeCode, string taskCode);
public event InStoreFinsih InStoreFinsihEvent;
#endregion
private InStoreTaskHandle() private InStoreTaskHandle()
{ {
_plcDictionary = _pool.GetAll();
}
#region 箱壳入库任务下发处理
public bool SendShellTask_InStore(RealTaskInfo taskInfo)
{
bool result = false;
try
{
IPlc _plc = _plcDictionary[taskInfo.storeCode];
if (_plc != null)
{
if (_plc.IsConnected)
{
//写入货道号
_plc.writeStringByAddress(plcConfig.in_shell_spaceCode, taskInfo.spaceCode);
//写入应答字
_plc.writeInt32ByAddress(plcConfig.in_shell_answer, 1);
//写入任务号
_plc.writeStringByAddress(plcConfig.in_shell_task, taskInfo.taskCode);
//写入完成后读取应答字进行复位
ReadShellAnswer_InStore(taskInfo.taskCode);
result = true;
}
else
{
logHelper.Info($"仓库{taskInfo.storeCode}PLC未连接");
}
}
else
{
logHelper.Info($"PLC信息为空通过{taskInfo.storeCode}未获取到该仓库对应的PLC信息");
}
}
catch (Exception ex)
{
logHelper.Error("箱壳入库任务下发异常", ex);
}
return result;
}
/// <summary>
/// 读取箱壳入库应答
/// </summary>
private void ReadShellAnswer_InStore(string taskCode)
{
lock (string.Empty)
{
bool isFlag = true;
IPlc _plc = _plcDictionary[appConfig.shellStoreCode];
try
{
Task.Run(() =>
{
if (_plc != null)
{
if (_plc.IsConnected)
{
do
{
//读取PLC应答字为2时上位机清空写入的入库内容
if (_plc.readInt32ByAddress(plcConfig.in_shell_answer) == 2)
{
//写入货道号
_plc.writeStringByAddress(plcConfig.in_shell_spaceCode, string.Empty);
//写入应答字
_plc.writeInt32ByAddress(plcConfig.in_shell_answer, 0);
//写入任务号
_plc.writeStringByAddress(plcConfig.in_shell_task, string.Empty);
isFlag = false;
ReadShellFinish_InStore(taskCode);
}
Thread.Sleep(5000);
} while (isFlag);
}
else
{
logHelper.Info($"仓库{appConfig.shellStoreCode}PLC未连接");
}
}
else
{
logHelper.Info($"PLC信息为空通过{appConfig.shellStoreCode}未获取到该仓库对应的PLC信息");
}
});
}
catch (Exception ex)
{
logHelper.Error("读取箱壳入库应答字异常", ex);
}
}
}
/// <summary>
/// 读取箱壳入库完成
/// </summary>
private void ReadShellFinish_InStore(string taskCode)
{
lock (string.Empty)
{
bool isFlag = true;
IPlc _plc = _plcDictionary[appConfig.shellStoreCode];
shellTaskCode = taskCode;
try
{
Task.Run(() =>
{
if (_plc != null)
{
if (_plc.IsConnected)
{
do
{
//读取PLC入库任务完成
if (_plc.readInt32ByAddress(plcConfig.in_shell_finish) == 1)
{
_plc.writeInt32ByAddress(plcConfig.in_shell_finish, 0);
//string taskCode = _plc.readStringByAddress(plcConfig.out_shell_task, 10);
InStoreFinsihEvent?.Invoke(appConfig.shellStoreCode, taskCode);
isFlag = false;
}
Thread.Sleep(5000);
} while (isFlag);
}
else
{
logHelper.Info($"仓库{appConfig.shellStoreCode}PLC未连接");
}
}
else
{
logHelper.Info($"PLC信息为空通过{appConfig.shellStoreCode}未获取到该仓库对应的PLC信息");
}
});
}
catch (Exception ex)
{
logHelper.Error("读取箱壳入库完成异常", ex);
}
}
}
#endregion
#region 内胆入库任务处理
/// <summary>
/// 内胆入库任务下发
/// </summary>
/// <param name="taskInfo"></param>
public bool SendLinerTask_InStore(RealTaskInfo taskInfo)
{
bool result = false;
try
{
IPlc _plc = _plcDictionary[taskInfo.storeCode];
if (_plc != null)
{
if (_plc.IsConnected)
{
//写入货道号
_plc.writeStringByAddress(plcConfig.in_liner_spaceCode, taskInfo.spaceCode);
//写入应答字
_plc.writeInt32ByAddress(plcConfig.in_liner_answer, 1);
//写入任务号
_plc.writeStringByAddress(plcConfig.in_liner_task, taskInfo.taskCode);
//写入完成后读取应答字进行复位
ReadLinerAnswer_InStore(taskInfo.taskCode);
result = true;
}
else
{
logHelper.Info($"仓库{taskInfo.storeCode}PLC未连接");
}
}
else
{
logHelper.Info($"PLC信息为空通过{taskInfo.storeCode}未获取到该仓库对应的PLC信息");
}
}
catch (Exception ex)
{
logHelper.Error("内胆入库任务下发异常", ex);
}
return result;
} }
/// <summary>
/// 读取内胆入库应答
/// </summary>
private void ReadLinerAnswer_InStore(string taskCode)
{
lock (string.Empty)
{
bool isFlag = true;
IPlc _plc = _plcDictionary[appConfig.shellStoreCode];
linerTaskCode = taskCode;
try
{
Task.Run(() =>
{
if (_plc != null)
{
if (_plc.IsConnected)
{
do
{
//读取PLC应答字为2时上位机清空写入的入库内容
if (_plc.readInt32ByAddress(plcConfig.in_liner_answer) == 2)
{
//写入货道号
_plc.writeStringByAddress(plcConfig.in_liner_spaceCode, string.Empty);
//写入应答字
_plc.writeInt32ByAddress(plcConfig.in_liner_answer, 0);
//写入任务号
_plc.writeStringByAddress(plcConfig.in_liner_task, string.Empty);
isFlag = false;
Thread.Sleep(5000);
ReadLinerFinish_InStore(taskCode);
}
} while (isFlag);
}
else
{
logHelper.Info($"仓库{appConfig.linerStoreCode}PLC未连接");
}
}
else
{
logHelper.Info($"PLC信息为空通过{appConfig.linerStoreCode}未获取到该仓库对应的PLC信息");
}
});
}
catch (Exception ex)
{
logHelper.Error("读取内胆入库应答字异常", ex);
}
}
}
/// <summary>
/// 读取内胆入库完成
/// </summary>
private void ReadLinerFinish_InStore(string taskCode)
{
lock (string.Empty)
{
try
{
Task.Run(() =>
{
bool isFlag = true;
IPlc _plc = _plcDictionary[appConfig.linerStoreCode];
if (_plc != null)
{
if (_plc.IsConnected)
{
do
{
//读取PLC入库任务完成
if (_plc.readInt32ByAddress(plcConfig.in_liner_finish) == 1)
{
_plc.writeInt32ByAddress(plcConfig.in_liner_finish, 0);
//string taskCode = _plc.readStringByAddress(plcConfig.in_liner_task, 10);
InStoreFinsihEvent?.Invoke(appConfig.linerStoreCode, taskCode);
isFlag = false;
Thread.Sleep(5000);
}
} while (isFlag);
}
else
{
logHelper.Info($"仓库{appConfig.linerStoreCode}PLC未连接");
}
}
else
{
logHelper.Info($"PLC信息为空通过{appConfig.linerStoreCode}未获取到该仓库对应的PLC信息");
}
});
}
catch (Exception ex)
{
logHelper.Error("读取内胆入库完成异常", ex);
}
}
}
#endregion
} }
} }

@ -3,12 +3,26 @@
箱壳PLC端口=6000 箱壳PLC端口=6000
内胆PLCIP=127.0.0.1 内胆PLCIP=127.0.0.1
内胆PLC端口=6000 内胆PLC端口=6000
#箱壳入库地址
[shell_inStore_address]
入库货道号=D101
入库应答字=D103
入库任务号=D104
入库完成=D105
#内胆入库地址
[liner_inStore_address]
入库货道号=D201
入库应答字=D203
入库任务号=D204
入库完成=D205
#箱壳出库地址
[shell_outStore_address] [shell_outStore_address]
出库货道号=M101 出库货道号=M101
出库数量=M102 出库数量=M102
出库应答字=M103 出库应答字=M103
出库任务号=M104 出库任务号=M104
出库完成=M105 出库完成=M105
#内胆出库地址
[liner_outStore_address] [liner_outStore_address]
出库货道号=M201 出库货道号=M201
出库数量=M202 出库数量=M202

@ -63,6 +63,82 @@ namespace HighWayIot.Config
} }
#endregion #endregion
#region 箱壳入库地址
/// <summary>
/// 箱壳——入库货道号
/// </summary>
public string in_shell_spaceCode
{
get { return iniHelper.IniReadValue("shell_inStore_address", "入库货道号"); }
set { iniHelper.IniWriteValue("shell_inStore_address", "入库货道号", value); }
}
/// <summary>
/// 箱壳——入库应答字
/// </summary>
public string in_shell_answer
{
get { return iniHelper.IniReadValue("shell_inStore_address", "入库应答字"); }
set { iniHelper.IniWriteValue("shell_inStore_address", "入库应答字", value); }
}
/// <summary>
/// 箱壳——入库任务号
/// </summary>
public string in_shell_task
{
get { return iniHelper.IniReadValue("shell_inStore_address", "入库任务号"); }
set { iniHelper.IniWriteValue("shell_inStore_address", "入库任务号", value); }
}
/// <summary>
/// 箱壳——入库完成
/// </summary>
public string in_shell_finish
{
get { return iniHelper.IniReadValue("shell_inStore_address", "入库完成"); }
set { iniHelper.IniWriteValue("shell_inStore_address", "入库完成", value); }
}
#endregion
#region 内胆入库地址
/// <summary>
/// 内胆——入库货道号
/// </summary>
public string in_liner_spaceCode
{
get { return iniHelper.IniReadValue("liner_inStore_address", "入库货道号"); }
set { iniHelper.IniWriteValue("liner_inStore_address", "入库货道号", value); }
}
/// <summary>
/// 内胆——入库应答字
/// </summary>
public string in_liner_answer
{
get { return iniHelper.IniReadValue("liner_inStore_address", "入库应答字"); }
set { iniHelper.IniWriteValue("liner_inStore_address", "入库应答字", value); }
}
/// <summary>
/// 内胆——入库任务号
/// </summary>
public string in_liner_task
{
get { return iniHelper.IniReadValue("liner_inStore_address", "入库任务号"); }
set { iniHelper.IniWriteValue("liner_inStore_address", "入库任务号", value); }
}
/// <summary>
/// 内胆——入库完成
/// </summary>
public string in_liner_finish
{
get { return iniHelper.IniReadValue("liner_inStore_address", "入库完成"); }
set { iniHelper.IniWriteValue("liner_inStore_address", "入库完成", value); }
}
#endregion
#region 箱壳出库地址 #region 箱壳出库地址
/// <summary> /// <summary>
/// 箱壳——出库货道号 /// 箱壳——出库货道号

Loading…
Cancel
Save