private static void OnDeviceConnected() { Console.WriteLine("Device connected"); Frequency = _device.ReadParam <SamplingFrequency>(Parameter.SamplingFrequency); Rewrite(); _device.AddIntChannelDataListener(BatteryChannel_DataReceived, DeviceTraits.GetChannelsWithType(_device, ChannelType.Battery)[0]); if (Frequency != SamplingFrequency.Hz250) { _device.SetParam(Parameter.SamplingFrequency, SamplingFrequency.Hz250); Frequency = _device.ReadParam <SamplingFrequency>(Parameter.SamplingFrequency); } var channelInfos = _device.Channels; foreach (var channelInfo in channelInfos) { if (channelInfo.Type != ChannelType.Signal) { continue; } _device.AddSignalChannelDataListener(SignalChannel_DataReceived, channelInfo); _channels[channelInfo.Name] = 0.0; } _device.Execute(Command.StartSignal); }
private void UpdateBatterySubscription() { if (ConnectionState == DeviceState.Connected) { if (DeviceTraits.HasChannelsWithType(_device, ChannelType.Battery)) { _device.AddIntChannelDataListener( OnBatteryChargeChanged, DeviceTraits.GetChannelsWithType(_device, ChannelType.Battery)[0] ); _needBatteryUnsubscribe = true; } } else if (_needBatteryUnsubscribe) { _needBatteryUnsubscribe = false; _device.RemoveIntChannelDataListener(OnBatteryChargeChanged); } }
private void _deviceModel_DeviceFound(object sender, Device device) { if (device == null) { return; } Invoke((MethodInvoker) delegate { _deviceLabel.Text = device.ReadParam <string>(Parameter.Name); _startSignalButton.Enabled = DeviceTraits.HasChannelsWithType(device, ChannelType.Signal); _stopButton.Enabled = _startSignalButton.Enabled; _channelComboBox.Items.Clear(); _channelComboBox.Items.AddRange(CreateChannels(device).ToArray()); if (_channelComboBox.Items.Count > 0) { _channelComboBox.SelectedIndex = 0; } _channelComboBox.Enabled = true; }); }
private static IEnumerable <ChannelAdapter <double> > CreateChannels(Device device) { var channels = DeviceTraits.GetChannelsWithType(device, ChannelType.Signal) .Select(channelInfo => CreateChannelForDevice(device, channelInfo)) .Cast <IDataChannel <double> >() .ToList(); var channelAdapters = new List <ChannelAdapter <double> >(); foreach (var signalChannel in channels) { channelAdapters.Add(new ChannelAdapter <double>(signalChannel)); } for (var i = 0; i < channels.Count - 1; ++i) { for (var j = i + 1; j < channels.Count; ++j) { var bipolarChannel = new BipolarDoubleChannel(channels[i], channels[j]); channelAdapters.Add(new ChannelAdapter <double>(bipolarChannel)); } } return(channelAdapters); }