Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ModbusCompositeChildNode.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
8
10{
15 {
20 : base()
21 {
22 }
23
29 public override Task<string> GetTypeNameAsync(Language Language)
30 {
31 return Language.GetStringAsync(typeof(ModbusGatewayNode), 28, "Composite Node");
32 }
33
39 public override Task<bool> AcceptsParentAsync(INode Parent)
40 {
41 return Task.FromResult(Parent is ModbusUnitNode);
42 }
43
49 public override Task<bool> AcceptsChildAsync(INode Child)
50 {
51 return Task.FromResult(Child is ModbusUnitChildNode);
52 }
53
58 public async Task StartReadout(ISensorReadout Request)
59 {
60 try
61 {
62 foreach (INode Child in await this.ChildNodes)
63 {
64 if (Child is ISensor Sensor)
65 {
66 TaskCompletionSource<bool> ReadoutCompleted = new TaskCompletionSource<bool>();
67
68 InternalReadoutRequest InternalReadout = new InternalReadoutRequest(this.LogId, null, Request.Types, Request.FieldNames,
69 Request.From, Request.To,
70 (Sender, e) =>
71 {
72 foreach (Field F in e.Fields)
73 F.Thing = this;
74
75 Request.ReportFields(false, e.Fields);
76
77 if (e.Done)
78 ReadoutCompleted.TrySetResult(true);
79
80 return Task.CompletedTask;
81 },
82 (Sender, e) =>
83 {
84 List<ThingError> Errors2 = new List<ThingError>();
85
86 foreach (ThingError Error in e.Errors)
87 Errors2.Add(new ThingError(this, Error.ErrorMessage));
88
89 Request.ReportErrors(false, Errors2.ToArray());
90
91 if (e.Done)
92 ReadoutCompleted.TrySetResult(true);
93
94 return Task.CompletedTask;
95 }, null);
96
97 await Sensor.StartReadout(InternalReadout);
98
99 Task Timeout = Task.Delay(60000);
100
101 Task T = await Task.WhenAny(ReadoutCompleted.Task, Timeout);
102
103 if (!ReadoutCompleted.Task.IsCompleted)
104 await Request.ReportErrors(false, new ThingError(this, "Timeout."));
105 }
106 }
107 }
108 catch (Exception ex)
109 {
110 await Request.ReportErrors(false, new ThingError(this, ex.Message));
111 }
112 finally
113 {
114 await Request.ReportFields(true);
115 }
116 }
117
122 public async Task<ControlParameter[]> GetControlParameters()
123 {
124 List<ControlParameter> Result = new List<ControlParameter>();
125
126 foreach (INode Child in await this.ChildNodes)
127 {
128 if (Child is IActuator Actuator)
129 Result.AddRange(await Actuator.GetControlParameters());
130 }
131
132 return Result.ToArray();
133 }
134
135 }
136}
Manages a chat sensor data readout request.
Contains information about a language.
Definition: Language.cs:17
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 ...
Definition: Language.cs:209
Represents a composition of nodes, under a unit.
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...
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
async Task StartReadout(ISensorReadout Request)
Starts the readout of the sensor.
ModbusCompositeChildNode()
Represents a composition of nodes, under a unit.
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 ...
async Task< ControlParameter[]> GetControlParameters()
Get control parameters for the actuator.
Node representing a TCP/IP connection to a Modbus Gateway
Abstract base class for child nodes to Mobus Unit nodes.
Represents a Unit Device on a Modbus network.
Contains information about an error on a thing
Definition: ThingError.cs:10
Interface for actuator nodes.
Definition: IActuator.cs:10
Interface for nodes that are published through the concentrator interface.
Definition: INode.cs:49
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.
Definition: INode.cs:140
INode Parent
Parent Node, or null if a root node.
Definition: INode.cs:116
string LogId
If provided, an ID for the node, as it would appear or be used in system logs. Can be null,...
Definition: INode.cs:62
Interface for sensor nodes.
Definition: ISensor.cs:9
Interface for classes managing sensor data readouts.
string[] FieldNames
Names of fields to read.
Task ReportErrors(bool Done, params ThingError[] Errors)
Report error states to the client.
FieldType Types
Field Types to read.
DateTime To
To what time readout is to be made. Use DateTime.MaxValue to specify no upper limit.
Task ReportFields(bool Done, params Field[] Fields)
Report read fields to the client.
DateTime From
From what time readout is to be made. Use DateTime.MinValue to specify no lower limit.