2using System.Collections.Generic;
3using Microsoft.Maker.RemoteWiring;
4using Microsoft.Maker.Serial;
5using Windows.Devices.Enumeration;
11 internal class UsbState : IDisposable
13 public Dictionary<string, Pin> Pins =
new Dictionary<string, Pin>();
14 public DeviceInformation DeviceInformation =
null;
15 public UsbSerial SerialPort =
null;
16 public RemoteDevice Device =
null;
17 public string Name =
string.Empty;
18 public bool Ready =
false;
20 internal void Device_DeviceConnectionLost(
string message)
23 Log.
Error(
"Device connection lost: " + message, this.Name);
26 internal void Device_DeviceConnectionFailed(
string message)
29 Log.
Error(
"Device connection failed: " + message, this.Name);
32 internal async
void Device_DeviceReady()
39 UsbConnectedDevice Port =
null;
44 Port = Node as UsbConnectedDevice;
45 if (!(Port is
null) && Port.PortName ==
this.Name)
54 Port =
new UsbConnectedDevice()
71 this.Pins[Pin.PinNrStr] = Pin;
84 internal void SerialPort_ConnectionEstablished()
89 internal void Device_DigitalPinUpdated(
byte pin, PinState state)
93 Pin Pin = this.GetPin(pin.ToString());
95 if (!(Pin is
null) && Pin is DigitalPin DigitalPin)
96 DigitalPin.Pin_ValueChanged(state);
104 internal async
void Device_AnalogPinUpdated(
string pin, ushort value)
108 Pin Pin = this.GetPin(pin);
110 if (!(Pin is
null) && Pin is AnalogInput AnalogInput)
111 await AnalogInput.Pin_ValueChanged(value);
119 internal Pin GetPin(
string PinNr)
123 if (this.Pins.TryGetValue(PinNr, out Pin Pin))
130 public void Dispose()
132 if (!(this.Device is
null))
134 this.Device.Dispose();
138 if (!(this.SerialPort is
null))
140 this.SerialPort.Dispose();
141 this.SerialPort =
null;
145 internal void AddPin(
string PinNr, Pin Pin)
149 if (!this.Pins.ContainsKey(PinNr))
150 this.Pins[PinNr] = Pin;
157 internal void RemovePin(
string PinNr, Pin Pin)
161 if (this.Pins.TryGetValue(PinNr, out Pin Pin2) && Pin2 == Pin)
162 this.Pins.Remove(PinNr);
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
static void Error(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an error event.
static void Informational(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an informational event.
Base class for all metering nodes.
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.
Defines the Metering Topology data source. This data source contains a tree structure of persistent r...
static Root Root
Root node.
Interface for nodes that are published through the concentrator interface.