增加配置库位编码接口

This commit is contained in:
hehaibing-1996
2025-06-06 14:33:30 +08:00
parent b64103e6f3
commit c78f0bfbe8
3 changed files with 95 additions and 1 deletions

View File

@ -82,6 +82,12 @@ namespace WCS.BLL.HardWare
/// 待机模式 无库存显示信息 /// 待机模式 无库存显示信息
/// </summary> /// </summary>
public byte[] StandbyNoInfoDisplayData = { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; public byte[] StandbyNoInfoDisplayData = { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
/// <summary>
/// 发送库位编码
/// </summary>
public byte[] SendStoreCodeData = { 0xBB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
#endregion #endregion
public int ModuleId { get; set; } public int ModuleId { get; set; }
public string ModuleCode { get; set; } public string ModuleCode { get; set; }
@ -223,6 +229,12 @@ namespace WCS.BLL.HardWare
SendMatQtyData[2] = boardIdData[1]; SendMatQtyData[2] = boardIdData[1];
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, SendMatQtyData)); tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, SendMatQtyData));
} }
//发送库位编码
public void SendStoreCode(string storeCode, TCPClient tcpClient)
{
tcpClient.SendList(tcpClient.GenerateMessageList(BoardId, SendStoreCodeData, storeCode));
}
#endregion #endregion
} }
} }

View File

@ -289,6 +289,37 @@ namespace WCS.BLL
} }
} }
public void SendList(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);
tcpReceiveClient.Send(message);
Thread.Sleep(3);
}
}
}
catch (Exception ex)
{
Logs.Write("【发送指令时发生异常】" + ex.Message, LogsType.Instructions);
//因异常断连时(网线已经被断了) 手动重连一次
if (ex is NotConnectedException)
{
IsReceivedClientOnline = false;
Task.Run(() =>
{
ReConnectAsync();
});
}
throw ex;
}
}
public void SendThenReturn(byte[] message, bool IsReSend = false) public void SendThenReturn(byte[] message, bool IsReSend = false)
{ {
try try

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc; using Kdbndp;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.Formula.Functions; using NPOI.SS.Formula.Functions;
using SqlSugar; using SqlSugar;
using WCS.BLL.DbModels; using WCS.BLL.DbModels;
@ -786,5 +787,55 @@ namespace WCS.WebApi.Controllers
}; };
} }
} }
/// <summary>
/// 配置库位编码
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("setStoreCode")]
[HttpPost(Name = "setStoreCode")]
public async Task<ResponseBase> setStoreCode(SetBoardIdRequest request)
{
try
{
var errorList = new List<string>();
//1.获取所有液晶标签货架
var shelfs = ShelfManager.Shelves.Where(t => t.ShelfTypeName == "液晶标签货架")
.WhereIF(!string.IsNullOrEmpty(request.IPPort), t => t.ClientIp == request.IPPort)
.Select(t => t as MXL4Shelf)
.ToList();
shelfs.ForEach(t =>
{
t.MXL4Modules.ForEach(m =>
{
try
{
m.SendStoreCode(m.ModuleCode, t.TcpCleint);
}
catch (Exception ex)
{
errorList.Add($"模组{m.ModuleCode}更新库位ID失败原因{ex.Message}");
}
});
});
return new ResponseCommon
{
Code = 200,
Message = "success",
Data = errorList
};
}
catch (Exception ex)
{
return new ResponseCommon
{
Code = 300,
Message = "操作失败:" + ex.Message,
};
}
}
} }
} }