液晶标签协议对接!
This commit is contained in:
@ -18,6 +18,11 @@ namespace WCS.BLL.HardWare
|
|||||||
/// 货架是否处于报警中
|
/// 货架是否处于报警中
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsWarning { get; set; }
|
public bool IsWarning { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 货架类型名称
|
||||||
|
/// </summary>
|
||||||
|
public string ShelfTypeName { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 货架ID 数据库中那个
|
/// 货架ID 数据库中那个
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -19,6 +19,7 @@ namespace WCS.BLL.HardWare
|
|||||||
{
|
{
|
||||||
public MXL4Shelf(ShelfInfo shelfInfo)
|
public MXL4Shelf(ShelfInfo shelfInfo)
|
||||||
{
|
{
|
||||||
|
ShelfTypeName = shelfInfo.ShelfTypeName;
|
||||||
ShelfId = shelfInfo.Id;
|
ShelfId = shelfInfo.Id;
|
||||||
ShelfCode = shelfInfo.ShelfCode;
|
ShelfCode = shelfInfo.ShelfCode;
|
||||||
RowCounts = shelfInfo.Rowcounts;
|
RowCounts = shelfInfo.Rowcounts;
|
||||||
@ -49,22 +50,19 @@ namespace WCS.BLL.HardWare
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ShelfTypeName { get; set; }
|
||||||
public int ShelfId { get; set; }
|
public int ShelfId { get; set; }
|
||||||
public string ShelfCode { get; set; }
|
public string ShelfCode { get; set; }
|
||||||
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 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 List<MXL4ShelfModule> MXL4Modules { get; set; } = new List<MXL4ShelfModule>();
|
public List<MXL4ShelfModule> MXL4Modules { get; set; } = new List<MXL4ShelfModule>();
|
||||||
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 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; }
|
||||||
@ -114,10 +112,11 @@ namespace WCS.BLL.HardWare
|
|||||||
public string WebSocketIpAddress { get; set; } = "127.0.0.2";
|
public string WebSocketIpAddress { get; set; } = "127.0.0.2";
|
||||||
|
|
||||||
public string OutOperateUser { get; set; } = string.Empty;
|
public string OutOperateUser { get; set; } = string.Empty;
|
||||||
|
|
||||||
#region 协议处理
|
#region 协议处理
|
||||||
public void GoInInstore(string? IPAddress)
|
public void GoInInstore(string? IPAddress)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GoOutInstore()
|
public void GoOutInstore()
|
||||||
@ -131,20 +130,20 @@ namespace WCS.BLL.HardWare
|
|||||||
/// <param name="ModuleId"></param>
|
/// <param name="ModuleId"></param>
|
||||||
public void GoInOutstoreByWebSocket(int moduleId)
|
public void GoInOutstoreByWebSocket(int moduleId)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
public void GoInOutstore(List<OutOrderMatDetail> MatDetails, OutOrder outOrder, string OperateUser)
|
public void GoInOutstore(List<OutOrderMatDetail> MatDetails, OutOrder outOrder, string OperateUser)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
public void GoOutOutstore()
|
public void GoOutOutstore()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GoInStocktaking(List<StockTakingOrderMatDetail> MatDetails, StockTakingOrder stockTakingOrder)
|
public void GoInStocktaking(List<StockTakingOrderMatDetail> MatDetails, StockTakingOrder stockTakingOrder)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 确认盘点 Pda进行触发
|
/// 确认盘点 Pda进行触发
|
||||||
@ -155,12 +154,12 @@ namespace WCS.BLL.HardWare
|
|||||||
}
|
}
|
||||||
public void GoOutStocktaking()
|
public void GoOutStocktaking()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
|
MXL4Modules.ForEach(t => t.Reset(TcpCleint));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void QueryVoltage(int moduleId)
|
public void QueryVoltage(int moduleId)
|
||||||
@ -196,7 +195,7 @@ namespace WCS.BLL.HardWare
|
|||||||
|
|
||||||
public void ShelfCheck()
|
public void ShelfCheck()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ using WCS.DAL.DbModels;
|
|||||||
|
|
||||||
namespace WCS.BLL.HardWare
|
namespace WCS.BLL.HardWare
|
||||||
{
|
{
|
||||||
public class MXL4ShelfModule : IModuleBase
|
public class MXL4ShelfModule
|
||||||
{
|
{
|
||||||
#region 协议
|
#region 协议
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -20,79 +20,45 @@ namespace WCS.BLL.HardWare
|
|||||||
public byte[] ResetData = { 0xBE, 0x52, 0x54, 0x41, 0x52, 0x54, 0x0A, 0xED };
|
public byte[] ResetData = { 0xBE, 0x52, 0x54, 0x41, 0x52, 0x54, 0x0A, 0xED };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 进入入库模式
|
/// 发送任务ID 0x01改为实际发送的任务ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[] GoInInstoreData = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
public byte[] SendTaskIdData = { 0xAA, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 确认入库
|
/// 发送料号信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[] ComfirmInstoreData = { 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
public byte[] SendMatCodeData = { 0xA5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
public byte[] ComfirmErrInstoreData = { 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 退出入库模式
|
/// 发送名称信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[] GoOutInstoreData = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
public byte[] SendMatNameData = { 0xA6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 自检模式
|
/// 发送规格信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[] CheckModeData = { 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
public byte[] SendMatSpecData = { 0xA7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发送批次信息
|
||||||
|
/// </summary>
|
||||||
|
public byte[] SendMatBatchData = { 0xA8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发送数量信息
|
||||||
|
/// </summary>
|
||||||
|
public byte[] SendMatQtyData = { 0xA9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 进入出库模式
|
/// 进入出库模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[] GoInOutstoreModeData = { 0x05, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00 };
|
public byte[] GoInOutstoreModeData = { 0xA2, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 确认出库信号
|
|
||||||
/// </summary>
|
|
||||||
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>
|
|
||||||
/// 进入盘点模式
|
|
||||||
/// 04代表颜色为蓝色色
|
|
||||||
/// </summary>
|
|
||||||
public byte[] GoInStockTakingModeData = { 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00 };
|
|
||||||
/// <summary>
|
|
||||||
/// 确认盘点
|
|
||||||
/// 03代表颜色为黄色
|
|
||||||
/// </summary>
|
|
||||||
public byte[] ConfirmStockTakingData = { 0x09, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 };
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 退出盘点模式
|
|
||||||
/// </summary>
|
|
||||||
public byte[] GoOutStockTakingModeData = { 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查询当前电压值
|
|
||||||
/// </summary>
|
|
||||||
public byte[] VoltageSingleData = { 0x17, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
/// <summary>
|
|
||||||
/// 查询电压偏移值
|
|
||||||
/// </summary>
|
|
||||||
public byte[] OffsetSingleData = { 0x18, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
/// <summary>
|
|
||||||
/// 查询电压标准值
|
|
||||||
/// </summary>
|
|
||||||
public byte[] StandardSingleData = { 0x19, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 标定
|
|
||||||
/// </summary>
|
|
||||||
public byte[] CalibrationData = { 0x0D, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
/// <summary>
|
|
||||||
/// 设置偏移量 01 F4 = 500
|
|
||||||
/// </summary>
|
|
||||||
public byte[] SetOffsetData = { 0x0E, 0x0A, 0x01, 0xF4, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
public int ModuleId { get; set; }
|
public int ModuleId { get; set; }
|
||||||
@ -112,73 +78,15 @@ namespace WCS.BLL.HardWare
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GoInInstoreMode(TCPClient tcpClient)
|
|
||||||
|
#region 液晶标签存在的协议
|
||||||
|
/// <summary>
|
||||||
|
/// 进入出库模式
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tcpClient"></param>
|
||||||
|
public void GoInOutstoreMode(TCPClient tcpClient)
|
||||||
{
|
{
|
||||||
if (CurrentMode != Mode.待机模式)
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, GoInOutstoreModeData));
|
||||||
{
|
|
||||||
//TO DO 退出对应的模式 然后再发送进入入库模式
|
|
||||||
}
|
|
||||||
var storeInfos = DbHelp.db.Queryable<StoreInfo>()
|
|
||||||
.Where(t => t.ModuleId == ModuleId)
|
|
||||||
.Where(t => t.BoardId == BoardId)
|
|
||||||
.OrderBy(t => t.LightNumber)
|
|
||||||
.ToList();
|
|
||||||
char[] data = "0000000000000000".ToCharArray();
|
|
||||||
|
|
||||||
//禁用
|
|
||||||
char[] dataBan = "0000000000000000".ToCharArray();
|
|
||||||
|
|
||||||
var boardStoreNumber = storeInfos.Count();
|
|
||||||
foreach (var storeInfo in storeInfos)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(storeInfo.CurrentMatSn) && storeInfo.LightNumber > 0 && storeInfo.LightNumber <= boardStoreNumber)
|
|
||||||
{
|
|
||||||
data[storeInfo.LightNumber - 1] = '1';
|
|
||||||
|
|
||||||
//禁用
|
|
||||||
if (storeInfo.CurrentMatSn == "禁用")
|
|
||||||
{
|
|
||||||
dataBan[storeInfo.LightNumber - 1] = '1';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var dataStr = string.Join("", data.Reverse());
|
|
||||||
var data1 = dataStr.Substring(8, 8);
|
|
||||||
var data2 = dataStr.Substring(0, 8);
|
|
||||||
GoInInstoreData[1] = Convert.ToByte(data1, 2);
|
|
||||||
GoInInstoreData[2] = Convert.ToByte(data2, 2);
|
|
||||||
|
|
||||||
//禁用
|
|
||||||
var dataBanStr = string.Join("", dataBan.Reverse());
|
|
||||||
var data1Ban = dataBanStr.Substring(8, 8);
|
|
||||||
var data2Ban = dataBanStr.Substring(0, 8);
|
|
||||||
GoInInstoreData[6] = Convert.ToByte(data1Ban, 2);
|
|
||||||
GoInInstoreData[7] = Convert.ToByte(data2Ban, 2);
|
|
||||||
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, GoInInstoreData));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ComfirmInstore(TCPClient tcpClient)
|
|
||||||
{
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, ComfirmInstoreData));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ComfirmErrInstore(TCPClient tcpClient)
|
|
||||||
{
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, ComfirmErrInstoreData));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void GoOutInstoreMode(TCPClient tcpClient)
|
|
||||||
{
|
|
||||||
if (CurrentMode == Mode.入库模式)
|
|
||||||
{
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, GoOutInstoreData));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//这里应该是状态异常的 正常不会是这种状态
|
|
||||||
Reset(tcpClient);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -187,310 +95,53 @@ namespace WCS.BLL.HardWare
|
|||||||
/// <param name="tcpClient"></param>
|
/// <param name="tcpClient"></param>
|
||||||
public void Reset(TCPClient tcpClient)
|
public void Reset(TCPClient tcpClient)
|
||||||
{
|
{
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, ResetData));
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, ResetData));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
//发送任务ID
|
||||||
/// 自检
|
public void SendTaskId(int taskID, TCPClient tcpClient)
|
||||||
/// </summary>
|
|
||||||
/// <param name="tcpClient"></param>
|
|
||||||
public void ShelfCheck(TCPClient tcpClient)
|
|
||||||
{
|
{
|
||||||
if (CurrentMode != Mode.待机模式)
|
var taskIDData = Convert.ToByte(taskID);
|
||||||
{
|
SendTaskIdData[1] = taskIDData;
|
||||||
return;
|
|
||||||
}
|
|
||||||
var storeInfos = DbHelp.db.Queryable<StoreInfo>()
|
|
||||||
.Where(t => t.ModuleId == ModuleId)
|
|
||||||
.Where(t => t.BoardId == BoardId)
|
|
||||||
.OrderBy(t => t.LightNumber)
|
|
||||||
.ToList();
|
|
||||||
char[] data = "0000000000000000".ToCharArray();
|
|
||||||
//禁用功能
|
|
||||||
char[] dataBan = "0000000000000000".ToCharArray();
|
|
||||||
|
|
||||||
var boardStoreNumber = storeInfos.Count();
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, SendTaskIdData));
|
||||||
foreach (var storeInfo in storeInfos)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(storeInfo.CurrentMatSn) && storeInfo.LightNumber > 0 && storeInfo.LightNumber <= boardStoreNumber)
|
|
||||||
{
|
|
||||||
data[storeInfo.LightNumber - 1] = '1';
|
|
||||||
|
|
||||||
//禁用功能
|
|
||||||
if (storeInfo.CurrentMatSn == "禁用")
|
|
||||||
{
|
|
||||||
dataBan[storeInfo.LightNumber - 1] = '1';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var dataStr = string.Join("", data.Reverse());
|
|
||||||
var data1 = dataStr.Substring(8, 8);
|
|
||||||
var data2 = dataStr.Substring(0, 8);
|
|
||||||
CheckModeData[1] = Convert.ToByte(data1, 2);
|
|
||||||
CheckModeData[2] = Convert.ToByte(data2, 2);
|
|
||||||
|
|
||||||
//禁用功能
|
|
||||||
var dataBanStr = string.Join("", dataBan.Reverse());
|
|
||||||
var data1Ban = dataBanStr.Substring(8, 8);
|
|
||||||
var data2Ban = dataBanStr.Substring(0, 8);
|
|
||||||
CheckModeData[6] = Convert.ToByte(data1Ban, 2);
|
|
||||||
CheckModeData[7] = Convert.ToByte(data2Ban, 2);
|
|
||||||
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, CheckModeData));
|
|
||||||
}
|
}
|
||||||
|
//发送料号
|
||||||
/// <summary>
|
public void SendMatCode(string matCode, TCPClient tcpClient)
|
||||||
/// 进入出库模式、亮灯
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="tcpClient"></param>
|
|
||||||
public void GoInOutStoreMode(TCPClient tcpClient, List<string> outSns)
|
|
||||||
{
|
{
|
||||||
Logs.Write($"模组{ModuleCode},本次亮灯物料{string.Join(",", outSns)}", LogsType.Outstore);
|
tcpClient.SendThenReturnList(tcpClient.GenerateMessageList(BoardId, SendMatCodeData, matCode));
|
||||||
CurrentOutSns = outSns;
|
|
||||||
var storeInfos = DbHelp.db.Queryable<StoreInfo>().Where(t => t.ModuleId == ModuleId)
|
|
||||||
.Where(t => t.BoardId == BoardId)
|
|
||||||
.OrderBy(t => t.LightNumber)
|
|
||||||
.ToList();
|
|
||||||
//计算物料在库的库位
|
|
||||||
char[] data = "0000000000000000".ToCharArray();
|
|
||||||
|
|
||||||
//计算禁用的库位
|
|
||||||
char[] dataBan = "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';
|
|
||||||
//禁用
|
|
||||||
if (storeInfo.CurrentMatSn == "禁用")
|
|
||||||
{
|
|
||||||
dataBan[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);
|
|
||||||
|
|
||||||
//禁用
|
|
||||||
var dataBanStr = string.Join("", dataBan.Reverse());
|
|
||||||
var data1Ban = dataBanStr.Substring(8, 8);
|
|
||||||
var data2Ban = dataBanStr.Substring(0, 8);
|
|
||||||
GoInOutstoreModeData[6] = Convert.ToByte(data1Ban, 2);
|
|
||||||
GoInOutstoreModeData[7] = Convert.ToByte(data2Ban, 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);
|
|
||||||
|
|
||||||
if (LocalFile.Config.IsSameMatCodeOut)
|
|
||||||
{
|
|
||||||
GoInOutstoreModeData[5] = LocalStatic.CurrentOutStoreColor;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GoInOutstoreModeData[5] = 0x02;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, GoInOutstoreModeData));
|
|
||||||
}
|
}
|
||||||
public void ComfirmOutstore(TCPClient tcpClient, byte lightNumber)
|
//发送名称
|
||||||
|
public void SendMatName(string matName, TCPClient tcpClient)
|
||||||
{
|
{
|
||||||
ComfirmOutstoreData[1] = lightNumber;
|
tcpClient.SendThenReturnList(tcpClient.GenerateMessageList(BoardId, SendMatNameData, matName));
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, ComfirmOutstoreData));
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
//发送规格
|
||||||
/// 退出出库模式
|
public void SendMatSpec(string matSpec, TCPClient tcpClient)
|
||||||
/// </summary>
|
|
||||||
/// <param name="tcpClient"></param>
|
|
||||||
public void GoOutOutStoreMode(TCPClient tcpClient)
|
|
||||||
{
|
{
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, GoOutOutstoreModeData));
|
tcpClient.SendThenReturnList(tcpClient.GenerateMessageList(BoardId, SendMatSpecData, matSpec));
|
||||||
}
|
}
|
||||||
|
//发送批次
|
||||||
/// <summary>
|
public void SendMatBatch(string matBatch, TCPClient tcpClient)
|
||||||
/// 未盘点的物料进入盘点模式、亮灯
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="tcpClient"></param>
|
|
||||||
public void GoInStockTakingMode(TCPClient tcpClient, List<string> stockTakingSns)
|
|
||||||
{
|
{
|
||||||
CurrentStockTakingSns = stockTakingSns;
|
tcpClient.SendThenReturnList(tcpClient.GenerateMessageList(BoardId, SendMatBatchData, matBatch));
|
||||||
|
|
||||||
var storeInfos = DbHelp.db.Queryable<StoreInfo>().Where(t => t.ModuleId == ModuleId)
|
|
||||||
.Where(t => t.BoardId == BoardId)
|
|
||||||
.OrderBy(t => t.LightNumber)
|
|
||||||
.ToList();
|
|
||||||
//计算物料在库的库位
|
|
||||||
char[] data = "0000000000000000".ToCharArray();
|
|
||||||
var storeNumber = storeInfos.Count();
|
|
||||||
|
|
||||||
char[] outData = "0000000000000000".ToCharArray();
|
|
||||||
//盘点位置亮灯
|
|
||||||
if (stockTakingSns != null && stockTakingSns.Count > 0)
|
|
||||||
{
|
|
||||||
var outStoreInfos = storeInfos.Where(t => stockTakingSns.Contains(t.CurrentMatSn))
|
|
||||||
.ToList();
|
|
||||||
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);
|
|
||||||
GoInStockTakingModeData[2] = Convert.ToByte(data3, 2);
|
|
||||||
GoInStockTakingModeData[3] = Convert.ToByte(data4, 2);
|
|
||||||
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, GoInStockTakingModeData));
|
|
||||||
}
|
}
|
||||||
|
//发送数量
|
||||||
/// <summary>
|
public void SendMatQty(int matQty, TCPClient tcpClient)
|
||||||
/// 已确认过的物料
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="tcpClient"></param>
|
|
||||||
public void ConfirmStockTaking(TCPClient tcpClient, List<string> stockTakingSns)
|
|
||||||
{
|
{
|
||||||
CurrentStockTakingSns = stockTakingSns;
|
var boardIdData = BitConverter.GetBytes(unchecked((short)matQty));
|
||||||
|
|
||||||
var storeInfos = DbHelp.db.Queryable<StoreInfo>().Where(t => t.ModuleId == ModuleId)
|
|
||||||
.Where(t => t.BoardId == BoardId)
|
|
||||||
.OrderBy(t => t.LightNumber)
|
|
||||||
.ToList();
|
|
||||||
//计算物料在库的库位
|
|
||||||
char[] data = "0000000000000000".ToCharArray();
|
|
||||||
var storeNumber = storeInfos.Count();
|
|
||||||
|
|
||||||
char[] outData = "0000000000000000".ToCharArray();
|
|
||||||
//盘点位置亮灯
|
|
||||||
if (stockTakingSns != null && stockTakingSns.Count > 0)
|
|
||||||
{
|
|
||||||
var outStoreInfos = storeInfos.Where(t => stockTakingSns.Contains(t.CurrentMatSn))
|
|
||||||
.ToList();
|
|
||||||
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);
|
|
||||||
ConfirmStockTakingData[2] = Convert.ToByte(data3, 2);
|
|
||||||
ConfirmStockTakingData[3] = Convert.ToByte(data4, 2);
|
|
||||||
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, ConfirmStockTakingData));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 单个确认物料
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="tcpClient"></param>
|
|
||||||
public void ConfirmStockTakingSingle(TCPClient tcpClient, int lightNumber)
|
|
||||||
{
|
|
||||||
var storeInfos = DbHelp.db.Queryable<StoreInfo>().Where(t => t.ModuleId == ModuleId)
|
|
||||||
.Where(t => t.BoardId == BoardId)
|
|
||||||
.OrderBy(t => t.LightNumber)
|
|
||||||
.ToList();
|
|
||||||
//计算物料在库的库位
|
|
||||||
char[] data = "0000000000000000".ToCharArray();
|
|
||||||
var storeNumber = storeInfos.Count();
|
|
||||||
|
|
||||||
//盘点位置亮灯
|
|
||||||
var outStoreInfos = storeInfos.Where(t => t.LightNumber == lightNumber)
|
|
||||||
.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);
|
|
||||||
ConfirmStockTakingData[2] = Convert.ToByte(data3, 2);
|
|
||||||
ConfirmStockTakingData[3] = Convert.ToByte(data4, 2);
|
|
||||||
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, ConfirmStockTakingData));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 退出盘点模式
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="tcpClient"></param>
|
|
||||||
public void GoOutStockTakingMode(TCPClient tcpClient)
|
|
||||||
{
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, GoOutStockTakingModeData));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ComfirmStockTaking(TCPClient tcpClient, byte lightNumber)
|
|
||||||
{
|
|
||||||
ComfirmOutstoreData[1] = lightNumber;
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, ComfirmOutstoreData));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 查询电压值
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="tcpClient"></param>
|
|
||||||
public void QueryVoltage(TCPClient tcpClient)
|
|
||||||
{
|
|
||||||
Thread.Sleep(10);
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, VoltageSingleData));
|
|
||||||
Thread.Sleep(50);
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, StandardSingleData));
|
|
||||||
Thread.Sleep(50);
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, OffsetSingleData));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CalibrationSetOffset(int offSet, TCPClient tcpClient)
|
|
||||||
{
|
|
||||||
var offSetData = BitConverter.GetBytes(unchecked((short)offSet));
|
|
||||||
// 检查是否需要交换字节
|
// 检查是否需要交换字节
|
||||||
if (BitConverter.IsLittleEndian)
|
if (BitConverter.IsLittleEndian)
|
||||||
{
|
{
|
||||||
// 如果是小端序系统,则交换字节
|
// 如果是小端序系统,则交换字节
|
||||||
byte temp = offSetData[0];
|
byte temp = boardIdData[0];
|
||||||
offSetData[0] = offSetData[1];
|
boardIdData[0] = boardIdData[1];
|
||||||
offSetData[1] = temp;
|
boardIdData[1] = temp;
|
||||||
}
|
}
|
||||||
|
SendMatQtyData[1] = boardIdData[0];
|
||||||
SetOffsetData[2] = offSetData[0];
|
SendMatQtyData[2] = boardIdData[1];
|
||||||
SetOffsetData[3] = offSetData[1];
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, SendMatQtyData));
|
||||||
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, CalibrationData));
|
|
||||||
Thread.Sleep(100);
|
|
||||||
tcpClient.Send(tcpClient.GenerateMessage(BoardId, SetOffsetData));
|
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,10 @@ namespace WCS.BLL.HardWare
|
|||||||
SetCurrentMode(Mode.待机模式);
|
SetCurrentMode(Mode.待机模式);
|
||||||
ClientIp = shelfInfo.ClientIp;
|
ClientIp = shelfInfo.ClientIp;
|
||||||
LightId = shelfInfo.LightId;
|
LightId = shelfInfo.LightId;
|
||||||
}
|
|
||||||
|
|
||||||
|
ShelfTypeName = shelfInfo.ShelfTypeName;
|
||||||
|
}
|
||||||
|
public string ShelfTypeName { get; set; }
|
||||||
public int ShelfId { get; set; }
|
public int ShelfId { get; set; }
|
||||||
public string ShelfCode { get; set; }
|
public string ShelfCode { get; set; }
|
||||||
public int RowCounts { get; set; }
|
public int RowCounts { get; set; }
|
||||||
@ -48,6 +50,9 @@ namespace WCS.BLL.HardWare
|
|||||||
|
|
||||||
public TCPClient TcpCleint { get { return TCPClientManager.GetTCPClientByIPHost(ClientIp); } }
|
public TCPClient TcpCleint { get { return TCPClientManager.GetTCPClientByIPHost(ClientIp); } }
|
||||||
|
|
||||||
|
public List<MXL4ShelfModule> MXL4Modules { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||||
|
|
||||||
|
|
||||||
public bool ConfirmStocktakingSingle(int BoardId, int LightNumber)
|
public bool ConfirmStocktakingSingle(int BoardId, int LightNumber)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
@ -27,26 +27,27 @@ namespace WCS.BLL.HardWare
|
|||||||
ClientIp = shelfInfo.ClientIp;
|
ClientIp = shelfInfo.ClientIp;
|
||||||
LightId = shelfInfo.LightId;
|
LightId = shelfInfo.LightId;
|
||||||
WarningLight = new WarningLight() { LightId = shelfInfo.LightId };
|
WarningLight = new WarningLight() { LightId = shelfInfo.LightId };
|
||||||
|
ShelfTypeName = shelfInfo.ShelfTypeName;
|
||||||
|
|
||||||
//初始化Module
|
//初始化Module
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
|
||||||
var modules = DbHelp.db.Queryable<ModuleInfo>().Where(t => t.ShelfId == ShelfId).ToList();
|
|
||||||
foreach (var module in modules)
|
|
||||||
{
|
{
|
||||||
Modules.Add(new SmartShelfModule()
|
var modules = DbHelp.db.Queryable<ModuleInfo>().Where(t => t.ShelfId == ShelfId).ToList();
|
||||||
|
foreach (var module in modules)
|
||||||
{
|
{
|
||||||
ModuleId = module.Id,
|
Modules.Add(new SmartShelfModule()
|
||||||
ModuleCode = module.ModuleCode,
|
{
|
||||||
BoardId = module.BoardId,
|
ModuleId = module.Id,
|
||||||
IsEnable = module.IsEnable,
|
ModuleCode = module.ModuleCode,
|
||||||
CurrentMode = module.CurrentMode
|
BoardId = module.BoardId,
|
||||||
});
|
IsEnable = module.IsEnable,
|
||||||
}
|
CurrentMode = module.CurrentMode
|
||||||
ModulesStr = string.Join(";", Modules.Select(t => t.ModuleCode));
|
});
|
||||||
|
}
|
||||||
|
ModulesStr = string.Join(";", Modules.Select(t => t.ModuleCode));
|
||||||
|
|
||||||
ModuleIds = Modules.Select(t => t.BoardId).ToList();
|
ModuleIds = Modules.Select(t => t.BoardId).ToList();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -113,6 +114,9 @@ namespace WCS.BLL.HardWare
|
|||||||
public string WebSocketIpAddress { get; set; } = "127.0.0.2";
|
public string WebSocketIpAddress { get; set; } = "127.0.0.2";
|
||||||
|
|
||||||
public string OutOperateUser { get; set; } = string.Empty;
|
public string OutOperateUser { get; set; } = string.Empty;
|
||||||
|
public List<MXL4ShelfModule> MXL4Modules { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||||
|
public string ShelfTypeName { get; set; }
|
||||||
|
|
||||||
#region 协议处理
|
#region 协议处理
|
||||||
public void GoInInstore(string? IPAddress)
|
public void GoInInstore(string? IPAddress)
|
||||||
{
|
{
|
||||||
@ -337,7 +341,7 @@ namespace WCS.BLL.HardWare
|
|||||||
if (module.CurrentOutSns == null || module.CurrentOutSns.Count == 0)
|
if (module.CurrentOutSns == null || module.CurrentOutSns.Count == 0)
|
||||||
{
|
{
|
||||||
Logs.Write($"GoInOutstoreByModule货架【{ShelfCode}】,模组【{module.ModuleCode}】,不存在需要继续出的物料,给其复位。", LogsType.Outstore);
|
Logs.Write($"GoInOutstoreByModule货架【{ShelfCode}】,模组【{module.ModuleCode}】,不存在需要继续出的物料,给其复位。", LogsType.Outstore);
|
||||||
|
|
||||||
//不需要这个模组继续亮灯了
|
//不需要这个模组继续亮灯了
|
||||||
module.GoOutOutStoreMode(TcpCleint);
|
module.GoOutOutStoreMode(TcpCleint);
|
||||||
Thread.Sleep(400);
|
Thread.Sleep(400);
|
||||||
@ -1467,11 +1471,7 @@ namespace WCS.BLL.HardWare
|
|||||||
SolvedGuids = warnings.Select(t => t.Guid).ToList(),
|
SolvedGuids = warnings.Select(t => t.Guid).ToList(),
|
||||||
};
|
};
|
||||||
WarningManager.SendWarning(warningModel);
|
WarningManager.SendWarning(warningModel);
|
||||||
//自动消除本地缓存的报警
|
|
||||||
warnings.ForEach(warning =>
|
|
||||||
{
|
|
||||||
WarningManager.ClearWarning(warning, SolveTypeEnum.忽略);
|
|
||||||
});
|
|
||||||
|
|
||||||
ProcessingExceptions.RemoveAll(t => t.BoardId == boardId);
|
ProcessingExceptions.RemoveAll(t => t.BoardId == boardId);
|
||||||
}
|
}
|
||||||
@ -2140,12 +2140,6 @@ namespace WCS.BLL.HardWare
|
|||||||
SolvedGuids = warnings.Select(t => t.Guid).ToList(),
|
SolvedGuids = warnings.Select(t => t.Guid).ToList(),
|
||||||
};
|
};
|
||||||
WarningManager.SendWarning(warningModel);
|
WarningManager.SendWarning(warningModel);
|
||||||
//自动消除本地缓存的报警
|
|
||||||
warnings.ForEach(warning =>
|
|
||||||
{
|
|
||||||
Logs.Write($"ClearWarning,{warning.Guid}", LogsType.Outstore);
|
|
||||||
WarningManager.ClearWarning(warning, SolveTypeEnum.忽略);
|
|
||||||
});
|
|
||||||
ProcessingExceptions.RemoveAll(t => t.BoardId == boardId);
|
ProcessingExceptions.RemoveAll(t => t.BoardId == boardId);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -48,7 +48,7 @@ namespace WCS.BLL.Manager
|
|||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
var tcpCleint = new TCPClient(cleientInDB.IP, cleientInDB.Port, cleientInDB.ShelfTypeName);
|
var tcpCleint = new TCPClient(cleientInDB.IP, cleientInDB.Port, cleientInDB.ShelfTypeName);
|
||||||
tcpCleint.tcpClient.Received += (client, e) =>
|
tcpCleint.tcpReceiveClient.Received += (client, e) =>
|
||||||
{
|
{
|
||||||
var clientIpHost = client.IP + ":" + client.Port;
|
var clientIpHost = client.IP + ":" + client.Port;
|
||||||
var TcpCleint = TCPClientManager.GetTCPClientByIPHost(clientIpHost);
|
var TcpCleint = TCPClientManager.GetTCPClientByIPHost(clientIpHost);
|
||||||
@ -65,19 +65,11 @@ namespace WCS.BLL.Manager
|
|||||||
e.ByteBlock.Clear();
|
e.ByteBlock.Clear();
|
||||||
var len = data.Length;
|
var len = data.Length;
|
||||||
|
|
||||||
if (tcpCleint.ShelfTypeName == "信息化货架")
|
if (tcpCleint.ShelfTypeName == "液晶标签货架")
|
||||||
{
|
{
|
||||||
Logs.Write($"【信息化货架开始处理接收数据】{BitConverter.ToString(data)}", LogsType.InstructionsProcess);
|
Logs.Write($"【液晶标签货架开始处理接收数据】{BitConverter.ToString(data)}", LogsType.InstructionsProcess);
|
||||||
Helper.ReturnDataProcess(TcpCleint, data);
|
|
||||||
Logs.Write($"【信息化货架完成处理接收数据】{BitConverter.ToString(data)}", LogsType.InstructionsProcess);
|
|
||||||
return EasyTask.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tcpCleint.ShelfTypeName == "液晶货架")
|
|
||||||
{
|
|
||||||
Logs.Write($"【液晶货架开始处理接收数据】{BitConverter.ToString(data)}", LogsType.InstructionsProcess);
|
|
||||||
//Helper.ReturnDataProcess(TcpCleint, data);
|
//Helper.ReturnDataProcess(TcpCleint, data);
|
||||||
Logs.Write($"【液晶货架完成处理接收数据】{BitConverter.ToString(data)}", LogsType.InstructionsProcess);
|
Logs.Write($"【液晶标签货架完成处理接收数据】{BitConverter.ToString(data)}", LogsType.InstructionsProcess);
|
||||||
return EasyTask.CompletedTask;
|
return EasyTask.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +115,7 @@ namespace WCS.BLL.Manager
|
|||||||
return EasyTask.CompletedTask;
|
return EasyTask.CompletedTask;
|
||||||
};
|
};
|
||||||
//配置首次连接后复位操作
|
//配置首次连接后复位操作
|
||||||
tcpCleint.tcpClient.Connected += (client, e) =>
|
tcpCleint.tcpSendClient.Connected += (client, e) =>
|
||||||
{
|
{
|
||||||
Logs.Write($"【TcpClient】{client.IP}完成连接,端口号{client.Port}", LogsType.StartBoot);
|
Logs.Write($"【TcpClient】{client.IP}完成连接,端口号{client.Port}", LogsType.StartBoot);
|
||||||
var clientIpHost = client.IP + ":" + client.Port;
|
var clientIpHost = client.IP + ":" + client.Port;
|
||||||
@ -132,7 +124,7 @@ namespace WCS.BLL.Manager
|
|||||||
{
|
{
|
||||||
return EasyTask.CompletedTask;
|
return EasyTask.CompletedTask;
|
||||||
}
|
}
|
||||||
//首次连接
|
////首次连接
|
||||||
if (TcpCleint.IsFirstConnected == false)
|
if (TcpCleint.IsFirstConnected == false)
|
||||||
{
|
{
|
||||||
Logs.Write($"【InitTcpClient】{clientIpHost}完成首次连接", LogsType.StartBoot);
|
Logs.Write($"【InitTcpClient】{clientIpHost}完成首次连接", LogsType.StartBoot);
|
||||||
@ -140,7 +132,7 @@ namespace WCS.BLL.Manager
|
|||||||
|
|
||||||
|
|
||||||
Console.WriteLine($"【InitTcpClient】{clientIpHost}完成首次连接");
|
Console.WriteLine($"【InitTcpClient】{clientIpHost}完成首次连接");
|
||||||
InitStatus(TcpCleint);
|
//InitStatus(TcpCleint);
|
||||||
TcpCleint.IsFirstConnected = true;
|
TcpCleint.IsFirstConnected = true;
|
||||||
//获取剩余未完成连接的tcp
|
//获取剩余未完成连接的tcp
|
||||||
var noFirstConnectedTcps = TCPClientManager.TCPClients.Where(t => t.IsFirstConnected == false)
|
var noFirstConnectedTcps = TCPClientManager.TCPClients.Where(t => t.IsFirstConnected == false)
|
||||||
|
@ -18,5 +18,10 @@ namespace WCS.BLL.Services.IService
|
|||||||
public Task<ResponseCommon<object>> sysOrderMXL4(SysOrderMXL4Request request);
|
public Task<ResponseCommon<object>> sysOrderMXL4(SysOrderMXL4Request request);
|
||||||
|
|
||||||
public Task<ResponseCommon> refreshInventoryRequest(RefreshInventoryRequest request);
|
public Task<ResponseCommon> refreshInventoryRequest(RefreshInventoryRequest request);
|
||||||
|
|
||||||
|
#region 调试用的APi
|
||||||
|
public Task<ResponseCommon> reSetAll();
|
||||||
|
public Task<ResponseCommon> defaultDisplay();
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
|||||||
using System.Xml.Xsl;
|
using System.Xml.Xsl;
|
||||||
using TouchSocket.Core;
|
using TouchSocket.Core;
|
||||||
using WCS.BLL.DbModels;
|
using WCS.BLL.DbModels;
|
||||||
|
using WCS.BLL.HardWare;
|
||||||
using WCS.BLL.Manager;
|
using WCS.BLL.Manager;
|
||||||
using WCS.BLL.Services.IService;
|
using WCS.BLL.Services.IService;
|
||||||
using WCS.BLL.Tool;
|
using WCS.BLL.Tool;
|
||||||
@ -162,5 +163,86 @@ namespace WCS.BLL.Services.Service
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<ResponseCommon> reSetAll()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//1.获取所有液晶标签货架
|
||||||
|
var shelfs = ShelfManager.Shelves.Where(t => t.ShelfTypeName == "液晶标签货架")
|
||||||
|
.Select(t => t as MXL4Shelf)
|
||||||
|
.ToList();
|
||||||
|
shelfs.ForEach(t =>
|
||||||
|
{
|
||||||
|
t.Reset();
|
||||||
|
});
|
||||||
|
return new ResponseCommon
|
||||||
|
{
|
||||||
|
Code = 200,
|
||||||
|
Message = "success"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ResponseCommon
|
||||||
|
{
|
||||||
|
Code = 200,
|
||||||
|
Message = "操作失败:" + ex.Message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<ResponseCommon> defaultDisplay()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//1.获取所有液晶标签货架
|
||||||
|
var shelfs = ShelfManager.Shelves.Where(t => t.ShelfTypeName == "液晶标签货架")
|
||||||
|
.Select(t => t as MXL4Shelf)
|
||||||
|
.ToList();
|
||||||
|
shelfs.ForEach(t =>
|
||||||
|
{
|
||||||
|
t.MXL4Modules.ForEach(m =>
|
||||||
|
{
|
||||||
|
//发送进入入库模式
|
||||||
|
m.GoInOutstoreMode(t.TcpCleint);
|
||||||
|
//任务ID
|
||||||
|
m.SendTaskId(7, t.TcpCleint);
|
||||||
|
m.SendMatCode("A7100200300", t.TcpCleint);
|
||||||
|
m.SendMatName("A7SESSSSSS", t.TcpCleint);
|
||||||
|
m.SendMatSpec("7GUIGE", t.TcpCleint);
|
||||||
|
m.SendMatBatch("202412097", t.TcpCleint);
|
||||||
|
m.SendMatQty(999, t.TcpCleint);
|
||||||
|
|
||||||
|
m.SendTaskId(6, t.TcpCleint);
|
||||||
|
m.SendMatCode("A6666666", t.TcpCleint);
|
||||||
|
m.SendMatName("ASESSSSSS6", t.TcpCleint);
|
||||||
|
m.SendMatSpec("GUIGE6", t.TcpCleint);
|
||||||
|
m.SendMatBatch("202412096", t.TcpCleint);
|
||||||
|
m.SendMatQty(222, t.TcpCleint);
|
||||||
|
|
||||||
|
m.SendTaskId(3, t.TcpCleint);
|
||||||
|
m.SendMatCode("A33333", t.TcpCleint);
|
||||||
|
m.SendMatName("3ASESSSSS", t.TcpCleint);
|
||||||
|
m.SendMatSpec("3GUIGE3", t.TcpCleint);
|
||||||
|
m.SendMatBatch("202412093", t.TcpCleint);
|
||||||
|
m.SendMatQty(333, t.TcpCleint);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return new ResponseCommon
|
||||||
|
{
|
||||||
|
Code = 200,
|
||||||
|
Message = "success"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ResponseCommon
|
||||||
|
{
|
||||||
|
Code = 200,
|
||||||
|
Message = "操作失败:" + ex.Message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.ComponentModel.Design;
|
using System.ComponentModel.Design;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using TouchSocket.Core;
|
using TouchSocket.Core;
|
||||||
using TouchSocket.Sockets;
|
using TouchSocket.Sockets;
|
||||||
using WCS.BLL.Tool;
|
using WCS.BLL.Tool;
|
||||||
@ -19,8 +20,8 @@ namespace WCS.BLL
|
|||||||
public string BindIPHost { get; set; } = "127.0.0.1:20003";
|
public string BindIPHost { get; set; } = "127.0.0.1:20003";
|
||||||
|
|
||||||
public string ShelfTypeName { get; set; }
|
public string ShelfTypeName { get; set; }
|
||||||
public bool IsOnline { get; set; } = false;
|
public bool IsReceivedClientOnline { get; set; } = false;
|
||||||
|
public bool IsSendClientOnline { get; set; } = false;
|
||||||
//第一次连接是否已连接
|
//第一次连接是否已连接
|
||||||
public bool IsFirstConnected { get; set; } = false;
|
public bool IsFirstConnected { get; set; } = false;
|
||||||
|
|
||||||
@ -31,13 +32,14 @@ namespace WCS.BLL
|
|||||||
//协议数据部分长度
|
//协议数据部分长度
|
||||||
public readonly int DataLength = 10;
|
public readonly int DataLength = 10;
|
||||||
|
|
||||||
public ConcurrentDictionary<int, MessageDto> MessageList { get; set; } = new ConcurrentDictionary<int, MessageDto>();
|
|
||||||
|
|
||||||
public TcpClient tcpClient { get; set; }
|
public TcpClient tcpSendClient { get; set; }
|
||||||
|
|
||||||
//同步发送等待客户端 等待上一条指令发送成功并收到响应之后才发送下一条指令
|
//同步发送等待客户端 等待上一条指令发送成功并收到响应之后才发送下一条指令
|
||||||
public IWaitingClient<TcpClient> waitClient;
|
public IWaitingClient<TcpClient> waitClient;
|
||||||
|
|
||||||
|
public TcpClient tcpReceiveClient { get; set; }
|
||||||
|
|
||||||
public object receivdLockObject = new object();
|
public object receivdLockObject = new object();
|
||||||
public object sendLockObject = new object();
|
public object sendLockObject = new object();
|
||||||
|
|
||||||
@ -45,7 +47,8 @@ namespace WCS.BLL
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
tcpClient.Connect();//调用连接,当连接不成功时,会抛出异常。
|
tcpSendClient.Connect();//调用连接,当连接不成功时,会抛出异常。
|
||||||
|
tcpReceiveClient.Connect();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -67,16 +70,15 @@ namespace WCS.BLL
|
|||||||
BindIPHost = bindIPHost;
|
BindIPHost = bindIPHost;
|
||||||
ShelfTypeName = shelfTypeName;
|
ShelfTypeName = shelfTypeName;
|
||||||
|
|
||||||
tcpClient = new TcpClient();
|
tcpSendClient = new TcpClient();
|
||||||
|
tcpReceiveClient = new TcpClient();
|
||||||
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(BindIPHost))
|
if (string.IsNullOrEmpty(BindIPHost))
|
||||||
{
|
{
|
||||||
//载入配置
|
//载入配置
|
||||||
tcpClient.Setup(new TouchSocketConfig()
|
tcpSendClient.Setup(new TouchSocketConfig()
|
||||||
.SetRemoteIPHost(new IPHost(RemoteIPHost))
|
.SetRemoteIPHost(new IPHost(RemoteIPHost))
|
||||||
//.SetBindIPHost(BindIPHost)
|
|
||||||
.ConfigurePlugins(a =>
|
.ConfigurePlugins(a =>
|
||||||
{
|
{
|
||||||
//配置断线重连
|
//配置断线重连
|
||||||
@ -89,7 +91,7 @@ namespace WCS.BLL
|
|||||||
a.AddConsoleLogger();
|
a.AddConsoleLogger();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
var waitClient = tcpClient.CreateWaitingClient(new WaitingOptions()
|
waitClient = tcpSendClient.CreateWaitingClient(new WaitingOptions()
|
||||||
{
|
{
|
||||||
FilterFunc = response => //设置用于筛选的fun委托,当返回为true时,才会响应返回
|
FilterFunc = response => //设置用于筛选的fun委托,当返回为true时,才会响应返回
|
||||||
{
|
{
|
||||||
@ -101,11 +103,26 @@ namespace WCS.BLL
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tcpReceiveClient.Setup(new TouchSocketConfig()
|
||||||
|
.SetRemoteIPHost(new IPHost(RemoteIPHost))
|
||||||
|
//.SetBindIPHost(BindIPHost)
|
||||||
|
.ConfigurePlugins(a =>
|
||||||
|
{
|
||||||
|
//配置断线重连
|
||||||
|
a.UseReconnection(-1, true, 1000);
|
||||||
|
a.Add<HeartbeatAndReceivePlugin>();
|
||||||
|
})
|
||||||
|
.ConfigureContainer(a =>
|
||||||
|
{
|
||||||
|
//添加控制台日志注入
|
||||||
|
a.AddConsoleLogger();
|
||||||
|
}));
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//载入配置
|
//载入配置
|
||||||
tcpClient.Setup(new TouchSocketConfig()
|
tcpSendClient.Setup(new TouchSocketConfig()
|
||||||
.SetRemoteIPHost(new IPHost(RemoteIPHost))
|
.SetRemoteIPHost(new IPHost(RemoteIPHost))
|
||||||
.SetBindIPHost(new IPHost(BindIPHost))
|
.SetBindIPHost(new IPHost(BindIPHost))
|
||||||
.ConfigurePlugins(a =>
|
.ConfigurePlugins(a =>
|
||||||
@ -119,124 +136,110 @@ namespace WCS.BLL
|
|||||||
//添加控制台日志注入
|
//添加控制台日志注入
|
||||||
a.AddConsoleLogger();
|
a.AddConsoleLogger();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
waitClient = tcpSendClient.CreateWaitingClient(new WaitingOptions()
|
||||||
|
{
|
||||||
|
FilterFunc = response => //设置用于筛选的fun委托,当返回为true时,才会响应返回
|
||||||
|
{
|
||||||
|
if (response.Data.Length == 13)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tcpReceiveClient.Setup(new TouchSocketConfig()
|
||||||
|
.SetRemoteIPHost(new IPHost(RemoteIPHost))
|
||||||
|
//.SetBindIPHost(BindIPHost)
|
||||||
|
.ConfigurePlugins(a =>
|
||||||
|
{
|
||||||
|
//配置断线重连
|
||||||
|
a.UseReconnection(-1, true, 1000);
|
||||||
|
a.Add<HeartbeatAndReceivePlugin>();
|
||||||
|
})
|
||||||
|
.ConfigureContainer(a =>
|
||||||
|
{
|
||||||
|
//添加控制台日志注入
|
||||||
|
a.AddConsoleLogger();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
//添加接收事件 匹配已发送的指令
|
//添加接收事件 匹配已发送的指令
|
||||||
tcpClient.Received += (client, e) =>
|
//tcpReceiveClient.Received += (client, e) =>
|
||||||
{
|
|
||||||
var data = e.ByteBlock.Buffer.Take((int)e.ByteBlock.Length).ToArray();
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
|
||||||
Logs.Write($"【校验发送接收 开始】{ShelfTypeName}" + BitConverter.ToString(data), LogsType.InstructionResend);
|
|
||||||
if (ShelfTypeName == "信息化货架")
|
|
||||||
{
|
|
||||||
//协议拆包
|
|
||||||
var len = data.Length;
|
|
||||||
//灯控制统一返回的是 FF-00-00-0A-00-02-D7-B5
|
|
||||||
if (len == 8)
|
|
||||||
{
|
|
||||||
if (data[4] == 0x00 && data[0] == 0xFF && data[1] == 0x00 && (data[5] == 0x01 || data[5] == 0x02))
|
|
||||||
{
|
|
||||||
//查询当前板子是否有待验证的指令
|
|
||||||
var message = new MessageDto();
|
|
||||||
var firstMessage = MessageList.Select(t => new { Id = t.Key, Value = t.Value })
|
|
||||||
.OrderBy(t => t.Value.CreateTime)
|
|
||||||
.FirstOrDefault();
|
|
||||||
if (firstMessage != null)
|
|
||||||
{
|
|
||||||
MessageList.TryRemove(firstMessage.Id, out message);
|
|
||||||
Logs.Write($"【信息化货架】以下指令已不重发:{BitConverter.ToString(firstMessage.Value.Message)}", LogsType.InstructionResend);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (ShelfTypeName == "液晶货架")
|
|
||||||
{
|
|
||||||
Logs.Write($"【液晶货架】接收到指令{BitConverter.ToString(data)}", LogsType.InstructionResend);
|
|
||||||
}
|
|
||||||
//智能货架
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var len = data.Length;
|
|
||||||
for (int index = 0; index < data.Length - PreFixLength; index++)
|
|
||||||
{
|
|
||||||
//协议拆包 通过前缀校验是否为完整数据包
|
|
||||||
var prefixInData = data.Skip(index).Take(PreFixLength);
|
|
||||||
var isEqual = prefixInData.SequenceEqual(Prefix);
|
|
||||||
if (isEqual)
|
|
||||||
{
|
|
||||||
var dataTemp = data.Skip(index).Take(PreFixLength + DataLength).ToArray();
|
|
||||||
if (dataTemp.Length < PreFixLength + DataLength)//拆包后不满足一条指令的长度
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//获取返回指令的板子ID
|
|
||||||
var boardId = (dataTemp[PreFixLength + 0] << 8) + dataTemp[PreFixLength + 1];
|
|
||||||
//查询当前板子是否有待验证的指令
|
|
||||||
var message = new MessageDto();
|
|
||||||
MessageList.TryGetValue(boardId, out message);
|
|
||||||
//功能位校验 功能位相同视为已响应指令 删除对应的指令
|
|
||||||
if (message?.Message[PreFixLength + 2] == dataTemp[PreFixLength + 2])
|
|
||||||
{
|
|
||||||
MessageList.TryRemove(boardId, out message);
|
|
||||||
}
|
|
||||||
index += (PreFixLength + DataLength - 2);//每次循环index会+1 所以这里-1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Logs.Write($"【校验发送接收 结束】{ShelfTypeName}" + BitConverter.ToString(data), LogsType.InstructionResend);
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
tcpClient.Connected += (client, e) =>
|
|
||||||
{
|
|
||||||
this.IsOnline = true;
|
|
||||||
return EasyTask.CompletedTask;
|
|
||||||
};
|
|
||||||
|
|
||||||
tcpClient.Disconnected += (client, e) =>
|
|
||||||
{
|
|
||||||
this.IsOnline = false;
|
|
||||||
return EasyTask.CompletedTask;
|
|
||||||
};
|
|
||||||
|
|
||||||
////配置数据重发机制
|
|
||||||
//Task.Run(async () =>
|
|
||||||
//{
|
//{
|
||||||
// while (true)
|
// var data = e.ByteBlock.Buffer.Take((int)e.ByteBlock.Length).ToArray();
|
||||||
|
// Task.Run(() =>
|
||||||
// {
|
// {
|
||||||
// try
|
// Logs.Write($"【校验发送接收 开始】{ShelfTypeName}" + BitConverter.ToString(data), LogsType.InstructionResend);
|
||||||
|
// if (ShelfTypeName == "信息化货架")
|
||||||
// {
|
// {
|
||||||
// //TODO如果指令已发两次 则取消重发
|
// //协议拆包
|
||||||
// await Task.Delay(100);
|
// var len = data.Length;
|
||||||
// if (MessageList.Count > 0)
|
// //灯控制统一返回的是 FF-00-00-0A-00-02-D7-B5
|
||||||
|
// if (len == 8)
|
||||||
// {
|
// {
|
||||||
// var failedMessage = MessageList.Where(t => t.Value.LastSendTime < DateTime.Now.AddSeconds(-1))
|
// if (data[4] == 0x00 && data[0] == 0xFF && data[1] == 0x00 && (data[5] == 0x01 || data[5] == 0x02))
|
||||||
// .ToList();
|
|
||||||
// foreach (var message in failedMessage)
|
|
||||||
// {
|
// {
|
||||||
// Logs.Write("【指令重发】" + BitConverter.ToString(message.Value.Message) + "指令超时1s未响应", LogsType.InstructionResend);
|
|
||||||
// }
|
|
||||||
// MessageList.RemoveWhen(t => t.Value.SendTimes >= 2);
|
|
||||||
// foreach (var item in MessageList)
|
|
||||||
// {
|
|
||||||
// if (item.Value.LastSendTime < DateTime.Now.AddSeconds(-1))
|
|
||||||
// {
|
|
||||||
|
|
||||||
// Send(item.Value.Message);
|
|
||||||
// item.Value.SendTimes++;
|
|
||||||
// item.Value.LastSendTime = DateTime.Now;
|
|
||||||
// Logs.Write("【指令重发】" + BitConverter.ToString(item.Value.Message) + "已进行重发", LogsType.InstructionResend);
|
|
||||||
// }
|
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// catch
|
// else if (ShelfTypeName == "液晶标签货架")
|
||||||
// {
|
// {
|
||||||
|
// Logs.Write($"【液晶标签货架】接收到指令{BitConverter.ToString(data)}", LogsType.InstructionResend);
|
||||||
// }
|
// }
|
||||||
// }
|
// //智能货架
|
||||||
//});
|
// else
|
||||||
|
// {
|
||||||
|
// var len = data.Length;
|
||||||
|
// for (int index = 0; index < data.Length - PreFixLength; index++)
|
||||||
|
// {
|
||||||
|
// //协议拆包 通过前缀校验是否为完整数据包
|
||||||
|
// var prefixInData = data.Skip(index).Take(PreFixLength);
|
||||||
|
// var isEqual = prefixInData.SequenceEqual(Prefix);
|
||||||
|
// if (isEqual)
|
||||||
|
// {
|
||||||
|
// var dataTemp = data.Skip(index).Take(PreFixLength + DataLength).ToArray();
|
||||||
|
// if (dataTemp.Length < PreFixLength + DataLength)//拆包后不满足一条指令的长度
|
||||||
|
// {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// //获取返回指令的板子ID
|
||||||
|
// var boardId = (dataTemp[PreFixLength + 0] << 8) + dataTemp[PreFixLength + 1];
|
||||||
|
// index += (PreFixLength + DataLength - 2);//每次循环index会+1 所以这里-1
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// Logs.Write($"【校验发送接收 结束】{ShelfTypeName}" + BitConverter.ToString(data), LogsType.InstructionResend);
|
||||||
|
// });
|
||||||
|
// return null;
|
||||||
|
//};
|
||||||
|
|
||||||
|
tcpSendClient.Connected += (client, e) =>
|
||||||
|
{
|
||||||
|
this.IsSendClientOnline = true;
|
||||||
|
return EasyTask.CompletedTask;
|
||||||
|
};
|
||||||
|
|
||||||
|
tcpSendClient.Disconnected += (client, e) =>
|
||||||
|
{
|
||||||
|
this.IsSendClientOnline = false;
|
||||||
|
return EasyTask.CompletedTask;
|
||||||
|
};
|
||||||
|
|
||||||
|
tcpReceiveClient.Connected += (client, e) =>
|
||||||
|
{
|
||||||
|
this.IsReceivedClientOnline = true;
|
||||||
|
return EasyTask.CompletedTask;
|
||||||
|
};
|
||||||
|
|
||||||
|
tcpReceiveClient.Disconnected += (client, e) =>
|
||||||
|
{
|
||||||
|
this.IsReceivedClientOnline = false;
|
||||||
|
ReConnectAsync();
|
||||||
|
return EasyTask.CompletedTask;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -245,7 +248,10 @@ namespace WCS.BLL
|
|||||||
|
|
||||||
public void ReConnectAsync()
|
public void ReConnectAsync()
|
||||||
{
|
{
|
||||||
tcpClient.TryConnectAsync();
|
if (IsSendClientOnline == false)
|
||||||
|
tcpSendClient.TryConnectAsync();
|
||||||
|
if (IsReceivedClientOnline == false)
|
||||||
|
tcpReceiveClient.TryConnectAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -255,25 +261,15 @@ namespace WCS.BLL
|
|||||||
{
|
{
|
||||||
var boardId = (message[3] << 8) + message[4];
|
var boardId = (message[3] << 8) + message[4];
|
||||||
|
|
||||||
if (boardId != 2047 && IsReSend == false)
|
|
||||||
{
|
|
||||||
MessageList.TryAdd(boardId, new MessageDto()
|
|
||||||
{
|
|
||||||
ID = boardId,
|
|
||||||
Message = message,
|
|
||||||
SendTimes = 1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (sendLockObject)
|
lock (sendLockObject)
|
||||||
{
|
{
|
||||||
tcpClient.Send(message);
|
tcpReceiveClient.Send(message);
|
||||||
|
|
||||||
var clientIpHost = tcpClient.IP + ":" + tcpClient.Port;
|
var clientIpHost = tcpReceiveClient.IP + ":" + tcpReceiveClient.Port;
|
||||||
Logs.Write($"【发送{clientIpHost}】{BitConverter.ToString(message)}", LogsType.Instructions);
|
Logs.Write($"【发送{clientIpHost}】{BitConverter.ToString(message)}", LogsType.Instructions);
|
||||||
|
|
||||||
//发送自带15ms间隔
|
//发送自带10ms间隔
|
||||||
Thread.Sleep(18);
|
Thread.Sleep(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -282,6 +278,7 @@ namespace WCS.BLL
|
|||||||
//因异常断连时(网线已经被断了) 手动重连一次
|
//因异常断连时(网线已经被断了) 手动重连一次
|
||||||
if (ex is NotConnectedException)
|
if (ex is NotConnectedException)
|
||||||
{
|
{
|
||||||
|
IsReceivedClientOnline = false;
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
ReConnectAsync();
|
ReConnectAsync();
|
||||||
@ -295,10 +292,9 @@ namespace WCS.BLL
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var boardId = (message[3] << 8) + message[4];
|
|
||||||
lock (sendLockObject)
|
lock (sendLockObject)
|
||||||
{
|
{
|
||||||
var clientIpHost = tcpClient.IP + ":" + tcpClient.Port;
|
var clientIpHost = tcpSendClient.IP + ":" + tcpSendClient.Port;
|
||||||
Logs.Write($"【同步等待发送{clientIpHost}】{BitConverter.ToString(message)}", LogsType.Instructions);
|
Logs.Write($"【同步等待发送{clientIpHost}】{BitConverter.ToString(message)}", LogsType.Instructions);
|
||||||
|
|
||||||
waitClient.SendThenReturn(message);
|
waitClient.SendThenReturn(message);
|
||||||
@ -311,6 +307,38 @@ namespace WCS.BLL
|
|||||||
//因异常断连时(网线已经被断了) 手动重连一次
|
//因异常断连时(网线已经被断了) 手动重连一次
|
||||||
if (ex is NotConnectedException)
|
if (ex is NotConnectedException)
|
||||||
{
|
{
|
||||||
|
IsSendClientOnline = false;
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
ReConnectAsync();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendThenReturnList(List<byte[]> messages, bool IsReSend = false)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
lock (sendLockObject)
|
||||||
|
{
|
||||||
|
foreach (var message in messages)
|
||||||
|
{
|
||||||
|
var clientIpHost = tcpSendClient.IP + ":" + tcpSendClient.Port;
|
||||||
|
Logs.Write($"【同步等待发送{clientIpHost}】{BitConverter.ToString(message)}", LogsType.Instructions);
|
||||||
|
waitClient.SendThenReturn(message);
|
||||||
|
Thread.Sleep(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logs.Write("【同步等待发送指令时发生异常】" + ex.Message, LogsType.Instructions);
|
||||||
|
//因异常断连时(网线已经被断了) 手动重连一次
|
||||||
|
if (ex is NotConnectedException)
|
||||||
|
{
|
||||||
|
IsSendClientOnline = false;
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
ReConnectAsync();
|
ReConnectAsync();
|
||||||
@ -340,26 +368,64 @@ namespace WCS.BLL
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<byte[]> GenerateMessageList(int boardId, byte[] data, string message)
|
||||||
|
{
|
||||||
|
var list = new List<byte[]>();
|
||||||
|
//去除不满足ASCII的数据
|
||||||
|
message = Regex.Replace(message, @"[^\u0000-\u007F]+", string.Empty);
|
||||||
|
//总共发的数据位数
|
||||||
|
data[1] = Convert.ToByte(message.Length);
|
||||||
|
//数据发送总帧数
|
||||||
|
var messageCount = Math.Ceiling((decimal)message.Length / 6);
|
||||||
|
|
||||||
|
for (int i = 0; i < messageCount; i++)
|
||||||
|
{
|
||||||
|
var tempmessage = string.Empty;
|
||||||
|
//不是最后一条指令
|
||||||
|
if (i != messageCount - 1)
|
||||||
|
{
|
||||||
|
tempmessage = message.Substring(i * 6, 6);
|
||||||
|
var charArray = tempmessage.ToCharArray();
|
||||||
|
for (int index = 0; index < 6; index++)
|
||||||
|
{
|
||||||
|
data[2 + index] = Convert.ToByte(charArray[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//最后一条指令
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tempmessage = message.Substring(i * 6, message.Length % 6 == 0 ? 6 : message.Length % 6);
|
||||||
|
var charArray = tempmessage.ToCharArray();
|
||||||
|
//先把所有数据位置为0
|
||||||
|
for (int index = 0; index < 6; index++)
|
||||||
|
{
|
||||||
|
data[2 + index] = 0x00;
|
||||||
|
}
|
||||||
|
//有数据的置为对应的数据
|
||||||
|
for (int index = 0; index < charArray.Length; index++)
|
||||||
|
{
|
||||||
|
data[2 + index] = Convert.ToByte(charArray[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.Add(GenerateMessage(boardId, data));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string CharToAscii(char chr)
|
||||||
|
{
|
||||||
|
return ((int)chr).ToString("X").PadLeft(2, '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] StrToToHexByte(string hexString)
|
||||||
|
{
|
||||||
|
hexString = hexString.Replace(" ", string.Empty);
|
||||||
|
if ((hexString.Length % 2) != 0)
|
||||||
|
hexString = "0" + hexString;
|
||||||
|
byte[] returnBytes = new byte[hexString.Length / 2];
|
||||||
|
for (int i = 0; i < returnBytes.Length; i++)
|
||||||
|
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
|
||||||
|
return returnBytes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//发送指令的记录
|
|
||||||
public class MessageDto
|
|
||||||
{
|
|
||||||
public int ID { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// 最后一次发送时间
|
|
||||||
/// </summary>
|
|
||||||
public DateTime LastSendTime { get; set; } = DateTime.Now;
|
|
||||||
|
|
||||||
public DateTime CreateTime { get; set; } = DateTime.Now;
|
|
||||||
/// <summary>
|
|
||||||
/// 发送内容
|
|
||||||
/// </summary>
|
|
||||||
public byte[] Message { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// 发送次数
|
|
||||||
/// </summary>
|
|
||||||
public int SendTimes { get; set; } = 0;//第几次发送
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -137,10 +137,11 @@ namespace WCS.WebApi.Controllers
|
|||||||
var tcpClients = TCPClientManager.TCPClients.Select(t => new
|
var tcpClients = TCPClientManager.TCPClients.Select(t => new
|
||||||
{
|
{
|
||||||
RemoteIPHost = t.RemoteIPHost,
|
RemoteIPHost = t.RemoteIPHost,
|
||||||
IsOnline = t.IsOnline,
|
IsReceivedClientOnline = t.IsReceivedClientOnline,
|
||||||
|
IsSendClientOnline = t.IsSendClientOnline,
|
||||||
IsFirstConnected = t.IsFirstConnected,
|
IsFirstConnected = t.IsFirstConnected,
|
||||||
tcpClientIsNull = t.tcpClient == null,
|
tcpClientIsNull = t.tcpSendClient == null,
|
||||||
tcpClientIsOnLine = t.tcpClient?.Online,
|
tcpClientIsOnLine = t.tcpSendClient?.Online,
|
||||||
|
|
||||||
}).ToList();
|
}).ToList();
|
||||||
//直接返回当前内存中缓存的货架和状态
|
//直接返回当前内存中缓存的货架和状态
|
||||||
|
@ -76,5 +76,44 @@ namespace WCS.WebApi.Controllers
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region 调试用的API
|
||||||
|
[Route("reSetAll")]
|
||||||
|
[HttpPost(Name = "reSetAll")]
|
||||||
|
public async Task<ResponseBase> reSetAll()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await _mxl4Service.reSetAll();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ResponseBase()
|
||||||
|
{
|
||||||
|
Code = 300,
|
||||||
|
Message = "操作失败:" + ex.Message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route("defaultDisplay")]
|
||||||
|
[HttpPost(Name = "defaultDisplay")]
|
||||||
|
public async Task<ResponseBase> defaultDisplay()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await _mxl4Service.defaultDisplay();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ResponseBase()
|
||||||
|
{
|
||||||
|
Code = 300,
|
||||||
|
Message = "操作失败:" + ex.Message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user