Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ReadModBusDiscreteInput.cs
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Threading.Tasks;
9using Waher.Script;
10
12{
17 {
24 : base(Parent, Model)
25 {
26 }
27
31 public override string LocalName => nameof(ReadModBusDiscreteInput);
32
40 {
42 }
43
49 public override async Task<LinkedListNode<IActivityNode>> Execute(Variables Variables)
50 {
51 ModBusClient Client = await this.GetClient(Variables);
52 byte Address = await this.address.GetUInt8ValueAsync(Variables);
53 ushort Register = await this.register.GetUInt16ValueAsync(Variables);
54 string VariableName = await this.responseVariable.GetValueAsync(Variables);
55
56 await Client.Lock();
57 try
58 {
59 if (!(Client.Client is null))
60 {
61 BitArray Bits = await Client.Client.ReadInputDiscretes(Address, Register, 1);
62 Variables[VariableName] = Bits[0];
63 }
64 }
65 finally
66 {
67 Client.Unlock();
68 }
69
70 return null;
71 }
72 }
73}
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 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.
ReadModBusDiscreteInput(ISimulationNode Parent, Model Model)
Reads a discrete input value.
override async Task< LinkedListNode< IActivityNode > > Execute(Variables Variables)
Executes a node.
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< BitArray > ReadInputDiscretes(byte UnitAddress, ushort ReferenceNumber, ushort NrBits)
Reads input discretes 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.