change - PLC 初始化设置

master
wenjy 10 months ago
parent 886e64ad39
commit b09b3c33a3

@ -39,28 +39,18 @@ namespace SlnMesnac.Plc
} }
_logger.LogInformation("HslCommunication 11.8.1.0激活成功"); _logger.LogInformation("HslCommunication 11.8.1.0激活成功");
try
{
if (_appConfig.plcConfig != null) if (_appConfig.plcConfig != null)
{
Task.Run(() =>
{ {
foreach (var item in _appConfig.plcConfig) foreach (var item in _appConfig.plcConfig)
{ {
AddPlc(item.plcType, item.plcIp, item.plcPort, item.plcKey); AddPlc(item.plcType, item.plcIp, item.plcPort, item.plcKey);
} }
});
} }
else else
{ {
_logger.LogInformation("PLC配置信息为空"); _logger.LogInformation("PLC配置信息为空");
} }
} }
catch (Exception e)
{
_logger.LogError($"PLC初始化连接异常{e.Message}");
}
}
/// <summary> /// <summary>
/// 添加PLC连接 /// 添加PLC连接
@ -70,6 +60,8 @@ namespace SlnMesnac.Plc
/// <param name="port"></param> /// <param name="port"></param>
/// <param name="key"></param> /// <param name="key"></param>
public void AddPlc(string plcType, string ip, int port, string key) public void AddPlc(string plcType, string ip, int port, string key)
{
try
{ {
PlcAbsractFactory _plc = null; PlcAbsractFactory _plc = null;
switch (plcType) switch (plcType)
@ -108,6 +100,11 @@ namespace SlnMesnac.Plc
_logger.LogInformation($"PLC{ip}:{port};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); _logger.LogInformation($"PLC{ip}:{port};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
} }
} }
catch (Exception e)
{
_logger.LogError($"PLC初始化连接异常{e.Message}");
}
}
/// <summary> /// <summary>
/// 获取PLC /// 获取PLC

Loading…
Cancel
Save