Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ReadModBusHoldingRegister.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
8using Waher.Script;
9
11{
16 {
23 : base(Parent, Model)
24 {
25 }
26
30 public override string LocalName => nameof(ReadModBusHoldingRegister);
31
39 {
41 }
42
48 public override async Task<LinkedListNode<IActivityNode>> Execute(Variables Variables)
49 {
50 ModBusClient Client = await this.GetClient(Variables);
51 byte Address = await this.address.GetUInt8ValueAsync(Variables);
52 ushort Register = await this.register.GetUInt16ValueAsync(Variables);
53 string VariableName = await this.responseVariable.GetValueAsync(Variables);
54
55 await Client.Lock();
56 try
57 {
58 if (!(Client.Client is null))
59 {
60 ushort[] Words = await Client.Client.ReadMultipleRegisters(Address, Register, 1);
61 Variables[VariableName] = Words[0];
62 }
63 }
64 finally
65 {
66 Client.Unlock();
67 }
68
69 return null;
70 }
71 }
72}
DoubleAttribute address
ModBus device Address attribute
async Task< ModBusClient > GetClient(Variables Variables)
Gets the ModBus TCP Client to use in the operation.
Abstract base class for ModBus read operations.
StringAttribute responseVariable
Response variable attribute.
Represents a simulated ModBus client
Definition: ModBusClient.cs:16
void Unlock()
Unlocks the client.
ModbusTcpClient Client
ModBus TCP client reference.
async Task Lock()
Locks the client for use by one caller.
override async Task< LinkedListNode< IActivityNode > > Execute(Variables Variables)
Executes a node.
override string LocalName
Local name of XML element defining contents of class.
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
ReadModBusHoldingRegister(ISimulationNode Parent, Model Model)
Reads a holding register value.
Root node of a simulation model
Definition: Model.cs:49
void Register(IActivityNode Node)
Registers a child activity node.
Definition: ActivityNode.cs:63
async Task< ushort[]> ReadMultipleRegisters(byte UnitAddress, ushort ReferenceNumber, ushort NrWords)
Reads multiple registers from a Modbus unit.
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.