private void LoadDevice() { foreach (ChannelInfoControl child in Channels.Children.OfType <ChannelInfoControl>()) { child.ToggleStateClicked -= ChannelControl_ToggleStateClicked; } Channels.Children.Clear(); IRelayDeviceInfo device = GetCurrentDevice(); if (device == null) { return; } using (var relayController = new RelayController()) { relayController.ConnectDevice(device); List <IRelayChannelInfo> channels = relayController.ListChannels(device); foreach (var channel in channels) { var channelControl = new ChannelInfoControl(device, channel); channelControl.ToggleStateClicked += ChannelControl_ToggleStateClicked; Channels.Children.Add(channelControl); } } }
private void ChannelControl_ToggleStateClicked(object sender, ChannelToggledEventArgs e) { using (var relayController = new RelayController()) { relayController.ConnectDevice(e.DeviceInfo); var control = sender as ChannelInfoControl; control.ChannelInfo = relayController.ToggleChannel(e.DeviceInfo, e.ChannelInfo.Index); } }
private void CloseAllChannels() { IRelayDeviceInfo device = GetCurrentDevice(); if (device == null) { return; } using (var relayController = new RelayController()) { relayController.ConnectDevice(device); relayController.CloseAllChannels(device); } }