6using System.Threading.Tasks;
55 #region ICommunicationLayer
79 if (!this.sniffers.Contains(Sniffer))
80 this.sniffers.Add(Sniffer);
100 public IEnumerator<ISniffer>
GetEnumerator() => this.sniffers.GetEnumerator();
106 IEnumerator IEnumerable.GetEnumerator() => this.sniffers.GetEnumerator();
120 public void ReceiveBinary(
bool ConstantBuffer,
byte[] Data) => this.sniffers.ReceiveBinary(ConstantBuffer, Data);
130 public void ReceiveBinary(
bool ConstantBuffer,
byte[] Data,
int Offset,
int Count) => this.sniffers.ReceiveBinary(ConstantBuffer, Data, Offset, Count);
144 public void TransmitBinary(
bool ConstantBuffer,
byte[] Data) => this.sniffers.TransmitBinary(ConstantBuffer, Data);
154 public void TransmitBinary(
bool ConstantBuffer,
byte[] Data,
int Offset,
int Count) => this.sniffers.TransmitBinary(ConstantBuffer, Data, Offset, Count);
160 public void ReceiveText(
string Text) => this.sniffers.ReceiveText(Text);
166 public void TransmitText(
string Text) => this.sniffers.TransmitText(Text);
172 public void Information(
string Comment) => this.sniffers.Information(Comment);
190 public void Exception(Exception Exception) => this.sniffers.Exception(Exception);
196 public void Exception(
string Exception) => this.sniffers.Exception(Exception);
203 public void ReceiveBinary(DateTime Timestamp,
int Count) => this.sniffers.ReceiveBinary(Timestamp, Count);
212 public void ReceiveBinary(DateTime Timestamp,
bool ConstantBuffer,
byte[] Data) => this.sniffers.ReceiveBinary(Timestamp, ConstantBuffer, Data);
223 public void ReceiveBinary(DateTime Timestamp,
bool ConstantBuffer,
byte[] Data,
int Offset,
int Count) => this.sniffers.ReceiveBinary(Timestamp, ConstantBuffer, Data, Offset, Count);
230 public void TransmitBinary(DateTime Timestamp,
int Count) => this.sniffers.TransmitBinary(Timestamp, Count);
240 public void TransmitBinary(DateTime Timestamp,
bool ConstantBuffer,
byte[] Data) => this.sniffers.TransmitBinary(Timestamp, ConstantBuffer, Data);
251 public void TransmitBinary(DateTime Timestamp,
bool ConstantBuffer,
byte[] Data,
int Offset,
int Count) => this.sniffers.TransmitBinary(Timestamp, ConstantBuffer, Data, Offset, Count);
258 public void ReceiveText(DateTime Timestamp,
string Text) => this.sniffers.ReceiveText(Timestamp, Text);
265 public void TransmitText(DateTime Timestamp,
string Text) => this.sniffers.TransmitText(Timestamp, Text);
272 public void Information(DateTime Timestamp,
string Comment) => this.sniffers.Information(Timestamp, Comment);
286 public void Error(DateTime Timestamp,
string Error) => this.sniffers.Error(Timestamp,
Error);
293 public void Exception(DateTime Timestamp,
string Exception) => this.sniffers.Exception(Timestamp, Exception);
300 public void Exception(DateTime Timestamp, Exception Exception) => this.sniffers.Exception(Timestamp, Exception);
304 #region TCP/IP connections
313 Result.Removed += Result_Removed;
329 return Task.CompletedTask;
338 StringBuilder sb =
new StringBuilder();
340 sb.Append(this.
Host);
341 sb.Append(this.
Port.ToString());
342 sb.Append(this.
Tls.ToString());
344 string Key = sb.ToString();
348 if (Client.Connected)
350 this.CheckSniffers(Client);
357 await clientsSynchObject.BeginWrite();
360 if (clients.TryGetValue(Key, out Client))
365 clients[Key] = Client;
369 await clientsSynchObject.EndWrite();
377 if (!Client.
HasSniffers && !
this.sniffers.HasSniffers)
384 foreach (
ISniffer Sniffer2
in this.sniffers.Sniffers)
386 if (Sniffer == Sniffer2)
397 foreach (
ISniffer Sniffer
in this.sniffers.Sniffers)
403 if (Sniffer == Sniffer2)
422 public override Task<IEnumerable<ICommand>>
Commands => this.GetCommands();
424 private async Task<IEnumerable<ICommand>> GetCommands()
426 List<ICommand>
Commands =
new List<ICommand>();
427 Commands.AddRange(await base.Commands);
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
void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been transmitted.
bool HasSniffers
If sniffers are registered
void Warning(string Warning)
Called to inform the viewer of a warning state.
void TransmitText(string Text)
Called when text has been transmitted.
override Task< IEnumerable< ICommand > > Commands
Available command objects. If no commands are available, null is returned.
void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
Called when binary data has been transmitted.
void Error(DateTime Timestamp, string Error)
Called to inform the viewer of an error state.
void TransmitBinary(DateTime Timestamp, int Count)
Called when binary data has been transmitted.
void ReceiveBinary(int Count)
Called when binary data has been received.
void TransmitBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been transmitted.
async Task< ModbusTcpClient > GetTcpIpConnection()
Gets the TCP/IP connection associated with this gateway.
void TransmitBinary(bool ConstantBuffer, byte[] Data)
Called when binary data has been transmitted.
void Information(string Comment)
Called to inform the viewer of something.
void ReceiveBinary(DateTime Timestamp, int Count)
Called when binary data has been received.
IEnumerator< ISniffer > GetEnumerator()
Gets an enumerator of registered sniffers.
void AddRange(IEnumerable< ISniffer > Sniffers)
Adds a range of sniffers
void ReceiveBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been received.
void ReceiveText(string Text)
Called when text has been received.
void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
Called when binary data has been received.
ISniffer[] Sniffers
Registered sniffers
void Warning(DateTime Timestamp, string Warning)
Called to inform the viewer of a warning state.
void Exception(DateTime Timestamp, string Exception)
Called to inform the viewer of an exception state.
void Error(string Error)
Called to inform the viewer of an error state.
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 ...
bool Remove(ISniffer Sniffer)
Removes a sniffer
void Exception(Exception Exception)
Called to inform the viewer of an exception state.
void ReceiveText(DateTime Timestamp, string Text)
Called when text has been received.
void TransmitBinary(int Count)
Called when binary data has been transmitted.
void Add(ISniffer Sniffer)
Adds a sniffer
void Exception(DateTime Timestamp, Exception Exception)
Called to inform the viewer of an exception state.
bool DecoupledEvents
If events raised from the communication layer are decoupled, i.e. executed in parallel with the sourc...
void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been received.
ModbusGatewayNode()
Node representing a TCP/IP connection to a Modbus Gateway
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
void Information(DateTime Timestamp, string Comment)
Called to inform the viewer of something.
void TransmitText(DateTime Timestamp, string Text)
Called when text has been transmitted.
void ReceiveBinary(bool ConstantBuffer, byte[] Data)
Called when binary data has been received.
void Exception(string 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.