移植后台关灯机制 超时退出模式关灯,灯状态不对的恢复

This commit is contained in:
hehaibing-1996
2024-05-29 14:23:01 +08:00
parent 4958c58706
commit d1914bb2d1
10 changed files with 233 additions and 30 deletions

View File

@ -42,6 +42,12 @@ namespace WCS.DAL.DbModels
[SugarColumn(ColumnName = "current_mode", IsNullable = false, ColumnDescription = "货架当前状态")] [SugarColumn(ColumnName = "current_mode", IsNullable = false, ColumnDescription = "货架当前状态")]
public Mode CurrentMode { get; set; } public Mode CurrentMode { get; set; }
/// <summary>
/// 货架设置当前模式的时间
/// </summary>
[SugarColumn(ColumnName = "set_current_mode_time", IsNullable = true, ColumnDescription = "设置货架当前模式的时间")]
public DateTime SetCurrentModeTime { get; set; }
/// <summary> /// <summary>
/// 货架行数 /// 货架行数
/// </summary> /// </summary>

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using WCS.BLL.DbModels; using WCS.BLL.DbModels;
using WCS.Model; using WCS.Model;
using static WCS.BLL.HardWare.WarningLight;
namespace WCS.BLL.HardWare namespace WCS.BLL.HardWare
{ {
@ -38,6 +39,7 @@ namespace WCS.BLL.HardWare
public int ColumnCounts { get; set; } public int ColumnCounts { get; set; }
public int LightId { get; set; } public int LightId { get; set; }
public LightColorEnum LightColor { get; set; }
public List<int> ModuleIds { get; set; } public List<int> ModuleIds { get; set; }
public List<SmartShelfModule> Modules { get; set; } public List<SmartShelfModule> Modules { get; set; }
public string ClientIp { get; set; } public string ClientIp { get; set; }
@ -45,6 +47,10 @@ namespace WCS.BLL.HardWare
/// 货架当前模式 /// 货架当前模式
/// </summary> /// </summary>
public Mode CurrentMode { get; set; } public Mode CurrentMode { get; set; }
/// <summary>
/// 设置到当前模式的时间
/// </summary>
public DateTime SetCurrentModeTime { get; set; }
public MatInfoResponse InStoreData { get; set; } public MatInfoResponse InStoreData { get; set; }
@ -68,7 +74,7 @@ namespace WCS.BLL.HardWare
/// <summary> /// <summary>
/// 设置货架模式 /// 设置货架模式
/// </summary> /// </summary>
public void SetCurrentMode(); public void SetCurrentMode(Mode mode);
/// <summary> /// <summary>
/// 货架进入入库模式 /// 货架进入入库模式
@ -99,7 +105,7 @@ namespace WCS.BLL.HardWare
/// <summary> /// <summary>
/// 货架单个确认盘点 /// 货架单个确认盘点
/// </summary> /// </summary>
public bool ConfirmStocktakingSingle(int BoardId,int LightNumber); public bool ConfirmStocktakingSingle(int BoardId, int LightNumber);
/// <summary> /// <summary>
/// 货架退出盘点模式 /// 货架退出盘点模式

View File

@ -15,6 +15,8 @@ namespace WCS.BLL.HardWare
= 0x01, = 0x01,
绿 = 0x02, 绿 = 0x02,
= 0x03, = 0x03,
//关闭仅用于后台暂存和判断使用 不用于协议
= 0x11,
} }
public enum LightModeEnum public enum LightModeEnum
{ {

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using WCS.BLL.DbModels; using WCS.BLL.DbModels;
using WCS.Model; using WCS.Model;
using static WCS.BLL.HardWare.WarningLight;
namespace WCS.BLL.HardWare namespace WCS.BLL.HardWare
{ {
@ -21,12 +22,14 @@ namespace WCS.BLL.HardWare
public string OrderNumber { get; set; } public string OrderNumber { get; set; }
public int LightId { get; set; } public int LightId { get; set; }
public LightColorEnum LightColor { get; set; }
public List<int> ModuleIds { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public List<int> ModuleIds { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string ClientIp { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public string ClientIp { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public List<string> ExceptionMessages { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public List<string> ExceptionMessages { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public bool IsWarning { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public bool IsWarning { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string WebSocketIpAddress { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public string WebSocketIpAddress { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public List<SmartShelfModule> Modules { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public List<SmartShelfModule> Modules { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public DateTime SetCurrentModeTime { get; set; }
public bool ConfirmStocktakingSingle(int BoardId, int LightNumber) public bool ConfirmStocktakingSingle(int BoardId, int LightNumber)
{ {
@ -41,33 +44,33 @@ namespace WCS.BLL.HardWare
public void GoInOutstore(List<OutOrderMatDetail> MatDetails, OutOrder outOrder) public void GoInOutstore(List<OutOrderMatDetail> MatDetails, OutOrder outOrder)
{ {
throw new NotImplementedException();
} }
public void GoInStocktaking() public void GoInStocktaking()
{ {
throw new NotImplementedException();
} }
public void GoInStocktaking(List<StockTakingOrderMatDetail> MatDetails, StockTakingOrder outOrder) public void GoInStocktaking(List<StockTakingOrderMatDetail> MatDetails, StockTakingOrder outOrder)
{ {
throw new NotImplementedException();
} }
public void GoOutInstore() public void GoOutInstore()
{ {
//找到已亮灯的 灭灯 //找到已亮灯的 灭灯
throw new NotImplementedException();
} }
public void GoOutOutstore() public void GoOutOutstore()
{ {
throw new NotImplementedException();
} }
public void GoOutStocktaking() public void GoOutStocktaking()
{ {
throw new NotImplementedException();
} }
public void Reset() public void Reset()
@ -75,19 +78,19 @@ namespace WCS.BLL.HardWare
return; return;
} }
public void SetCurrentMode() public void SetCurrentMode(Mode mode)
{ {
throw new NotImplementedException();
} }
public void ShelfCheck() public void ShelfCheck()
{ {
throw new NotImplementedException();
} }
public void Warning() public void Warning()
{ {
throw new NotImplementedException();
} }
} }
} }

View File

@ -1,4 +1,5 @@
using WCS.BLL.Config; using System;
using WCS.BLL.Config;
using WCS.BLL.DbModels; using WCS.BLL.DbModels;
using WCS.BLL.Manager; using WCS.BLL.Manager;
using WCS.DAL.Db; using WCS.DAL.Db;
@ -7,6 +8,7 @@ using WCS.Model;
using WCS.Model.ApiModel.InOutRecord; using WCS.Model.ApiModel.InOutRecord;
using WCS.Model.ApiModel.OutStore; using WCS.Model.ApiModel.OutStore;
using WCS.Model.WebSocketModel; using WCS.Model.WebSocketModel;
using static WCS.BLL.HardWare.WarningLight;
namespace WCS.BLL.HardWare namespace WCS.BLL.HardWare
{ {
@ -21,7 +23,8 @@ namespace WCS.BLL.HardWare
ShelfCode = shelfInfo.ShelfCode; ShelfCode = shelfInfo.ShelfCode;
RowCounts = shelfInfo.Rowcounts; RowCounts = shelfInfo.Rowcounts;
ColumnCounts = shelfInfo.Columncounts; ColumnCounts = shelfInfo.Columncounts;
CurrentMode = shelfInfo.CurrentMode; //CurrentMode = shelfInfo.CurrentMode;
SetCurrentMode(Mode.);
ClientIp = shelfInfo.ClientIp; ClientIp = shelfInfo.ClientIp;
LightId = shelfInfo.LightId; LightId = shelfInfo.LightId;
WarningLight = new WarningLight() { LightId = shelfInfo.LightId }; WarningLight = new WarningLight() { LightId = shelfInfo.LightId };
@ -53,12 +56,15 @@ namespace WCS.BLL.HardWare
public int RowCounts { get; set; } public int RowCounts { get; set; }
public int ColumnCounts { get; set; } public int ColumnCounts { get; set; }
public Mode CurrentMode { get; set; } public Mode CurrentMode { get; set; }
public DateTime SetCurrentModeTime { get; set; }
public string ModulesStr { get; set; }//当前货架所有模组的Str public string ModulesStr { get; set; }//当前货架所有模组的Str
public string GroupName { get; set; } public string GroupName { get; set; }
public List<SmartShelfModule> Modules { get; set; } = new List<SmartShelfModule>(); public List<SmartShelfModule> Modules { get; set; } = new List<SmartShelfModule>();
public TCPClient TcpCleint { get { return TCPClientManager.GetTCPClientByIPHost(ClientIp); } } public TCPClient TcpCleint { get { return TCPClientManager.GetTCPClientByIPHost(ClientIp); } }
public int LightId { get; set; } public int LightId { get; set; }
public LightColorEnum LightColor { get; set; }
public bool IsWarning { get; set; } = false; public bool IsWarning { get; set; } = false;
public WarningLight WarningLight { get; set; } public WarningLight WarningLight { get; set; }
public void ClearWarning() public void ClearWarning()
@ -124,7 +130,8 @@ namespace WCS.BLL.HardWare
} }
else else
{ {
this.CurrentMode = Mode.; //this.CurrentMode = Mode.入库模式;
SetCurrentMode(Mode.);
} }
//清空错误 //清空错误
ExceptionMessages.Clear(); ExceptionMessages.Clear();
@ -221,7 +228,8 @@ namespace WCS.BLL.HardWare
} }
else else
{ {
this.CurrentMode = Mode.; //this.CurrentMode = Mode.待机模式;
SetCurrentMode(Mode.);
} }
//清空错误 //清空错误
@ -258,7 +266,8 @@ namespace WCS.BLL.HardWare
.ToList(); .ToList();
if (list.Count > 0) if (list.Count > 0)
{ {
CurrentMode = Mode.; //CurrentMode = Mode.待机模式;
SetCurrentMode(Mode.);
foreach (var item in list) foreach (var item in list)
{ {
ExceptionMessages.Add($"模组{item.ModuleCode}未成功退出入库模式!"); ExceptionMessages.Add($"模组{item.ModuleCode}未成功退出入库模式!");
@ -295,7 +304,8 @@ namespace WCS.BLL.HardWare
//复位需要点时间间隔才能响应指令 //复位需要点时间间隔才能响应指令
Thread.Sleep(1500); Thread.Sleep(1500);
} }
CurrentMode = Mode.; //CurrentMode = Mode.出库模式;
SetCurrentMode(Mode.);
//第二步货架添加需要出的SN 出库的领料单号 //第二步货架添加需要出的SN 出库的领料单号
//移除货架所有现有待出库的MatSN //移除货架所有现有待出库的MatSN
@ -424,7 +434,8 @@ namespace WCS.BLL.HardWare
CurrentOutStoreMatSNs.Clear(); CurrentOutStoreMatSNs.Clear();
WarningLight.CloseLight(TcpCleint); WarningLight.CloseLight(TcpCleint);
this.CurrentMode = Mode.; //this.CurrentMode = Mode.待机模式;
SetCurrentMode(Mode.);
Logs.Write($"货架【{ShelfCode}】,结束退出出库", LogsType.Outstore); Logs.Write($"货架【{ShelfCode}】,结束退出出库", LogsType.Outstore);
} }
catch (Exception ex) catch (Exception ex)
@ -449,7 +460,8 @@ namespace WCS.BLL.HardWare
Thread.Sleep(1500); Thread.Sleep(1500);
} }
CurrentMode = Mode.; //CurrentMode = Mode.盘点模式;
SetCurrentMode(Mode.);
//第二步:货架添加 盘点单号 记录当前盘点的发料单 //第二步:货架添加 盘点单号 记录当前盘点的发料单
CurrentStockTakingOrder = stockTakingOrder; CurrentStockTakingOrder = stockTakingOrder;
@ -609,7 +621,8 @@ namespace WCS.BLL.HardWare
}); });
CurrentOutStoreMatSNs.Clear(); CurrentOutStoreMatSNs.Clear();
WarningLight.CloseLight(TcpCleint); WarningLight.CloseLight(TcpCleint);
this.CurrentMode = Mode.; //this.CurrentMode = Mode.待机模式;
SetCurrentMode(Mode.);
} }
public void Reset() public void Reset()
@ -623,7 +636,8 @@ namespace WCS.BLL.HardWare
}); });
} }
WarningLight.CloseLight(TcpCleint); WarningLight.CloseLight(TcpCleint);
this.CurrentMode = Mode.; //this.CurrentMode = Mode.待机模式;
SetCurrentMode(Mode.);
} }
public void QueryVoltage(int moduleId) public void QueryVoltage(int moduleId)
@ -635,9 +649,20 @@ namespace WCS.BLL.HardWare
} }
} }
void IShelfBase.SetCurrentMode() public void SetCurrentMode(Mode mode)
{ {
throw new NotImplementedException(); this.CurrentMode = mode;
this.SetCurrentModeTime = DateTime.Now;
Task.Run(() =>
{
var shelf = DbHelp.db.Queryable<ShelfInfo>().Where(t => t.Id == ShelfId).First();
if (shelf != null)
{
shelf.CurrentMode = mode;
shelf.SetCurrentModeTime = SetCurrentModeTime;
DbHelp.db.Updateable(shelf).ExecuteCommand();
}
});
} }
void IShelfBase.Warning() void IShelfBase.Warning()
@ -654,6 +679,39 @@ namespace WCS.BLL.HardWare
} }
#endregion #endregion
#region
public void WarningLightProcess(byte[] data, int boardId, int lightNumber)
{
if (data[TcpCleint.PreFixLength + 2] == 0x20 && data[TcpCleint.PreFixLength + 3] == 0x01)
{
//常亮或关闭 0x00常亮 0x01关闭
if (data[TcpCleint.PreFixLength + 5] == 0x00)
{
LightColor = LightColorEnum.;
Logs.Write($"货架[{ShelfCode}],灯状态更新为:{LightColor}");
}
else if (data[TcpCleint.PreFixLength + 5] == 0x01)
{
switch (data[7])
{
case 0x01:
LightColor = LightColorEnum.;
break;
case 0x02:
LightColor = LightColorEnum.绿;
break;
case 0x03:
LightColor = LightColorEnum.;
break;
default:
break;
}
Logs.Write($"货架[{ShelfCode}],灯状态更新为:{LightColor}");
}
}
}
#endregion
#region #region
public void ProtocolProcess(byte[] data, int boardId, int lightNumber) public void ProtocolProcess(byte[] data, int boardId, int lightNumber)
{ {
@ -1432,6 +1490,15 @@ namespace WCS.BLL.HardWare
//确认本次出库 //确认本次出库
module.ComfirmOutstore(TcpCleint, data[TcpCleint.PreFixLength + 3]); module.ComfirmOutstore(TcpCleint, data[TcpCleint.PreFixLength + 3]);
//更新时间 避免被自动退出
Task.Run(() =>
{
var shelves = ShelfManager.Shelves.Where(t => t.CurrentMode == Mode. && t.OrderNumber == OrderNumber).ToList();
foreach (var shelf in shelves)
{
shelf.SetCurrentModeTime = DateTime.Now;
}
});
//当前柜子是否还存在未出库的 //当前柜子是否还存在未出库的

View File

@ -1,10 +1,12 @@
using SqlSugar; using SqlSugar;
using WCS.BLL.Config; using WCS.BLL.Config;
using WCS.BLL.DbModels; using WCS.BLL.DbModels;
using WCS.BLL.HardWare;
using WCS.BLL.Tool; using WCS.BLL.Tool;
using WCS.DAL; using WCS.DAL;
using WCS.DAL.Db; using WCS.DAL.Db;
using WCS.DAL.Db.AuthDb; using WCS.DAL.Db.AuthDb;
using WCS.DAL.DbModels;
using WCS.Model; using WCS.Model;
using WCS.Model.ApiModel.InOutRecord; using WCS.Model.ApiModel.InOutRecord;
using WCS.Model.ApiModel.MXBackgroundThread; using WCS.Model.ApiModel.MXBackgroundThread;
@ -117,7 +119,54 @@ namespace WCS.BLL.Manager
#endregion #endregion
#region 退 #region 退
Task.Run(() =>
{
while (true)
{
//每10s一次
Thread.Sleep(10000);
try
{
#region
var inStoreShelf = ShelfManager.Shelves.Where(t => t.CurrentMode == Mode.)
.Where(t => DateTime.Now - t.SetCurrentModeTime >= TimeSpan.FromMinutes(3))
.ToList();
foreach (var shelf in inStoreShelf)
{
shelf.GoOutInstore();
Logs.Write($"【定时任务:定时退出模式】货架【{shelf.ShelfCode}】超时3min未退出入库模式系统后台自动退出");
}
#endregion
#region
//出库超过n分钟自动进入待机模式
var outStoreShelf = ShelfManager.Shelves.Where(t => t.CurrentMode == Mode.)
.Where(t => DateTime.Now - t.SetCurrentModeTime >= TimeSpan.FromMinutes(5))
.ToList();
foreach (var shelf in outStoreShelf)
{
shelf.GoOutOutstore();
Logs.Write($"【定时任务:定时退出模式】货架【{shelf.ShelfCode}】超时5min未退出出库模式系统后台自动退出");
}
#endregion
#region
var stockTakingShelf = ShelfManager.Shelves.Where(t => t.CurrentMode == Mode.)
.Where(t => DateTime.Now - t.SetCurrentModeTime >= TimeSpan.FromMinutes(5))
.ToList();
foreach (var shelf in stockTakingShelf)
{
shelf.GoOutStocktaking();
Logs.Write($"【定时任务:定时退出模式】货架【{shelf.ShelfCode}】超时5min未退出盘点模式系统后台自动退出");
}
#endregion
}
catch (Exception e)
{
Logs.Write("【定时任务:定时退出模式】" + e.Message,LogsType.Info);
}
}
});
#endregion #endregion
#region #region
@ -212,7 +261,64 @@ namespace WCS.BLL.Manager
}); });
#endregion #endregion
#region #region
//判断灯颜色和模式是否对应
Task.Run(() =>
{
while (true)
{
//间隔5秒查询一次
Thread.Sleep(5000);
try
{
//待机模式未关灯
var shelves = ShelfManager.Shelves.Where(t => t.CurrentMode == Mode. && t.LightColor != WarningLight.LightColorEnum.)
.Where(t => t.SetCurrentModeTime < DateTime.Now.AddSeconds(-5))
.ToList();
foreach (var shelf in shelves)
{
try
{
if (shelf is SmartShelf)
{
var smartShelf = (SmartShelf)shelf;
smartShelf?.WarningLight.CloseLight(smartShelf.TcpCleint);
Logs.Write($"【定时任务】:监测警示灯关灯机制,关【{shelf.ShelfCode}】灯发送指令成功!");
}
}
catch (Exception ex)
{
Logs.Write($"【定时任务】:监测警示灯关灯机制,关【{shelf.ShelfCode}】灯发生异常" + ex.Message);
}
}
//出库模式未亮灯
var outShelves = ShelfManager.Shelves.Where(t => t.CurrentMode == Mode. && t.LightColor == WarningLight.LightColorEnum.)
.Where(t => t.SetCurrentModeTime < DateTime.Now.AddSeconds(-5))
.ToList();
foreach (var shelf in outShelves)
{
try
{
if (shelf is SmartShelf)
{
var smartShelf = (SmartShelf)shelf;
smartShelf?.WarningLight.GreenLight(smartShelf.TcpCleint);
Logs.Write($"【定时任务】:监测警示灯关灯机制,出库开灯【{shelf.ShelfCode}】发送指令成功!");
}
}
catch (Exception ex)
{
Logs.Write($"【定时任务】:监测警示灯关灯机制,出库开灯【{shelf.ShelfCode}】发生异常" + ex.Message);
}
}
}
catch (Exception ex)
{
Logs.Write("【定时任务】:监测警示灯关灯机制发生异常" + ex.Message);
}
}
});
#endregion #endregion
} }

