protected override void SortChildrenAfterLoadLocked(List <MeteringNode> Children) { base.SortChildrenAfterLoadLocked(Children); if (Children != null) { UsbState State = Module.GetState(this.portName); if (State != null) { MeteringNode[] Children2 = Children.ToArray(); Task.Run(() => { lock (State.Pins) { foreach (INode Node in Children2) { if (Node is Pin Pin) { State.Pins[Pin.PinNrStr] = Pin; } } } }); } } }
public override Task DestroyAsync() { Task Result = base.DestroyAsync(); if (this.Parent is UsbConnectedDevice UsbConnectedDevice) { UsbState State = Module.GetState(UsbConnectedDevice.PortName); State?.RemovePin(this.PinNrStr, this); } return(Result); }
public override async Task <bool> RemoveAsync(INode Child) { bool Result = await base.RemoveAsync(Child); UsbState State = Module.GetState(this.portName); if (State != null && Child is Pin Pin) { State.RemovePin(Pin.PinNrStr, Pin); } return(Result); }
public override Task AddAsync(INode Child) { Task Result = base.AddAsync(Child); UsbState State = Module.GetState(this.portName); if (State != null && Child is Pin Pin) { State.AddPin(Pin.PinNrStr, Pin); } return(Result); }
private async void Init(ManualResetEvent Done) { try { DeviceInformationCollection Devices = await UsbSerial.listAvailableDevicesAsync(); UsbState State; foreach (DeviceInformation DeviceInfo in Devices) { if (!DeviceInfo.IsEnabled) { continue; } lock (serialPorts) { State = new UsbState() { Name = DeviceInfo.Name, DeviceInformation = DeviceInfo, SerialPort = new UsbSerial(DeviceInfo) }; State.SerialPort.ConnectionEstablished += State.SerialPort_ConnectionEstablished; State.Device = new RemoteDevice(State.SerialPort); State.Device.DeviceReady += State.Device_DeviceReady; State.Device.AnalogPinUpdated += State.Device_AnalogPinUpdated; State.Device.DigitalPinUpdated += State.Device_DigitalPinUpdated; State.Device.DeviceConnectionFailed += State.Device_DeviceConnectionFailed; State.Device.DeviceConnectionLost += State.Device_DeviceConnectionLost; serialPorts[DeviceInfo.Name] = State; } State.SerialPort.begin(57600, SerialConfig.SERIAL_8N1); } } catch (Exception ex) { Log.Critical(ex); } finally { Done.Set(); } }
public void Stop() { UsbState[] States; lock (serialPorts) { States = new UsbState[serialPorts.Count]; serialPorts.Values.CopyTo(States, 0); serialPorts.Clear(); } foreach (UsbState State in States) { State.Dispose(); } }
public Task Stop() { UsbState[] States; lock (serialPorts) { States = new UsbState[serialPorts.Count]; serialPorts.Values.CopyTo(States, 0); serialPorts.Clear(); } foreach (UsbState State in States) { State.Dispose(); } return(Task.CompletedTask); }