From 068a66e70aa58be3949445fd76d67966b1ce637d Mon Sep 17 00:00:00 2001 From: wenjy Date: Mon, 13 May 2024 13:48:55 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E6=BF=80=E6=B4=BB=E7=A0=81?= =?UTF-8?q?=E6=BF=80=E6=B4=BBHsl=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Extensions/PlcFactorySetup.cs | 49 ++++++++++++++++--------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/SlnMesnac.Extensions/PlcFactorySetup.cs b/SlnMesnac.Extensions/PlcFactorySetup.cs index 383e7e1..3298593 100644 --- a/SlnMesnac.Extensions/PlcFactorySetup.cs +++ b/SlnMesnac.Extensions/PlcFactorySetup.cs @@ -48,34 +48,47 @@ namespace SlnMesnac.Extensions try { - if (appConfig.plcConfig != null) + do { - foreach (var item in appConfig.plcConfig) + if (!HslCommunication.Authorization.SetAuthorizationCode("1839541f-8fb4-42c4-a13f-733b027fe5af")) { - if (item.isFlage) - { - PlcAbsractFactory _plc = InitPlc(x, item.plcType); + Log.Information("HslCommunication激活失败,可用时长为24小时"); + break; + } + else + { + Log.Information("HslCommunication激活成功"); + } - var connectResult = _plc.Connect(item.plcIp, item.plcPort); - if (connectResult) + if (appConfig.plcConfig != null) + { + foreach (var item in appConfig.plcConfig) + { + if (item.isFlage) { - Log.Information($"PLC:{item.plcIp}:{item.plcPort};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); - _plc.ConfigKey = item.plcKey; + PlcAbsractFactory _plc = InitPlc(x, item.plcType); - if(absractFactories.Contains(_plc)) + var connectResult = _plc.Connect(item.plcIp, item.plcPort); + if (connectResult) { - absractFactories.Remove(_plc); - } + Log.Information($"PLC:{item.plcIp}:{item.plcPort};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + _plc.ConfigKey = item.plcKey; - absractFactories.Add(_plc); - } - else - { - Log.Information($"PLC:{item.plcIp}:{item.plcPort};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + if (absractFactories.Contains(_plc)) + { + absractFactories.Remove(_plc); + } + + absractFactories.Add(_plc); + } + else + { + Log.Information($"PLC:{item.plcIp}:{item.plcPort};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + } } } } - } + }while(false); } catch (Exception e) {