Added Name property and override ToString

- fixed value of PLCIpAddress
This commit is contained in:
Federico Barresi
2021-02-04 22:09:58 +01:00
parent 2bc47b1b14
commit 9a890ef26f

View File

@@ -661,6 +661,13 @@ namespace Sharp7
#region [Class Control] #region [Class Control]
public S7Client(string name) : this()
{
Name = name;
}
public string Name { get; }
public S7Client() public S7Client()
{ {
CreateSocket(); CreateSocket();
@@ -671,6 +678,11 @@ namespace Sharp7
Disconnect(); Disconnect();
} }
public override string ToString()
{
return $"PLC {Name ?? string.Empty}@{PLCIpAddress ?? "0.0.0.0"}";
}
public int Connect() public int Connect()
{ {
_LastError = 0; _LastError = 0;
@@ -698,7 +710,6 @@ namespace Sharp7
public int ConnectTo(string Address, int Rack, int Slot) public int ConnectTo(string Address, int Rack, int Slot)
{ {
PLCIpAddress = Address;
UInt16 RemoteTSAP = (UInt16)((ConnType << 8) + (Rack * 0x20) + Slot); UInt16 RemoteTSAP = (UInt16)((ConnType << 8) + (Rack * 0x20) + Slot);
SetConnectionParams(Address, 0x0100, RemoteTSAP); SetConnectionParams(Address, 0x0100, RemoteTSAP);
return Connect(); return Connect();
@@ -2269,7 +2280,7 @@ namespace Sharp7
} }
} }
public string PLCIpAddress { get; private set; } public string PLCIpAddress => IPAddress;
public int PLCPort public int PLCPort
{ {