80 lines
2.5 KiB
C#
80 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using WCS.DAL.Db;
|
|
using WCS.DAL.DbModels;
|
|
|
|
namespace WCS.BLL.HardWare
|
|
{
|
|
public class SmartShelfModule : IModuleBase
|
|
{
|
|
#region 协议明细
|
|
/// <summary>
|
|
/// 进入入库模式
|
|
/// </summary>
|
|
public byte[] GoInInstoreData = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
/// <summary>
|
|
/// 退出入库模式
|
|
/// </summary>
|
|
public byte[] GoOutInstoreData = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
#endregion
|
|
public int ModuleId { get; set; }
|
|
public string ModuleCode { get; set; }
|
|
public bool IsEnable { get; set; }
|
|
public Mode CurrentMode { get; set; }
|
|
|
|
public void SetCurrentMode()
|
|
{
|
|
|
|
}
|
|
|
|
public void GoInInstoreMode(TCPClient tcpCleint)
|
|
{
|
|
|
|
if (CurrentMode != Mode.待机模式)
|
|
{
|
|
//退出对应的模式 然后再发送进入入库模式
|
|
}
|
|
|
|
var storeInfos = DbHelp.db.Queryable<StoreInfo>()
|
|
.Where(t => t.BoardId == ModuleId)
|
|
.OrderBy(t => t.LightNumber)
|
|
.ToList();
|
|
char[] data = "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';
|
|
}
|
|
}
|
|
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);
|
|
|
|
tcpCleint.Send(tcpCleint.GenerateMessage(ModuleId, GoInInstoreData));
|
|
}
|
|
|
|
public void GoOutInstoreMode(TCPClient tcpCleint)
|
|
{
|
|
if (CurrentMode == Mode.入库模式)
|
|
{
|
|
tcpCleint.Send(tcpCleint.GenerateMessage(ModuleId, GoOutInstoreData));
|
|
}
|
|
else
|
|
{
|
|
//退出对应的模式 回到待机状态 并记录对应的状态日志(这个分支肯定是异常了)
|
|
//记录错误日志
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|