From 3a2364d2e50dbffab6dd106e99a734427e5b0a50 Mon Sep 17 00:00:00 2001 From: "nodyang@aliyun.com" Date: Tue, 3 Dec 2024 11:09:36 +0800 Subject: [PATCH] logn --- HighWayIot.Log4net/LogHelper.cs | 2 +- HighWayIot.Plc/HighWayIot.Plc.csproj | 4 +--- HighWayIot.Plc/PlcConnect.cs | 33 +++++++++++++++------------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/HighWayIot.Log4net/LogHelper.cs b/HighWayIot.Log4net/LogHelper.cs index c36ef08..22680fe 100644 --- a/HighWayIot.Log4net/LogHelper.cs +++ b/HighWayIot.Log4net/LogHelper.cs @@ -113,7 +113,7 @@ namespace HighWayIot.Log4net /// /// 记录Error日志 /// - /// + /// /// public void Error(string info, Exception ex = null) { diff --git a/HighWayIot.Plc/HighWayIot.Plc.csproj b/HighWayIot.Plc/HighWayIot.Plc.csproj index fd0970d..d3d98be 100644 --- a/HighWayIot.Plc/HighWayIot.Plc.csproj +++ b/HighWayIot.Plc/HighWayIot.Plc.csproj @@ -59,8 +59,6 @@ HighWayIot.Log4net - - - + \ No newline at end of file diff --git a/HighWayIot.Plc/PlcConnect.cs b/HighWayIot.Plc/PlcConnect.cs index eca1006..b4ffcbc 100644 --- a/HighWayIot.Plc/PlcConnect.cs +++ b/HighWayIot.Plc/PlcConnect.cs @@ -1,16 +1,17 @@ using System; using HighWayIot.Log4net; using HslCommunication; -using HslCommunication.LogNet; -using HslCommunication.Profinet.AllenBradley; using HslCommunication.Profinet.Melsec; namespace HighWayIot.Plc { public class PlcConnect { private static LogHelper logNet = LogHelper.Instance; - private static readonly Lazy lazy = new Lazy(() => new PlcConnect().CreateAb()); - public static MelsecMcNet Instance => lazy.Value; + /// + /// 静态懒加载 + /// + private static readonly MelsecMcNet Instance = new PlcConnect().CreateAb(); + private PlcConnect() { @@ -29,7 +30,7 @@ namespace HighWayIot.Plc string Ip = ""; MelsecMcNet plc = new MelsecMcNet(); - plc.CommunicationPipe = new HslCommunication.Core.Pipe.PipeTcpNet(Ip, 44818) + plc.CommunicationPipe = new HslCommunication.Core.Pipe.PipeTcpNet(Ip, 0) { ConnectTimeOut = 1000, // 连接超时时间,单位毫秒 SleepTime = 0, @@ -64,16 +65,18 @@ namespace HighWayIot.Plc } } - - /// - /// 写入数据 - /// - /// 地址 - /// 值 - /// 数据类型 - /// - public static OperateResult Write(string address, object value, DataTypeEnum type) + + + + /// + /// 写入数据 + /// + /// 地址 + /// 值 + /// 数据类型 + /// + public static OperateResult Write(string address, object value, DataTypeEnum type) { var result = new OperateResult() { IsSuccess = false }; switch (type) @@ -111,7 +114,7 @@ namespace HighWayIot.Plc break; } - logNet.Info($"write 地址[{address}] value:[{value.ToString()}] type:[{type.ToString()}] result:[{result.IsSuccess}]"); + logNet.Info($"write 地址[{address}] value:[{value}] type:[{type.ToString()}] result:[{result.IsSuccess}]"); return result; }