View File

@ -65,14 +65,14 @@ namespace WCS.BLL.Manager
//获取板子ID //获取板子ID
var boardId = (dataTemp[TcpCleint.PreFixLength + 0] << 8) + dataTemp[TcpCleint.PreFixLength + 1]; var boardId = (dataTemp[TcpCleint.PreFixLength + 0] << 8) + dataTemp[TcpCleint.PreFixLength + 1];
var lightNumber = Convert.ToInt32(dataTemp[TcpCleint.PreFixLength + 3]); var lightNumber = Convert.ToInt32(dataTemp[TcpCleint.PreFixLength + 3]);
//报警灯 //报警灯 返回来就修改对应的灯的颜色
if (dataTemp[TcpCleint.PreFixLength + 2] == 0x20) if (dataTemp[TcpCleint.PreFixLength + 2] == 0x20)
{ {
var shelf = ShelfManager.Shelves.Where(t => t.ClientIp == clientIpHost) var shelf = ShelfManager.Shelves.Where(t => t.ClientIp == clientIpHost)
.Where(t => t.LightId == boardId) .Where(t => t.LightId == boardId)
.FirstOrDefault(); .FirstOrDefault();
var smartShelf = shelf as SmartShelf; var smartShelf = shelf as SmartShelf;
smartShelf?.ProtocolProcess(dataTemp, boardId, lightNumber); smartShelf?.WarningLightProcess(dataTemp, boardId, lightNumber);
} }
//!= 0x20 货架类型协议返回 //!= 0x20 货架类型协议返回
else else

