<update>[important]删除对PLC进行Socket通讯的支持
This commit is contained in:
parent
8a61f237eb
commit
2d635c7415
|
|
@ -1,106 +0,0 @@
|
|||
using WcsMain.Business.Convey.DataHandler;
|
||||
using WcsMain.Common;
|
||||
using WcsMain.DataBase.Dao;
|
||||
using WcsMain.DataBase.TableEntity;
|
||||
using WcsMain.Enum.General;
|
||||
using WcsMain.Enum.Tcp;
|
||||
using WcsMain.Tcp.Client;
|
||||
using WcsMain.Tcp.Entity;
|
||||
using WcsMain.Tcp.Entity.Message;
|
||||
using WcsMain.WcsAttribute.AutoFacAttribute;
|
||||
|
||||
namespace WcsMain.Business.Convey;
|
||||
|
||||
/// <summary>
|
||||
/// 连接并接收 PLC 的信息
|
||||
/// </summary>
|
||||
[Component]
|
||||
public class ConnectPlcServe(AppTcpDao tcpDao, BaseConveyDataHandler conveyDataHandler)
|
||||
{
|
||||
|
||||
public void SetBaseAction()
|
||||
{
|
||||
CommonTool.PlcTcpClient = new PlcTcpClient();
|
||||
CommonTool.PlcTcpClient.SetConnecting((tcpData) => ConsoleLog.Info($"{tcpData} 正在连接"));
|
||||
CommonTool.PlcTcpClient.SetConnectFailAction((tcpData, ex) => ConsoleLog.Warning($"{tcpData} 连接失败,参考信息:{ex.Message}"));
|
||||
CommonTool.PlcTcpClient.SetConnectSuccess((tcpData) => ConsoleLog.Success($"{tcpData} 连接成功"));
|
||||
CommonTool.PlcTcpClient.SetConnectOffline((tcpData) => ConsoleLog.Warning($"{tcpData} 失去连接"));
|
||||
CommonTool.PlcTcpClient.GetMessage(GetMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 连接PLC服务
|
||||
/// </summary>
|
||||
public void ConnectPlc()
|
||||
{
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
List<AppTcp>? tcps = default;
|
||||
while (true)
|
||||
{
|
||||
tcps = tcpDao.Query(new AppTcp { TcpStatus = (int)TrueFalseEnum.TRUE, TcpType = (int)TcpType.PLC });
|
||||
if (tcps != default) break;
|
||||
Thread.Sleep(5000);
|
||||
continue;
|
||||
}
|
||||
if (tcps.Count == 0) return;
|
||||
CommonTool.PlcTcpClient.SetBaseTcpServe(tcps);
|
||||
CommonTool.PlcTcpClient.Connect();
|
||||
}, TaskCreationOptions.LongRunning);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 收到信息时的处理
|
||||
/// </summary>
|
||||
/// <param name="tcpServe"></param>
|
||||
/// <param name="Msg"></param>
|
||||
private void GetMessage(TcpServeConnectionData tcpServe, string msg)
|
||||
{
|
||||
ConsoleLog.Tcp($"{tcpServe} 收到信息:{msg}");
|
||||
MsgHeader? header = CommonTool.PlcTcpClient.GetMsgHeader(msg);
|
||||
if(header == default) { return; }
|
||||
switch(header.MsgType)
|
||||
{
|
||||
case "SEND":
|
||||
GetRequest(tcpServe, header, msg);
|
||||
return;
|
||||
case "RESP":
|
||||
GetResponse();
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************** 请求和响应事件 *****************************/
|
||||
|
||||
|
||||
private void GetResponse()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void GetRequest(TcpServeConnectionData tcpServe, MsgHeader header, string msg)
|
||||
{
|
||||
switch(header.MsgTag)
|
||||
{
|
||||
case "GTROUTER": // plc向WCS请求路向 ---- 箱式线
|
||||
conveyDataHandler.GetRouter(tcpServe.DisplayName, msg);
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/****************************** 请求事件 ******************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,138 +0,0 @@
|
|||
using Autofac;
|
||||
using System.Reflection;
|
||||
using WcsMain.Business.Convey.DataHandler.GetRouter.I;
|
||||
using WcsMain.DataBase.Dao;
|
||||
using WcsMain.DataBase.TableEntity;
|
||||
using WcsMain.Tcp.Entity.Convey;
|
||||
using WcsMain.WcsAttribute.AutoFacAttribute;
|
||||
|
||||
namespace WcsMain.Business.Convey.DataHandler;
|
||||
|
||||
/// <summary>
|
||||
/// 输送线收到的数据处理基础类
|
||||
/// </summary>
|
||||
[Component]
|
||||
public class BaseConveyDataHandler(AppRouterMethodDao routerMethodDao, IComponentContext componentContext)
|
||||
{
|
||||
private readonly IComponentContext _componentContext = componentContext;
|
||||
private readonly AppRouterMethodDao _routerMethodDao = routerMethodDao;
|
||||
|
||||
private Dictionary<string, IBaseGetRouter?>? methodConfig;
|
||||
|
||||
/// <summary>
|
||||
/// 处理 PLC 请求分拣路向逻辑
|
||||
/// </summary>
|
||||
/// <param name="displayName"></param>
|
||||
/// <param name="msg"></param>
|
||||
public void GetRouter(string? displayName, string msg)
|
||||
{
|
||||
LoadingMethodConfig(); // 加载配置信息,仅第一次加载
|
||||
if(methodConfig == default)
|
||||
{
|
||||
ConsoleLog.Warning("路由处理参数尚未加载,可能是和数据库服务连接存在异常");
|
||||
return;
|
||||
}
|
||||
GetRouterData? routerData = FormatGetRouterData(msg);
|
||||
if(routerData == default )
|
||||
{
|
||||
ConsoleLog.Warning($"数据不能正常识别,数据:{msg}");
|
||||
return;
|
||||
}
|
||||
var getInstance = methodConfig.TryGetValue(routerData.Area ?? "", out var instance);
|
||||
if(!getInstance || instance == default)
|
||||
{
|
||||
ConsoleLog.Warning($"点位:{routerData.Area} 未配置处理逻辑或者处理逻辑不可用");
|
||||
return;
|
||||
}
|
||||
if(routerData.Code == "NoRead")
|
||||
{
|
||||
instance.ReadFail(routerData, displayName, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.ReadSuccess(routerData, displayName, msg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************/
|
||||
|
||||
/// <summary>
|
||||
/// 加载获取路由的参数
|
||||
/// </summary>
|
||||
private void LoadingMethodConfig()
|
||||
{
|
||||
if (methodConfig != default) return;
|
||||
List<AppRouterMethod>? appRouters = _routerMethodDao.Query();
|
||||
if (appRouters == default) return;
|
||||
methodConfig = [];
|
||||
// 扫描创建继承 BaseGetRouter 的类的实例
|
||||
Dictionary<string, IBaseGetRouter> classInstances = [];
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var assTypes = assembly.GetTypes();
|
||||
foreach (var assType in assTypes)
|
||||
{
|
||||
var interfaces = assType.GetInterfaces();
|
||||
foreach (var inteface in interfaces)
|
||||
{
|
||||
if (inteface.GetType() != typeof(IBaseGetRouter)) continue;
|
||||
var instance = Activator.CreateInstance(inteface.GetType());
|
||||
if (instance == default) continue;
|
||||
classInstances.Add(assType.Name, (IBaseGetRouter)instance);
|
||||
}
|
||||
}
|
||||
// 将实例和请求点位绑定
|
||||
foreach (var appRouter in appRouters)
|
||||
{
|
||||
if(string.IsNullOrEmpty(appRouter.ClassName)) continue;
|
||||
bool isGetInstance = classInstances.TryGetValue(appRouter.ClassName, out var inst);
|
||||
if (!isGetInstance) continue;
|
||||
methodConfig.TryAdd(appRouter.Area ?? "", inst);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****************************** 格式化数据 ***************************/
|
||||
|
||||
/// <summary>
|
||||
/// PLC请求WCS路向的请求体格式化
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
/// <returns></returns>
|
||||
private GetRouterData? FormatGetRouterData(string msg)
|
||||
{
|
||||
if (string.IsNullOrEmpty(msg)) return default;
|
||||
msg = msg.Trim().TrimStart('<').TrimEnd('>');
|
||||
string[] datas = msg.Split(';');
|
||||
if (datas.Length != 14) return default;
|
||||
try
|
||||
{
|
||||
return new GetRouterData
|
||||
{
|
||||
MsgType = datas[0],
|
||||
ClientId = datas[1],
|
||||
MsgId = datas[2],
|
||||
MsgTag = datas[3],
|
||||
Area = datas[4],
|
||||
SortStatus = datas[5],
|
||||
Code = datas[6],
|
||||
Size = datas[7],
|
||||
Weight = Convert.ToDecimal(string.IsNullOrEmpty(datas[8]) ? 0 : datas[8]),
|
||||
Length = Convert.ToDecimal(string.IsNullOrEmpty(datas[9]) ? 0 : datas[9]),
|
||||
Width = Convert.ToDecimal(string.IsNullOrEmpty(datas[10]) ? 0 : datas[10]),
|
||||
Hight = Convert.ToDecimal(string.IsNullOrEmpty(datas[11]) ? 0 : datas[11]),
|
||||
Spare1 = datas[12],
|
||||
Spare2 = datas[13],
|
||||
};
|
||||
}
|
||||
catch (Exception ex) // 防止转换decimal失败
|
||||
{
|
||||
_ = ex;
|
||||
return default;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
using WcsMain.Business.Convey.DataHandler.GetRouter.I;
|
||||
using WcsMain.Tcp.Entity.Convey;
|
||||
|
||||
namespace WcsMain.Business.Convey.DataHandler.GetRouter;
|
||||
|
||||
/// <summary>
|
||||
/// 发货获取路向
|
||||
/// </summary>
|
||||
public class DeliverGetRouter : IBaseGetRouter
|
||||
{
|
||||
public void ReadFail(GetRouterData routerData, string? disPlayName, string msg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ReadSuccess(GetRouterData routerData, string? disPlayName, string msg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
using WcsMain.Tcp.Entity.Convey;
|
||||
|
||||
namespace WcsMain.Business.Convey.DataHandler.GetRouter.I;
|
||||
|
||||
public interface IBaseGetRouter
|
||||
{
|
||||
/// <summary>
|
||||
/// 读码失败
|
||||
/// </summary>
|
||||
/// <param name="routerData"></param>
|
||||
/// <param name="disPlayName"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
void ReadFail(GetRouterData routerData, string? disPlayName, string msg);
|
||||
|
||||
/// <summary>
|
||||
/// 不是读码失败
|
||||
/// </summary>
|
||||
/// <param name="routerData"></param>
|
||||
/// <param name="disPlayName"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
void ReadSuccess(GetRouterData routerData, string? disPlayName, string msg);
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
using WcsMain.Business.Convey.DataHandler.GetRouter.I;
|
||||
using WcsMain.Tcp.Entity.Convey;
|
||||
|
||||
namespace WcsMain.Business.Convey.DataHandler.GetRouter;
|
||||
|
||||
/// <summary>
|
||||
/// 注册口获取路向
|
||||
/// </summary>
|
||||
public class LoginGetRouter : IBaseGetRouter
|
||||
{
|
||||
public void ReadFail(GetRouterData routerData, string? disPlayName, string msg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ReadSuccess(GetRouterData routerData, string? disPlayName, string msg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
using WcsMain.Business.Convey.DataHandler.GetRouter.I;
|
||||
using WcsMain.Tcp.Entity.Convey;
|
||||
|
||||
namespace WcsMain.Business.Convey.DataHandler.GetRouter;
|
||||
|
||||
/// <summary>
|
||||
/// 拣选请求获取路向
|
||||
/// </summary>
|
||||
public class PickGetRouter : IBaseGetRouter
|
||||
{
|
||||
public void ReadFail(GetRouterData routerData, string? disPlayName, string msg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ReadSuccess(GetRouterData routerData, string? disPlayName, string msg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
using WcsMain.Business.Convey.DataHandler.GetRouter.I;
|
||||
using WcsMain.Tcp.Entity.Convey;
|
||||
|
||||
namespace WcsMain.Business.Convey.DataHandler.GetRouter;
|
||||
|
||||
/// <summary>
|
||||
/// 复核获取路向
|
||||
/// </summary>
|
||||
public class RecheckGetRouter : IBaseGetRouter
|
||||
{
|
||||
public void ReadFail(GetRouterData routerData, string? disPlayName, string msg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ReadSuccess(GetRouterData routerData, string? disPlayName, string msg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
using WcsMain.Business.Convey.DataHandler.GetRouter.I;
|
||||
using WcsMain.Tcp.Entity.Convey;
|
||||
|
||||
namespace WcsMain.Business.Convey.DataHandler.GetRouter;
|
||||
|
||||
/// <summary>
|
||||
/// 补货获取路向
|
||||
/// </summary>
|
||||
public class ReplenishGetRouter : IBaseGetRouter
|
||||
{
|
||||
public void ReadFail(GetRouterData routerData, string? disPlayName, string msg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void ReadSuccess(GetRouterData routerData, string? disPlayName, string msg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
|
||||
|
||||
该文件夹是给 TCP 通讯的 PLC 预留的功能
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
using WcsMain.Business.Convey.DataHandler.GetRouter;
|
||||
|
||||
namespace WcsMain.Enum.Convey;
|
||||
namespace WcsMain.Enum.Convey;
|
||||
|
||||
/// <summary>
|
||||
/// 箱式线站台类型
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace WcsMain.StartAction;
|
|||
/// </summary>
|
||||
[Component]
|
||||
public class ServiceStart(WcsCirculation wcsCirculation, ConnectPLCs connectPLCs, SocketOperation socketOperation,
|
||||
AppStackerDao appStackerDao, AppLocationDao appLocationDao, AppConfigDao appConfigDao, ConnectPlcServe connectPlcServe,
|
||||
AppStackerDao appStackerDao, AppLocationDao appLocationDao, AppConfigDao appConfigDao,
|
||||
ConnectOprServe connectOprServe, AppElTagLocationDao appElTagBaseDao, AppConveyStandDao conveyStandDao, AppApiBaseInfoDao appApiBaseInfoDao)
|
||||
{
|
||||
private static string _errMsg = string.Empty;
|
||||
|
|
@ -91,15 +91,6 @@ public class ServiceStart(WcsCirculation wcsCirculation, ConnectPLCs connectPLCs
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void CreateTcpClient()
|
||||
{
|
||||
connectPlcServe.SetBaseAction();
|
||||
connectPlcServe.ConnectPlc();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建并启用定时器
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user