Update IP4address if have null reading.
Create Nullchannel and null exception
This commit is contained in:
parent
af0da881f3
commit
25ef41b330
|
@ -0,0 +1,14 @@
|
|||
namespace InnovEnergy.Lib.Protocols.Modbus.Channels;
|
||||
|
||||
public class NullChannel : Channel
|
||||
{
|
||||
public override IReadOnlyList<Byte> Read(Int32 nBytes) => throw new NullChannelException();
|
||||
|
||||
public override void Write(IReadOnlyList<Byte> bytes)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class NullChannelException : Exception
|
||||
{
|
||||
}
|
|
@ -11,8 +11,8 @@ public class TcpChannel : ConnectionChannel<TcpClient>
|
|||
public TcpChannel(Ip4Address ip4Address,
|
||||
Boolean closeAfterSuccessfulRead = false,
|
||||
Boolean closeAfterSuccessfulWrite = false) :
|
||||
this(ip4Address.Host,
|
||||
ip4Address.Port,
|
||||
this(ip4Address.Host ?? "null",
|
||||
ip4Address.Port.HasValue ? (Int32)ip4Address.Port.Value : 0,
|
||||
closeAfterSuccessfulRead,
|
||||
closeAfterSuccessfulWrite)
|
||||
{
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
using System.Net;
|
||||
|
||||
namespace InnovEnergy.Lib.Utils.Net;
|
||||
|
||||
public class Ip4Address
|
||||
{
|
||||
public required String Host { get; init; }
|
||||
public required UInt16 Port { get; init; }
|
||||
public required String? Host { get; init; }
|
||||
public required UInt16? Port { get; init; }
|
||||
|
||||
public override String ToString() => $"{Host}:{Port}";
|
||||
|
||||
|
@ -18,6 +20,7 @@ public class Ip4Address
|
|||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != GetType()) return false;
|
||||
|
||||
return Equals((Ip4Address)obj);
|
||||
}
|
||||
|
||||
|
@ -25,4 +28,12 @@ public class Ip4Address
|
|||
public static Boolean operator !=(Ip4Address? left, Ip4Address? right) => !Equals(left, right);
|
||||
|
||||
public override Int32 GetHashCode() => ToString().GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue