|
|
@ -4,6 +4,8 @@ using SlnMesnac.Plc.Impl;
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using SlnMesnac.Config;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SlnMesnac.Plc
|
|
|
|
namespace SlnMesnac.Plc
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -21,30 +23,59 @@ namespace SlnMesnac.Plc
|
|
|
|
private readonly MelsecBinaryPlc _melsecBinaryPlc;
|
|
|
|
private readonly MelsecBinaryPlc _melsecBinaryPlc;
|
|
|
|
private readonly OmronNJPlc _omronNJPlc;
|
|
|
|
private readonly OmronNJPlc _omronNJPlc;
|
|
|
|
private readonly SiemensPlc _siemensPlc;
|
|
|
|
private readonly SiemensPlc _siemensPlc;
|
|
|
|
|
|
|
|
private readonly AppConfig _appConfig;
|
|
|
|
|
|
|
|
|
|
|
|
public PlcPool(ILogger<PlcPool> logger, InovancePlc inovancePlc,MelsecBinaryPlc melsecBinaryPlc,OmronNJPlc omronNJPlc,SiemensPlc siemensPlc)
|
|
|
|
public PlcPool(ILogger<PlcPool> logger, InovancePlc inovancePlc,MelsecBinaryPlc melsecBinaryPlc,OmronNJPlc omronNJPlc,SiemensPlc siemensPlc,AppConfig appConfig)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
_logger = logger;
|
|
|
|
_inovancePlc = inovancePlc;
|
|
|
|
_inovancePlc = inovancePlc;
|
|
|
|
_melsecBinaryPlc = melsecBinaryPlc;
|
|
|
|
_melsecBinaryPlc = melsecBinaryPlc;
|
|
|
|
_omronNJPlc = omronNJPlc;
|
|
|
|
_omronNJPlc = omronNJPlc;
|
|
|
|
_siemensPlc = siemensPlc;
|
|
|
|
_siemensPlc = siemensPlc;
|
|
|
|
|
|
|
|
_appConfig = appConfig;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//this.Init();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
|
|
|
{
|
|
|
|
if (!HslCommunication.Authorization.SetAuthorizationCode("ed1415f8-e06a-43ad-95f7-c04f7ae93b41"))
|
|
|
|
if (!HslCommunication.Authorization.SetAuthorizationCode("ed1415f8-e06a-43ad-95f7-c04f7ae93b41"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogInformation("HslCommunication激活失败,可用时长24小时");
|
|
|
|
_logger.LogInformation("HslCommunication激活失败,可用时长24小时");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_logger.LogInformation("HslCommunication 11.0.6.0激活成功");
|
|
|
|
_logger.LogInformation("HslCommunication 11.0.6.0激活成功");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_appConfig.plcConfig != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var item in _appConfig.plcConfig)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
AddPlc(item.plcType, item.plcIp, item.plcPort, item.plcKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogInformation("PLC配置信息为空");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.LogError($"PLC初始化连接异常:{e.Message}");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 初始化Plc
|
|
|
|
/// 添加PLC连接
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="plcType"></param>
|
|
|
|
/// <param name="plcType"></param>
|
|
|
|
/// <param name="ip"></param>
|
|
|
|
/// <param name="ip"></param>
|
|
|
|
/// <param name="port"></param>
|
|
|
|
/// <param name="port"></param>
|
|
|
|
/// <param name="key"></param>
|
|
|
|
/// <param name="key"></param>
|
|
|
|
public void InitPlc(string plcType, string ip, int port, string key)
|
|
|
|
public void AddPlc(string plcType, string ip, int port, string key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IPlc _plc = null;
|
|
|
|
IPlc _plc = null;
|
|
|
|
switch (plcType)
|
|
|
|
switch (plcType)
|
|
|
|