Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ModBusOperation.cs
1using System;
2using System.Threading.Tasks;
3using System.Xml;
8using Waher.Script;
9
11{
15 public abstract class ModBusOperation : ActivityNode
16 {
21
26
30 protected DoubleAttribute register;
31
38 : base(Parent, Model)
39 {
40 }
41
45 public override string Namespace => ModBusActor.ComSimModBusNamespace;
46
51
56 public override Task FromXml(XmlElement Definition)
57 {
58 foreach (XmlAttribute Attr in Definition.Attributes)
59 {
60 switch (Attr.Name)
61 {
62 case "client":
63 this.client = new StringAttribute(Attr.Value);
64 break;
65
66 case "address":
67 this.address = new DoubleAttribute(Attr.Name, Attr.Value);
68 break;
69
70 case "register":
71 this.register = new DoubleAttribute(Attr.Name, Attr.Value);
72 break;
73 }
74 }
75
76 return base.FromXml(Definition);
77 }
78
84 public async Task<ModBusClient> GetClient(Variables Variables)
85 {
86 object Obj = await this.Model.GetActorObjectAsync(this.client, Variables);
87 if (!(Obj is ModBusClient Client))
88 throw new Exception("Client ID does not point to a ModBus client.");
89
90 return Client;
91 }
92 }
93}
Abstract base class for ModBus operations.
override string Namespace
XML Namespace where the element is defined.
DoubleAttribute address
ModBus device Address attribute
ModBusOperation(ISimulationNode Parent, Model Model)
Abstract base class for ModBus operations.
async Task< ModBusClient > GetClient(Variables Variables)
Gets the ModBus TCP Client to use in the operation.
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
override string SchemaResource
Points to the embedded XML Schema resource defining the semantics of the XML namespace.
StringAttribute client
ModBus client to use in communication.
Abstract base class for ModBus actors.
Definition: ModBusActor.cs:9
const string ComSimModBusSchema
Resource name of ModBus schema.
Definition: ModBusActor.cs:18
const string ComSimModBusNamespace
http://lab.tagroot.io/Schema/ComSim.xsd
Definition: ModBusActor.cs:13
Represents a simulated ModBus client
Definition: ModBusClient.cs:16
Root node of a simulation model
Definition: Model.cs:49
Abstract base class for activity nodes
Definition: ActivityNode.cs:15
Contains the value of a double attribute, possibly with embedded script.
async Task< object > GetActorObjectAsync(StringAttribute Actor, Variables Variables)
Gets an actor object, given a string representation, possibly containing script, of the actor.
Contains the value of a string attribute, possibly with embedded script.
Collection of variables.
Definition: Variables.cs:25
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
ISimulationNode Parent
Parent node in the simulation model.