From 9a890ef26feffe7fb463017a142a310b12003f21 Mon Sep 17 00:00:00 2001 From: Federico Barresi Date: Thu, 4 Feb 2021 22:09:58 +0100 Subject: [PATCH] Added Name property and override ToString - fixed value of PLCIpAddress --- Sharp7/S7Client.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Sharp7/S7Client.cs b/Sharp7/S7Client.cs index 2b70b04..7018fc0 100644 --- a/Sharp7/S7Client.cs +++ b/Sharp7/S7Client.cs @@ -661,6 +661,13 @@ namespace Sharp7 #region [Class Control] + public S7Client(string name) : this() + { + Name = name; + } + + public string Name { get; } + public S7Client() { CreateSocket(); @@ -671,6 +678,11 @@ namespace Sharp7 Disconnect(); } + public override string ToString() + { + return $"PLC {Name ?? string.Empty}@{PLCIpAddress ?? "0.0.0.0"}"; + } + public int Connect() { _LastError = 0; @@ -698,7 +710,6 @@ namespace Sharp7 public int ConnectTo(string Address, int Rack, int Slot) { - PLCIpAddress = Address; UInt16 RemoteTSAP = (UInt16)((ConnType << 8) + (Rack * 0x20) + Slot); SetConnectionParams(Address, 0x0100, RemoteTSAP); return Connect(); @@ -2269,7 +2280,7 @@ namespace Sharp7 } } - public string PLCIpAddress { get; private set; } + public string PLCIpAddress => IPAddress; public int PLCPort {