!提交代码

This commit is contained in:
hehaibing-1996
2024-04-15 18:43:28 +08:00
commit e89b64ea3a
232 changed files with 22292 additions and 0 deletions

View File

@ -0,0 +1,210 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TouchSocket.Core;
using WCS.DAL;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
using WCS.Model;
namespace WCS.BLL.HardWare
{
/// <summary>
/// 智能货架
/// </summary>
public class SmartShelf : IShelfBase
{
public SmartShelf(ShelfInfo shelfInfo)
{
ShelfId = shelfInfo.Id;
ShelfCode = shelfInfo.ShelfCode;
RowCounts = shelfInfo.Rowcounts;
ColumnCounts = shelfInfo.Columncounts;
CurentMode = shelfInfo.CurrentMode;
//初始化Module
Task.Run(() =>
{
var modules = DbHelp.db.Queryable<ModuleInfo>().Where(t => t.ShelfId == ShelfId).ToList();
foreach (var module in modules)
{
Modules.Add(new SmartShelfModule()
{
ModuleId = module.Id,
ModuleCode = module.ModuleCode,
IsEnable = module.IsEnable,
CurrentMode = module.CurentMode
});
}
ModulesStr = string.Join(";", Modules.Select(t => t.ModuleCode));
});
//初始化TCPCleint
TcpCleint = new TCPClient("127.0.0.1:20002", "127.0.0.1:20003");
TcpCleint.Connect();
TcpCleint.tcpClient.Received += (client, e) =>
{
var data = e.ByteBlock.Buffer.Take((int)e.ByteBlock.Length).ToArray();
e.ByteBlock.Clear();
var len = data.Length;
for (int index = 0; index < data.Length - TcpCleint.PreFixLength; index++)
{
//协议拆包 通过前缀校验是否为完整数据包
var prefixInData = data.Skip(index).Take(TcpCleint.PreFixLength);
var isEqual = prefixInData.SequenceEqual(TcpCleint.Prefix);
if (isEqual)
{
var dataTemp = data.Skip(index).Take(TcpCleint.PreFixLength + TcpCleint.DataLength).ToArray();
if (dataTemp.Length < TcpCleint.PreFixLength + TcpCleint.DataLength)//拆包后不满足一条指令的长度
{
continue;
}
index += (TcpCleint.PreFixLength + TcpCleint.DataLength - 1);//每次循环index会+1 所以这里-1
//获取板子ID
var boardId = (data[TcpCleint.PreFixLength + 0] << 8) + data[TcpCleint.PreFixLength + 1];
//协议处理 判断功能位
switch (dataTemp[TcpCleint.PreFixLength + 2])
{
case 0x01:
;
break;
default:
;
break;
}
}
}
return EasyTask.CompletedTask;
};
}
public int ShelfId { get; set; }
public string ShelfCode { get; set; }
public int RowCounts { get; set; }
public int ColumnCounts { get; set; }
public Mode CurentMode { get; set; }
public string ModulesStr { get; set; }//当前货架所有模组的Str
public string GroupName { get; set; }
public List<SmartShelfModule> Modules { get; set; } = new List<SmartShelfModule>();
public TCPClient TcpCleint { get; set; }
public IWarningLightBase WarningLight { get; set; }
public List<string> ExceptionMessages { get; set; } = new List<string>();
public string? InstoreIpAddress { get; set; } = string.Empty;
public MatInfoModel InStoreData { get; set; }
public string OutOrderNumber { get; set; }
public void GoInInstore(string? IPAddress)
{
//判断当前模式是否为待机模式
if (this.CurentMode != Mode.)
{
return;
}
else
{
this.CurentMode = Mode.;
}
//货架所有模组发送指令进入入库模式
foreach (var module in Modules.Where(t => t.IsEnable).ToList())
{
module.GoInInstoreMode(TcpCleint);
}
//延时获取异常
var timeOut = 3000;
var timeSpan = TimeSpan.FromMilliseconds(0);
var beginTime = DateTime.Now;
while (timeSpan <= TimeSpan.FromMilliseconds(timeOut))
{
timeSpan = DateTime.Now - beginTime;
//接收到第一个异常就不继续循环了
if (ExceptionMessages.Count() > 0)
{
var deficientTime = timeOut - (int)timeSpan.TotalMilliseconds;
if (deficientTime > 0)
Thread.Sleep(deficientTime);
//出现异常的未进入入库模式,有红灯进行指引
//未出现异常的需要退出入库模式
GoOutInstore();
return;
}
//延时处理
Thread.Sleep(50);
}
//警示灯亮起
//WarningLight.BlueLight();
//绑定当前入库PDA的IP
InstoreIpAddress = IPAddress;
//返回成功
return;
}
public void GoInInstoreReturn()
{
}
public void GoOutInstore()
{
//看货架是否为入库模式
if (CurentMode != Mode.)
{
return;
}
else
{
this.CurentMode = Mode.;
}
//货架所有模组发送指令退出入库模式
foreach (var module in Modules.Where(t => t.IsEnable)
.Where(t => t.CurrentMode == Mode.)
.ToList())
{
module.GoOutInstoreMode(TcpCleint);
}
}
public void GoInOutstore()
{
throw new NotImplementedException();
}
public void GoInStocktaking()
{
throw new NotImplementedException();
}
public void GoOutOutstore()
{
throw new NotImplementedException();
}
public void GoOutStocktaking()
{
throw new NotImplementedException();
}
void IShelfBase.Reset()
{
throw new NotImplementedException();
}
void IShelfBase.SetCurrentMode()
{
throw new NotImplementedException();
}
void IShelfBase.Warning()
{
throw new NotImplementedException();
}
}
}