3using System.Net.NetworkInformation;
5using System.Threading.Tasks;
26 private string host =
string.Empty;
27 private bool pingHost =
true;
36 return Task.FromResult(
49 return Task.FromResult(
68 [Header(2,
"Host Name:", 50)]
69 [ToolTip(3,
"Host Name or IP Address of device.")]
70 [DefaultValueStringEmpty]
75 set => this.host = value;
82 [Header(38,
"Ping host.", 50)]
83 [ToolTip(39,
"If host name should be pinged during readout.")]
88 set => this.pingHost = value;
104 string Module = typeof(
IpHost).Namespace;
111 DateTime Now = DateTime.UtcNow;
112 string Protocol = Monitor.Protocol;
116 if (
string.IsNullOrEmpty(Protocol))
117 Protocol = Monitor.Port.ToString();
122 (DateTime.UtcNow - Now).TotalMilliseconds, 0,
"ms",
128 "Unable to connect using " + Protocol +
": " + ex.Message));
135 using Ping Icmp =
new Ping();
137 PingReply
Response = await Icmp.SendPingAsync(this.host, 2000, data, options);
138 DateTime Now = DateTime.UtcNow;
140 if (
Response.Status == IPStatus.Success)
157 catch (PingException ex)
159 if (!(ex.InnerException is
null))
160 await
Request.ReportErrors(
true,
new ThingError(
this, ex.InnerException.Message));
170 private static string GetErrorMessage(PingReply
Response)
172 return Response.Status
switch
174 IPStatus.Success =>
null,
175 IPStatus.BadDestination =>
"Bad destination",
176 IPStatus.BadHeader =>
"Bad header",
177 IPStatus.BadOption =>
"Bad option",
178 IPStatus.BadRoute =>
"Bad route",
179 IPStatus.DestinationHostUnreachable =>
"Destination host unreachable",
180 IPStatus.DestinationNetworkUnreachable =>
"Destination network unreachable",
181 IPStatus.DestinationPortUnreachable =>
"Destination port unreachable",
182 IPStatus.DestinationProhibited =>
"Destination prohibited",
184 IPStatus.DestinationScopeMismatch =>
"Destination scope mismatch",
185 IPStatus.DestinationUnreachable =>
"Destination unreachable",
186 IPStatus.HardwareError =>
"Hardware error",
187 IPStatus.IcmpError =>
"ICMP error",
188 IPStatus.NoResources =>
"No resources",
189 IPStatus.PacketTooBig =>
"Packet too big",
190 IPStatus.ParameterProblem =>
"Parameter problem",
191 IPStatus.SourceQuench =>
"Source quench",
192 IPStatus.TimedOut =>
"Timed out",
193 IPStatus.TimeExceeded =>
"Time exceeded",
194 IPStatus.TtlExpired =>
"TTL expired",
195 IPStatus.TtlReassemblyTimeExceeded =>
"TTL reassembly time exceeded",
196 IPStatus.UnrecognizedNextHeader =>
"Unrecognized next header",
197 _ =>
"Unknown error",
201 private static readonly
byte[] data = Encoding.ASCII.GetBytes(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
202 private static readonly PingOptions options =
new PingOptions(64,
true);
212 LinkedList<Parameter> Result = await base.GetDisplayableParametersAsync(
Language, Caller) as LinkedList<Parameter>;
Implements a binary TCP Client, by encapsulating a TcpClient. It also makes the use of TcpClient safe...
Access to the current request.
Access to the current response.
A chunked list is a linked list of chunks of objects of type T .
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 ...
Extract the fields of a type or an object.
Makes sure an expression is defined. Otherwise, an exception is thrown.
Node representing an IP Host machine.
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
async override Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
override bool IsReadable
If the node can be read.
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 ...
virtual async Task StartReadout(ISensorReadout Request)
Starts the readout of the sensor.
override Task< bool > AcceptsParentAsync(INode Parent)
If the node accepts a presumptive parent, i.e. can be added to that parent (if that parent accepts th...
string Host
Host name or IP address.
bool PingHost
If host should be pinged during readout.
Node representing a port on an IP Host machine.
Class for the root node of the Metering topology.
Base class for all provisioned metering nodes.
Tokens available in request.
Represents a physical quantity value.
Represents a string value.
Contains information about an error on a thing
Interface for objects that contain a reference to a host.
Interface for nodes that are published through the concentrator interface.
bool IsReadable
If the node can be read.
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.
INode Parent
Parent Node, or null if a root node.
Interface for sensor nodes.
Interface for classes managing sensor data readouts.
FieldQoS
Field Quality of Service flags
FieldType
Field Type flags