From ed815bf9cd0b4841c4aff896cde5d2362eb87ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=94=84=E5=A4=B4?= Date: Mon, 9 Sep 2024 10:26:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=81=A2=E5=A4=8Drfid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tool/PlcConnect.cs | 15 ++++++++++++--- Tool/RfidSetting.cs | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Tool/PlcConnect.cs b/Tool/PlcConnect.cs index 1da5904..c80305f 100644 --- a/Tool/PlcConnect.cs +++ b/Tool/PlcConnect.cs @@ -6,18 +6,27 @@ namespace Tool { public class PlcConnect { - - private static readonly Lazy lazy = new Lazy(() => new PlcConnect().CreateAb()); public static AllenBradleyNet Instance => lazy.Value; - private PlcConnect() { } + + + private void Init() + { + // 授权示例 Authorization example + if (!HslCommunication.Authorization.SetAuthorizationCode(RfidSetting.Current.HslKey)) + { + Console.WriteLine( "Authorization failed! The current program can only be used for 8 hours!" ); + return; // 激活失败应该退出系统 + } + } private AllenBradleyNet CreateAb() { + Init(); var rfidSetting = RfidSetting.Current; AllenBradleyNet ab = new AllenBradleyNet(); diff --git a/Tool/RfidSetting.cs b/Tool/RfidSetting.cs index 145ae3e..5ebb114 100644 --- a/Tool/RfidSetting.cs +++ b/Tool/RfidSetting.cs @@ -20,5 +20,6 @@ namespace Tool public int Port { get; set; }=44818; + public string HslKey { get; set; } = "4b133324-fea4-4766-b066-857279c92f5d"; } }