View File

@ -152,6 +152,8 @@ namespace WCS.BLL.Services.Service
Message = $"操作失败:货架[{request.ShelfCode}]不在入库模式!\r\n当前为{shelf.CurrentMode}", Message = $"操作失败:货架[{request.ShelfCode}]不在入库模式!\r\n当前为{shelf.CurrentMode}",
}; };
} }
//物料在入库模式,更新时间 避免被后台线程关闭
shelf.SetCurrentModeTime = DateTime.Now;
} }
#region //调用接口或者直接查询数据库 #region //调用接口或者直接查询数据库

View File

@ -788,10 +788,21 @@ namespace WCS.BLL.Services.Service
}; };
} }
shelf.ConfirmStocktakingSingle(stockTakingMatDetail.StoreInfo.BoardId, stockTakingMatDetail.StoreInfo.LightNumber); shelf.ConfirmStocktakingSingle(stockTakingMatDetail.StoreInfo.BoardId, stockTakingMatDetail.StoreInfo.LightNumber);
#endregion #endregion
DbHelp.db.CommitTran(); DbHelp.db.CommitTran();
//更新时间 避免被自动退出
Task.Run(() =>
{
var shelves = ShelfManager.Shelves.Where(t => t.CurrentMode == HardWare.Mode. && t.OrderNumber == request.StocktakingOrderNumber)
.ToList();
foreach (var shelf in shelves)
{
shelf.SetCurrentModeTime = DateTime.Now;
}
});
#region Order状态 #region Order状态
Task.Run(() => Task.Run(() =>
{ {

View File

@ -132,7 +132,7 @@
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<StackPanel> <StackPanel>
<Ellipse Width="20" Height="20" Fill="LightGreen" Visibility="{Binding IsSended,Converter={StaticResource Boolean2VisibilityConverter}}"></Ellipse> <Ellipse Width="20" Height="20" Fill="Green" Visibility="{Binding IsSended,Converter={StaticResource Boolean2VisibilityConverter}}"></Ellipse>
<Ellipse Width="20" Height="20" Fill="Gray" Visibility="{Binding IsSended,Converter={StaticResource Boolean2VisibilityReConverter}}"></Ellipse> <Ellipse Width="20" Height="20" Fill="Gray" Visibility="{Binding IsSended,Converter={StaticResource Boolean2VisibilityReConverter}}"></Ellipse>
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>