2using System.Collections;
3using System.Collections.Generic;
5using System.Threading.Tasks;
54 #region ICommunicationLayer
76 public void Add(
ISniffer Sniffer) => this.sniffers.Add(Sniffer);
95 public IEnumerator<ISniffer>
GetEnumerator() => this.sniffers.GetEnumerator();
101 IEnumerator IEnumerable.GetEnumerator() => this.sniffers.GetEnumerator();
107 public Task
ReceiveBinary(
byte[] Data) => this.sniffers.ReceiveBinary(Data);
119 public Task
ReceiveText(
string Text) => this.sniffers.ReceiveText(Text);
125 public Task
TransmitText(
string Text) => this.sniffers.TransmitText(Text);
131 public Task
Information(
string Comment) => this.sniffers.Information(Comment);
149 public Task
Exception(Exception Exception) => this.sniffers.Exception(Exception);
155 public Task
Exception(
string Exception) => this.sniffers.Exception(Exception);
162 public Task
ReceiveBinary(DateTime Timestamp,
byte[] Data) => this.sniffers.ReceiveBinary(Timestamp, Data);
169 public Task
TransmitBinary(DateTime Timestamp,
byte[] Data) => this.sniffers.TransmitBinary(Timestamp, Data);
176 public Task
ReceiveText(DateTime Timestamp,
string Text) => this.sniffers.ReceiveText(Timestamp, Text);
183 public Task
TransmitText(DateTime Timestamp,
string Text) => this.sniffers.TransmitText(Timestamp, Text);
190 public Task
Information(DateTime Timestamp,
string Comment) => this.sniffers.Information(Timestamp, Comment);
204 public Task
Error(DateTime Timestamp,
string Error) => this.sniffers.Error(Timestamp,
Error);
211 public Task
Exception(DateTime Timestamp,
string Exception) => this.sniffers.Exception(Timestamp, Exception);
218 public Task
Exception(DateTime Timestamp, Exception Exception) => this.sniffers.Exception(Timestamp, Exception);
222 #region TCP/IP connections
231 Result.Removed += Result_Removed;
247 return Task.CompletedTask;
256 StringBuilder sb =
new StringBuilder();
258 sb.Append(this.
Host);
259 sb.Append(this.
Port.ToString());
260 sb.Append(this.
Tls.ToString());
262 string Key = sb.ToString();
266 if (Client.Connected)
268 this.CheckSniffers(Client);
275 await clientsSynchObject.BeginWrite();
278 if (clients.TryGetValue(Key, out Client))
283 clients[Key] = Client;
287 await clientsSynchObject.EndWrite();
295 if (!Client.
HasSniffers && !
this.sniffers.HasSniffers)
302 foreach (
ISniffer Sniffer2
in this.sniffers.Sniffers)
304 if (Sniffer == Sniffer2)
315 foreach (
ISniffer Sniffer
in this.sniffers.Sniffers)
321 if (Sniffer == Sniffer2)
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Simple base class for classes implementing communication protocols.
virtual bool Remove(ISniffer Sniffer)
ICommunicationLayer.Remove
ISniffer[] Sniffers
Registered sniffers.
bool HasSniffers
If there are sniffers registered on the object.
virtual void Add(ISniffer Sniffer)
ICommunicationLayer.Add
static async Task< ModbusTcpClient > Connect(string Host, int Port, params ISniffer[] Sniffers)
Connects to an Modbus TCP/IP Gateway
Implements an in-memory cache.
Event arguments for cache item removal events.
ValueType Value
Value of item that was removed.
Contains information about a language.
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Represents an object that allows single concurrent writers but multiple concurrent readers....
string Host
Host name or IP address.
Node representing a port on an IP Host machine.
bool Tls
If connection is encrypted using TLS or not.
Node representing a TCP/IP connection to a Modbus Gateway
bool HasSniffers
If sniffers are registered
Task Information(DateTime Timestamp, string Comment)
Called to inform the viewer of something.
Task TransmitText(DateTime Timestamp, string Text)
Called when text has been transmitted.
Task ReceiveText(DateTime Timestamp, string Text)
Called when text has been received.
Task Exception(Exception Exception)
Called to inform the viewer of an exception state.
Task ReceiveBinary(byte[] Data)
Called when binary data has been received.
Task Exception(string Exception)
Called to inform the viewer of an exception state.
Task Error(DateTime Timestamp, string Error)
Called to inform the viewer of an error state.
Task ReceiveText(string Text)
Called when text has been received.
Task TransmitText(string Text)
Called when text has been transmitted.
async Task< ModbusTcpClient > GetTcpIpConnection()
Gets the TCP/IP connection associated with this gateway.
IEnumerator< ISniffer > GetEnumerator()
Gets an enumerator of registered sniffers.
void AddRange(IEnumerable< ISniffer > Sniffers)
Adds a range of sniffers
ISniffer[] Sniffers
Registered sniffers
Task Exception(DateTime Timestamp, string Exception)
Called to inform the viewer of an exception state.
Task Information(string Comment)
Called to inform the viewer of something.
Task ReceiveBinary(DateTime Timestamp, byte[] Data)
Called when binary data has been received.
override Task< bool > AcceptsChildAsync(INode Child)
If the node accepts a presumptive child, i.e. can receive as a child (if that child accepts the node ...
Task Warning(string Warning)
Called to inform the viewer of a warning state.
bool Remove(ISniffer Sniffer)
Removes a sniffer
Task TransmitBinary(DateTime Timestamp, byte[] Data)
Called when binary data has been transmitted.
void Add(ISniffer Sniffer)
Adds a sniffer
bool DecoupledEvents
If events raised from the communication layer are decoupled, i.e. executed in parallel with the sourc...
ModbusGatewayNode()
Node representing a TCP/IP connection to a Modbus Gateway
Task Warning(DateTime Timestamp, string Warning)
Called to inform the viewer of a warning state.
Task Error(string Error)
Called to inform the viewer of an error state.
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
Task TransmitBinary(byte[] Data)
Called when binary data has been transmitted.
Task Exception(DateTime Timestamp, Exception Exception)
Called to inform the viewer of an exception state.
Represents a Unit Device on a Modbus network.
Interface for observable classes implementing communication protocols.
Interface for sniffers. Sniffers can be added to ICommunicationLayer classes to eavesdrop on communic...
Interface for nodes that are published through the concentrator interface.