2024-05-14 16:30:56 +08:00
|
|
|
|
using WcsMain.Socket;
|
|
|
|
|
|
using WcsMain.Common;
|
|
|
|
|
|
using WcsMain.WcsAttribute.AutoFacAttribute;
|
|
|
|
|
|
using WcsMain.Plugins;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
using WcsMain.AppEntity.SystemData;
|
|
|
|
|
|
using WcsMain.DataBase.Dao;
|
|
|
|
|
|
using WcsMain.DataBase.TableEntity;
|
|
|
|
|
|
using WcsMain.WcsAttribute.AppConfig;
|
|
|
|
|
|
using WcsMain.Business.Convey;
|
2024-05-28 16:53:50 +08:00
|
|
|
|
using WcsMain.ElTag.Atop;
|
2024-05-30 15:34:20 +08:00
|
|
|
|
using WcsMain.EquipOperation;
|
2024-05-14 16:30:56 +08:00
|
|
|
|
|
|
|
|
|
|
namespace WcsMain.StartAction;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 服务启动主体类
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Component]
|
|
|
|
|
|
public class ServiceStart(WcsCirculation wcsCirculation, ConnectPLCs connectPLCs, SocketOperation socketOperation,
|
2024-05-28 16:53:50 +08:00
|
|
|
|
AppStackerDao appStackerDao, AppLocationDao appLocationDao, AppConfigDao appConfigDao, ConnectPlcServe connectPlcServe,
|
2024-06-15 13:54:11 +08:00
|
|
|
|
ConnectOprServe connectOprServe, AppElTagLocationDao appElTagBaseDao, AppConveyStandDao conveyStandDao)
|
2024-05-14 16:30:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
private static string _errMsg = string.Empty;
|
2024-05-23 07:27:57 +08:00
|
|
|
|
|
2024-05-14 16:30:56 +08:00
|
|
|
|
/// <summary>
|
2024-05-23 07:27:57 +08:00
|
|
|
|
/// 加载必要参数
|
2024-05-14 16:30:56 +08:00
|
|
|
|
/// </summary>
|
2024-05-23 07:27:57 +08:00
|
|
|
|
public void LoadingData()
|
2024-05-14 16:30:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
LoadingConfig(); // 加载数据库中的配置项 (config 表)
|
|
|
|
|
|
LoadingStackerData(); // 加载数据库中的堆垛机信息
|
|
|
|
|
|
LoadingLocationData(); // 加载数据库中的库位信息
|
2024-05-29 12:56:32 +08:00
|
|
|
|
LoadElTagBase(); // 加载电子标签基础资料
|
2024-06-13 09:12:27 +08:00
|
|
|
|
LoadConveyStand(); // 加载输送线站台基础资料
|
2024-05-14 16:30:56 +08:00
|
|
|
|
|
2024-05-23 07:27:57 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(_errMsg))
|
2024-05-14 16:30:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
ConsoleLog.Error($"【异常】启动加载运行文件出错,WCS功能受到限制,您可以检查网络连接后重新启动或者联系我们,参考信息:{_errMsg}");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-05-23 07:27:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 启动 ——-- 主方法
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
/* 指定线程池规格 */
|
|
|
|
|
|
ThreadPool.SetMinThreads(30, 10);
|
2024-05-14 16:30:56 +08:00
|
|
|
|
|
|
|
|
|
|
CreatePlcClient(); // 连接 PLC 客户端
|
|
|
|
|
|
CreateSocketClient(); // Socket客户端
|
2024-05-28 16:53:50 +08:00
|
|
|
|
ConnectOprServe(); // 连接 Opr 电子标签客户端
|
2024-05-14 16:30:56 +08:00
|
|
|
|
CreateCieculateTask();// 创建并启用定时器
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建并连接 Plc
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void CreatePlcClient()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CommonData.AppConfig.UseConnectPlc == "1") // 1 表示允许连接PLC
|
|
|
|
|
|
{
|
2024-06-20 09:41:02 +08:00
|
|
|
|
connectPLCs.ConnectPlc();
|
2024-05-14 16:30:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-28 16:53:50 +08:00
|
|
|
|
/// 创建并运行 Socket 客户端 ---- 待更新
|
2024-05-14 16:30:56 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void CreateSocketClient()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CommonData.AppConfig.UseSocket == "1") // 1 表示允许开启Socket
|
|
|
|
|
|
{
|
2024-06-20 09:41:02 +08:00
|
|
|
|
socketOperation.Connect();
|
2024-05-14 16:30:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-28 16:53:50 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 连接Opr电子标签客户端
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void ConnectOprServe()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CommonData.AppConfig.UseOpr == "1") // 1 表示允许连接电子标签
|
|
|
|
|
|
{
|
2024-06-20 09:41:02 +08:00
|
|
|
|
connectOprServe.SetBaseAction();
|
|
|
|
|
|
connectOprServe.Connect();
|
2024-05-28 16:53:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-05-14 16:30:56 +08:00
|
|
|
|
|
|
|
|
|
|
public void CreateTcpClient()
|
|
|
|
|
|
{
|
2024-06-20 09:41:02 +08:00
|
|
|
|
connectPlcServe.SetBaseAction();
|
|
|
|
|
|
connectPlcServe.ConnectPlc();
|
2024-05-14 16:30:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建并启用定时器
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void CreateCieculateTask()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CommonData.AppConfig.UseCirculation == "1") // 1 表示允许开启 定时器
|
|
|
|
|
|
{
|
2024-06-20 09:41:02 +08:00
|
|
|
|
wcsCirculation.ExceptionHandler += (methodDescription, ex) =>
|
2024-05-14 16:30:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
ConsoleLog.Error($"定时器:{methodDescription} 发生异常,异常信息:{ex}");
|
|
|
|
|
|
};
|
2024-06-20 09:41:02 +08:00
|
|
|
|
wcsCirculation.MessageHandler += (msg) =>
|
2024-05-14 16:30:56 +08:00
|
|
|
|
{
|
|
|
|
|
|
//ConsoleLog.Tip(msg);
|
|
|
|
|
|
};
|
2024-06-20 09:41:02 +08:00
|
|
|
|
wcsCirculation.StartAssemblyCirculation(GetType().Assembly);
|
2024-05-14 16:30:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加载数据库内的 Config 配置信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void LoadingConfig()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrEmpty(_errMsg)) return;
|
2024-06-13 09:12:27 +08:00
|
|
|
|
//ConsoleLog.Info("正在加载数据库配置信息...");
|
2024-06-20 09:41:02 +08:00
|
|
|
|
List<AppConfig>? Configs = appConfigDao.Query();
|
2024-05-14 16:30:56 +08:00
|
|
|
|
if (Configs == default)
|
|
|
|
|
|
{
|
|
|
|
|
|
_errMsg = "加载 Config 资源失败,请检查数据库服务器连接是否正常";
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
AppConfigEntity? appConfigEntity = new();
|
|
|
|
|
|
var type = appConfigEntity.GetType();
|
|
|
|
|
|
var propertys = type.GetProperties();
|
|
|
|
|
|
foreach (var property in propertys)
|
|
|
|
|
|
{
|
|
|
|
|
|
string? propertyName = property.Name;
|
|
|
|
|
|
var attribute = property.GetCustomAttribute(typeof(ConfigKeyAttribute));
|
|
|
|
|
|
if (attribute != default)
|
|
|
|
|
|
{
|
|
|
|
|
|
var configKeyAttribute = attribute as ConfigKeyAttribute;
|
|
|
|
|
|
if (configKeyAttribute != default && configKeyAttribute.KeyName != default)
|
|
|
|
|
|
{
|
|
|
|
|
|
propertyName = configKeyAttribute.KeyName;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
AppConfig? appConfig = Configs.Find(f => f.ConfigKey == propertyName);
|
|
|
|
|
|
if (appConfig == default) continue;
|
|
|
|
|
|
property.SetValue(appConfigEntity, appConfig.ConfigValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
CommonData.AppConfig = appConfigEntity;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加载堆垛机数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void LoadingStackerData()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrEmpty(_errMsg)) return;
|
2024-06-13 09:12:27 +08:00
|
|
|
|
//ConsoleLog.Info("正在加载堆垛机参数信息...");
|
2024-06-20 09:41:02 +08:00
|
|
|
|
List<AppStacker>? appStackers = appStackerDao.Select();
|
2024-05-14 16:30:56 +08:00
|
|
|
|
if (appStackers == default)
|
|
|
|
|
|
{
|
|
|
|
|
|
_errMsg = "加载堆垛机参数信息失败,请检查数据库服务器连接是否正常";
|
|
|
|
|
|
CommonData.AppStackers = [];
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
CommonData.AppStackers = appStackers;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加载库位信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void LoadingLocationData()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrEmpty(_errMsg)) return;
|
2024-06-13 09:12:27 +08:00
|
|
|
|
//ConsoleLog.Info("正在加载库位信息...");
|
2024-06-20 09:41:02 +08:00
|
|
|
|
List<AppLocation>? appLocations = appLocationDao.Select();
|
2024-05-14 16:30:56 +08:00
|
|
|
|
if (appLocations == default)
|
|
|
|
|
|
{
|
|
|
|
|
|
_errMsg = "加载库位信息失败,请检查数据库服务器连接是否正常";
|
|
|
|
|
|
CommonData.AppLocations = [];
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
CommonData.AppLocations = appLocations;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-29 12:56:32 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加载电子标签基础资料
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void LoadElTagBase()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrEmpty(_errMsg)) return;
|
2024-06-13 09:12:27 +08:00
|
|
|
|
//ConsoleLog.Info("正在电子标签基础资料信息...");
|
2024-06-20 09:41:02 +08:00
|
|
|
|
List<AppElTagLocation>? eltags = appElTagBaseDao.Query();
|
2024-05-29 12:56:32 +08:00
|
|
|
|
if (eltags == default)
|
|
|
|
|
|
{
|
|
|
|
|
|
_errMsg = "加载电子标签基础信息失败,请检查数据库服务器连接是否正常";
|
|
|
|
|
|
CommonData.AppElTags = [];
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
CommonData.AppElTags = eltags;
|
|
|
|
|
|
}
|
2024-06-13 09:12:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加载输送线站台基础资料信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void LoadConveyStand()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrEmpty(_errMsg)) return;
|
|
|
|
|
|
//ConsoleLog.Info("正在加载输送线基础资料信息...");
|
2024-06-20 09:41:02 +08:00
|
|
|
|
List<AppConveyStand>? appConveyStands = conveyStandDao.Query();
|
2024-06-13 09:12:27 +08:00
|
|
|
|
if (appConveyStands == default)
|
|
|
|
|
|
{
|
|
|
|
|
|
_errMsg = "加载输送线站台基础资料信息失败,请检查数据库服务器连接是否正常";
|
|
|
|
|
|
CommonData.AppConveyStands = [];
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
CommonData.AppConveyStands = appConveyStands;
|
|
|
|
|
|
}
|
2024-05-14 16:30:56 +08:00
|
|
|
|
}
|