218 lines
7.6 KiB
C#
218 lines
7.6 KiB
C#
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.BLL.Config;
|
|
using WCS.BLL.DbModels.Task;
|
|
using WCS.DAL.Db;
|
|
using WCS.DAL.DbModels;
|
|
|
|
namespace WCS.BLL.HardWare
|
|
{
|
|
public class MXL4ShelfModule
|
|
{
|
|
#region 协议
|
|
/// <summary>
|
|
/// 复位命令
|
|
/// </summary>
|
|
public byte[] ResetData = { 0xBE, 0x52, 0x54, 0x41, 0x52, 0x54, 0x0A, 0xED };
|
|
|
|
/// <summary>
|
|
/// 发送任务ID 0x01改为实际发送的任务ID
|
|
/// </summary>
|
|
public byte[] SendTaskIdData = { 0xAA, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
/// <summary>
|
|
/// 发送料号信息
|
|
/// </summary>
|
|
public byte[] SendMatCodeData = { 0xA5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
/// <summary>
|
|
/// 发送名称信息
|
|
/// </summary>
|
|
public byte[] SendMatNameData = { 0xA6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
/// <summary>
|
|
/// 发送规格信息
|
|
/// </summary>
|
|
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>
|
|
public byte[] GoInInstoreModeData = { 0xA1, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00 };
|
|
/// <summary>
|
|
/// 退出入库模式
|
|
/// </summary>
|
|
public byte[] GoOutInstoreModeData = { 0xA1, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
/// <summary>
|
|
/// 进入出库模式
|
|
/// </summary>
|
|
public byte[] GoInOutstoreModeData = { 0xA2, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00 };
|
|
/// <summary>
|
|
/// 退出出库模式
|
|
/// </summary>
|
|
public byte[] GoOutOutstoreModeData = { 0xA2, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
/// <summary>
|
|
/// 进入盘点模式
|
|
/// </summary>
|
|
public byte[] GoInStocktakingModeData = { 0xA3, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00 };
|
|
/// <summary>
|
|
/// 进入盘点模式
|
|
/// </summary>
|
|
public byte[] GoOutStocktakingModeData = { 0xA3, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
|
|
/// <summary>
|
|
/// 待机模式 无库存显示信息
|
|
/// </summary>
|
|
public byte[] StandbyNoInfoDisplayData = { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
#endregion
|
|
public int ModuleId { get; set; }
|
|
public string ModuleCode { get; set; }
|
|
public int BoardId { get; set; }
|
|
public bool IsEnable { get; set; }
|
|
public TaskModeEnum CurrentMode { get; set; } = TaskModeEnum.待机模式;
|
|
|
|
public bool IsNeedRefresh { get; set; } = true;
|
|
|
|
public void SetCurrentMode(TaskModeEnum currentMode)
|
|
{
|
|
CurrentMode = currentMode;
|
|
}
|
|
|
|
|
|
#region 液晶标签存在的协议
|
|
/// <summary>
|
|
/// 复位
|
|
/// </summary>
|
|
/// <param name="tcpClient"></param>
|
|
public void Reset(TCPClient tcpClient)
|
|
{
|
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, ResetData));
|
|
}
|
|
|
|
public void StandbyNoInfoDisplay(TCPClient tcpClient)
|
|
{
|
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, StandbyNoInfoDisplayData));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 进入入库模式
|
|
/// </summary>
|
|
/// <param name="tcpClient"></param>
|
|
public void GoInInstoreMode(TCPClient tcpClient)
|
|
{
|
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, GoInInstoreModeData));
|
|
//SetCurrentMode(TaskModeEnum.入库模式);
|
|
}
|
|
/// <summary>
|
|
/// 退出入库模式
|
|
/// </summary>
|
|
/// <param name="tcpClient"></param>
|
|
public void GoOutInstoreMode(TCPClient tcpClient)
|
|
{
|
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, GoOutInstoreModeData));
|
|
//SetCurrentMode(TaskModeEnum.入库模式);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 进入出库模式
|
|
/// </summary>
|
|
/// <param name="tcpClient"></param>
|
|
public void GoInOutstoreMode(TCPClient tcpClient)
|
|
{
|
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, GoInOutstoreModeData));
|
|
//SetCurrentMode(TaskModeEnum.出库模式);
|
|
}
|
|
/// <summary>
|
|
/// 退出出库模式
|
|
/// </summary>
|
|
/// <param name="tcpClient"></param>
|
|
public void GoOutOutstoreMode(TCPClient tcpClient)
|
|
{
|
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, GoOutInstoreModeData));
|
|
//SetCurrentMode(TaskModeEnum.出库模式);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 进入盘点模式
|
|
/// </summary>
|
|
/// <param name="tcpClient"></param>
|
|
public void GoInStocktakingMode(TCPClient tcpClient)
|
|
{
|
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, GoInStocktakingModeData));
|
|
//SetCurrentMode(TaskModeEnum.盘点模式);
|
|
}
|
|
/// <summary>
|
|
/// 退出盘点模式
|
|
/// </summary>
|
|
/// <param name="tcpClient"></param>
|
|
public void GoOutStocktakingMode(TCPClient tcpClient)
|
|
{
|
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, GoOutStocktakingModeData));
|
|
//SetCurrentMode(TaskModeEnum.盘点模式);
|
|
}
|
|
|
|
//发送任务ID
|
|
public void SendTaskId(int taskID, TCPClient tcpClient)
|
|
{
|
|
var taskIDData = Convert.ToByte(taskID);
|
|
SendTaskIdData[1] = taskIDData;
|
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, SendTaskIdData));
|
|
}
|
|
//发送料号
|
|
public void SendMatCode(string matCode, TCPClient tcpClient)
|
|
{
|
|
tcpClient.SendThenReturnList(tcpClient.GenerateMessageList(BoardId, SendMatCodeData, matCode));
|
|
}
|
|
//发送名称
|
|
public void SendMatName(string matName, TCPClient tcpClient)
|
|
{
|
|
tcpClient.SendThenReturnList(tcpClient.GenerateMessageList(BoardId, SendMatNameData, matName));
|
|
}
|
|
//发送规格
|
|
public void SendMatSpec(string matSpec, TCPClient tcpClient)
|
|
{
|
|
tcpClient.SendThenReturnList(tcpClient.GenerateMessageList(BoardId, SendMatSpecData, matSpec));
|
|
}
|
|
//发送批次
|
|
public void SendMatBatch(string matBatch, TCPClient tcpClient)
|
|
{
|
|
tcpClient.SendThenReturnList(tcpClient.GenerateMessageList(BoardId, SendMatBatchData, matBatch));
|
|
}
|
|
//发送数量
|
|
public void SendMatQty(int matQty, TCPClient tcpClient)
|
|
{
|
|
var boardIdData = BitConverter.GetBytes(unchecked((short)matQty));
|
|
// 检查是否需要交换字节
|
|
if (BitConverter.IsLittleEndian)
|
|
{
|
|
// 如果是小端序系统,则交换字节
|
|
byte temp = boardIdData[0];
|
|
boardIdData[0] = boardIdData[1];
|
|
boardIdData[1] = temp;
|
|
}
|
|
SendMatQtyData[1] = boardIdData[0];
|
|
SendMatQtyData[2] = boardIdData[1];
|
|
tcpClient.SendThenReturn(tcpClient.GenerateMessage(BoardId, SendMatQtyData));
|
|
}
|
|
#endregion
|
|
}
|
|
}
|