提交代码

This commit is contained in:
hehaibing-1996
2024-04-29 08:39:09 +08:00
parent a1199028b3
commit 97888c6978
46 changed files with 2303 additions and 255 deletions

View File

@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using TouchSocket.Core;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
@ -32,6 +34,22 @@ namespace WCS.BLL.HardWare
/// 自检模式
/// </summary>
public byte[] CheckModeData = { 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
/// <summary>
/// 进入出库模式
/// </summary>
public byte[] GoInOutstoreModeData = { 0x05, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00 };
public byte[] ComfirmOutstoreData = { 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
/// <summary>
/// 退出出库模式
/// </summary>
public byte[] GoOutOutstoreModeData = { 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
/// <summary>
/// 复位命令
/// </summary>
public byte[] ResetData = { 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
#endregion
public int ModuleId { get; set; }
public string ModuleCode { get; set; }
@ -90,11 +108,24 @@ namespace WCS.BLL.HardWare
}
else
{
//退出对应的模式 回到待机状态 并记录对应的状态日志(这个分支肯定是异常了)
//记录错误日志
//这里应该是状态异常的 正常不会是这种状态
Reset(tcpClient);
}
}
/// <summary>
/// 复位
/// </summary>
/// <param name="tcpClient"></param>
public void Reset(TCPClient tcpClient)
{
tcpClient.Send(tcpClient.GenerateMessage(BoardId, ResetData));
}
/// <summary>
/// 自检
/// </summary>
/// <param name="tcpClient"></param>
public void ShelfCheck(TCPClient tcpClient)
{
if (CurrentMode != Mode.)
@ -122,5 +153,68 @@ namespace WCS.BLL.HardWare
tcpClient.Send(tcpClient.GenerateMessage(BoardId, CheckModeData));
}
/// <summary>
/// 进入出库模式、亮灯
/// </summary>
/// <param name="tcpClient"></param>
public void GoInOutStoreMode(TCPClient tcpClient, List<string> outSns)
{
var storeInfos = DbHelp.db.Queryable<StoreInfo>()
.Where(t => t.BoardId == BoardId)
.OrderBy(t => t.LightNumber)
.ToList();
//计算物料在库的库位
char[] data = "0000000000000000".ToCharArray();
var storeNumber = storeInfos.Count();
foreach (var storeInfo in storeInfos)
{
if (!string.IsNullOrEmpty(storeInfo.CurrentMatSn) && storeInfo.LightNumber > 0 && storeInfo.LightNumber <= storeNumber)
{
data[storeInfo.LightNumber - 1] = '1';
}
}
var dataStr = string.Join("", data.Reverse());
var data1 = dataStr.Substring(8, 8);
var data2 = dataStr.Substring(0, 8);
GoInOutstoreModeData[1] = Convert.ToByte(data1, 2);
GoInOutstoreModeData[2] = Convert.ToByte(data2, 2);
//出库位置亮灯
if (outSns != null && outSns.Count > 0)
{
var outStoreInfos = storeInfos.Where(t => outSns.Contains(t.CurrentMatSn))
.ToList();
char[] outData = "0000000000000000".ToCharArray();
foreach (var storeInfo in outStoreInfos)
{
if (!string.IsNullOrEmpty(storeInfo.CurrentMatSn) && storeInfo.LightNumber > 0 && storeInfo.LightNumber <= storeNumber)
{
outData[storeInfo.LightNumber - 1] = '1';
}
}
var outDataStr = string.Join("", outData.Reverse());
var data3 = outDataStr.Substring(8, 8);
var data4 = outDataStr.Substring(0, 8);
GoInOutstoreModeData[3] = Convert.ToByte(data3, 2);
GoInOutstoreModeData[4] = Convert.ToByte(data4, 2);
}
tcpClient.Send(tcpClient.GenerateMessage(BoardId, GoInOutstoreModeData));
}
public void ComfirmOutstore(TCPClient tcpClient, byte lightNumber)
{
ComfirmOutstoreData[1] = lightNumber;
tcpClient.Send(tcpClient.GenerateMessage(BoardId, ComfirmOutstoreData));
}
/// <summary>
/// 退出出库模式
/// </summary>
/// <param name="tcpClient"></param>
public void GoOutOutStoreMode(TCPClient tcpClient)
{
tcpClient.Send(tcpClient.GenerateMessage(BoardId, GoOutOutstoreModeData));
}
}
}