Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
UsbConnectedDevice.cs
1using System.Collections.Generic;
2using System.Threading.Tasks;
3using Microsoft.Maker.RemoteWiring;
9
11{
16 {
17 private string portName = string.Empty;
18
23 : base()
24 {
25 }
26
30 [Page(2, "Port")]
31 [Header(3, "Name:")]
32 [ToolTip(4, "Name of USB serial port.")]
33 [DefaultValueStringEmpty]
34 public string PortName
35 {
36 get => this.portName;
37 set => this.portName = value;
38 }
39
43 public RemoteDevice Device
44 {
45 get
46 {
47 return Module.GetDevice(this.portName);
48 }
49 }
50
54 public override Task AddAsync(INode Child)
55 {
56 Task Result = base.AddAsync(Child);
57
58 UsbState State = Module.GetState(this.portName);
59 if (!(State is null) && Child is Pin Pin)
60 State.AddPin(Pin.PinNrStr, Pin);
61
62 return Result;
63 }
64
68 public override async Task<bool> RemoveAsync(INode Child)
69 {
70 bool Result = await base.RemoveAsync(Child);
71
72 UsbState State = Module.GetState(this.portName);
73 if (!(State is null) && Child is Pin Pin)
74 State.RemovePin(Pin.PinNrStr, Pin);
75
76 return Result;
77 }
78
82 protected override void SortChildrenAfterLoadLocked(List<MeteringNode> Children)
83 {
84 base.SortChildrenAfterLoadLocked(Children);
85
86 if (!(Children is null))
87 {
88 UsbState State = Module.GetState(this.portName);
89 if (!(State is null))
90 {
91 MeteringNode[] Children2 = Children.ToArray();
92
93 Task.Run(() =>
94 {
95 lock (State.Pins)
96 {
97 foreach (INode Node in Children2)
98 {
99 if (Node is Pin Pin)
100 State.Pins[Pin.PinNrStr] = Pin;
101 }
102 }
103 });
104 }
105 }
106 }
107
111 public override Task<bool> AcceptsChildAsync(INode Child)
112 {
113 return Task.FromResult<bool>(Child is Pin);
114 }
115
119 public override Task<bool> AcceptsParentAsync(INode Parent)
120 {
121 return Task.FromResult<bool>(Parent is Root);
122 }
123
127 public override Task<string> GetTypeNameAsync(Language Language)
128 {
129 return Language.GetStringAsync(typeof(Module), 1, "USB Connected Device");
130 }
131 }
132}
133
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
abstract string PinNrStr
TODO
Definition: Pin.cs:43
override Task< bool > AcceptsChildAsync(INode Child)
TODO
override void SortChildrenAfterLoadLocked(List< MeteringNode > Children)
TODO
override Task< string > GetTypeNameAsync(Language Language)
TODO
override Task AddAsync(INode Child)
TODO
override Task< bool > AcceptsParentAsync(INode Parent)
TODO
override async Task< bool > RemoveAsync(INode Child)
TODO
Base class for all metering nodes.
Definition: MeteringNode.cs:28
NodeState State
Current overall state of the node.
INode Parent
Parent Node, or null if a root node.
Class for the root node of the Metering topology.
Definition: Root.cs:11
Interface for nodes that are published through the concentrator interface.
Definition: INode.cs:49