public async System.Threading.Tasks.Task CreateAudioGraphAsync(string outputFileName) { Windows.Media.Audio.AudioGraphSettings graphSettings = new Windows.Media.Audio.AudioGraphSettings(Windows.Media.Render.AudioRenderCategory.Media); graphSettings.QuantumSizeSelectionMode = Windows.Media.Audio.QuantumSizeSelectionMode.LowestLatency; // TODO: let user pick from list of devices instead of blindly picking first one -- hoping for the microphone. Windows.Devices.Enumeration.DeviceInformationCollection deviceInformationCollection = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.AudioRender); Windows.Devices.Enumeration.DeviceInformation deviceInformation = deviceInformationCollection[0]; // blindly pick first one graphSettings.PrimaryRenderDevice = deviceInformation; Windows.Media.Audio.CreateAudioGraphResult result = await Windows.Media.Audio.AudioGraph.CreateAsync(graphSettings); if (result.Status != Windows.Media.Audio.AudioGraphCreationStatus.Success) { WoundifyShared.Log.WriteLine("Cannot create graph:" + result.Status.ToString()); return; } graph = result.Graph; await AudioDeviceInputAsync(); // setup microphone (usually) //await AudioDeviceOutputAsync(); // setup speakers (usually) await AudioFileOutputAsync(WoundifyShared.Options.options.tempFolderPath + outputFileName); // setup file deviceInputNode.AddOutgoingConnection(fileOutputNode); }
public static async Task <UARTDevice> CreateUARTDeviceAsync(string deviceName) { Log.WriteLine("finding device {0}", deviceName != null ? deviceName : "(default)"); Windows.Devices.Enumeration.DeviceInformation info = null; if (deviceName != null) { info = await FindAsync(SerialDevice.GetDeviceSelector(deviceName)); } else { info = await FindAsync(SerialDevice.GetDeviceSelector()); } Log.WriteLine("UART device info {0} null. selected {1}", info == null ? "is" : "is not", info.Id); var d = new UARTDevice(); d.Device = await AsAsync(SerialDevice.FromIdAsync(info.Id)); d.Device.DataBits = 8; d.Device.Handshake = SerialHandshake.None; d.Device.BaudRate = 9600; d.Device.WriteTimeout = TimeSpan.FromMilliseconds(1000); d.Device.ReadTimeout = TimeSpan.FromMilliseconds(1000); d.Device.StopBits = SerialStopBitCount.One; d.Device.Parity = SerialParity.None; Log.WriteLine("UART Settings complete"); d._write = new DataWriter(d.Device.OutputStream); Log.WriteLine("have datawriter"); return(d); }
/// <summary> /// Event handler for arrival of devices /// </summary> /// <param name="sender"></param> /// <param name="devInterface">The device interface which was added</param> private void OnAdded(Windows.Devices.Enumeration.DeviceWatcher sender, Windows.Devices.Enumeration.DeviceInformation devInterface) { // search the device list for a device with a matching interface ID DeviceListEntry match = FindInList(devInterface.Id); // If we found a match then mark it as verified and return if (match != null) { if (match.Matched == false) { DeviceAdded(this, new UsbDeviceInfo(match)); } match.Matched = true; return; } // Create a new element for this device interface, and queue up the query of its // device information match = new DeviceListEntry(devInterface); // Add the new element to the end of the list of devices this.devices.Add(match); DeviceAdded(this, new UsbDeviceInfo(match)); }
// // // public async Task setMidiInputPortId(Windows.Devices.Enumeration.DeviceInformation Di) { this.midiInputPort = await MidiInPort.FromIdAsync(Di.Id); // this.midiInputPort.MessageReceived += MidiInputDevice_MessageReceived; }
public static async Task <PWMDevice> CreatePWMDeviceAsync(string deviceName, int pinNumber) { Log.WriteLine("finding device {0}", deviceName != null ? deviceName : "(default)"); Windows.Devices.Enumeration.DeviceInformation info = null; if (deviceName != null) { info = await FindAsync(PwmController.GetDeviceSelector(deviceName)); } else { info = await FindAsync(PwmController.GetDeviceSelector()); } Log.WriteLine("PWM device info {0} null", info == null ? "is" : "is not"); var d = new PWMDevice(); d.Device = await AsAsync(PwmController.FromIdAsync(info.Id)); if (d.Device != null) { Log.WriteLine("Pin Count {0}", d.Device.PinCount); } d.Pin = d.Device.OpenPin(pinNumber); return(d); }
public static async Task CreateDeviceInputNode() { Console.WriteLine("Creating AudioGraphs"); // Create an AudioGraph with default settings AudioGraphSettings graphsettings = new AudioGraphSettings(AudioRenderCategory.GameChat); graphsettings.EncodingProperties = new AudioEncodingProperties(); graphsettings.EncodingProperties.Subtype = "Float"; graphsettings.EncodingProperties.SampleRate = 48000; graphsettings.EncodingProperties.ChannelCount = 2; graphsettings.EncodingProperties.BitsPerSample = 32; graphsettings.EncodingProperties.Bitrate = 3072000; //settings.DesiredSamplesPerQuantum = 960; //settings.QuantumSizeSelectionMode = QuantumSizeSelectionMode.ClosestToDesired; CreateAudioGraphResult graphresult = await AudioGraph.CreateAsync(graphsettings); if (graphresult.Status != AudioGraphCreationStatus.Success) { // Cannot create graph return; } ingraph = graphresult.Graph; AudioGraphSettings nodesettings = new AudioGraphSettings(AudioRenderCategory.GameChat); nodesettings.EncodingProperties = AudioEncodingProperties.CreatePcm(48000, 2, 16); nodesettings.DesiredSamplesPerQuantum = 960; nodesettings.QuantumSizeSelectionMode = QuantumSizeSelectionMode.ClosestToDesired; frameOutputNode = ingraph.CreateFrameOutputNode(outgraph.EncodingProperties); quantum = 0; ingraph.QuantumStarted += Graph_QuantumStarted; Windows.Devices.Enumeration.DeviceInformation selectedDevice = await Windows.Devices.Enumeration.DeviceInformation.CreateFromIdAsync(Windows.Media.Devices.MediaDevice.GetDefaultAudioCaptureId(Windows.Media.Devices.AudioDeviceRole.Default)); CreateAudioDeviceInputNodeResult result = await ingraph.CreateDeviceInputNodeAsync(MediaCategory.Media, nodesettings.EncodingProperties, selectedDevice); if (result.Status != AudioDeviceNodeCreationStatus.Success) { // Cannot create device output node return; } deviceInputNode = result.DeviceInputNode; deviceInputNode.AddOutgoingConnection(frameOutputNode); frameOutputNode.Start(); ingraph.Start(); }
//</SnippetCreateDeviceOutputNode> private async Task EnumerateAudioCaptureDevices() { //<SnippetEnumerateAudioCaptureDevices> Windows.Devices.Enumeration.DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Media.Devices.MediaDevice.GetAudioCaptureSelector()); // Show UI to allow the user to select a device Windows.Devices.Enumeration.DeviceInformation selectedDevice = ShowMyDeviceSelectionUI(devices); CreateAudioDeviceInputNodeResult result = await audioGraph.CreateDeviceInputNodeAsync(Windows.Media.Capture.MediaCategory.Media, audioGraph.EncodingProperties, selectedDevice); //</SnippetEnumerateAudioCaptureDevices> }
//</SnippetInitAudioGraph> private async Task EnumerateAudioRenderDevices() { AudioGraphSettings settings = new AudioGraphSettings(Windows.Media.Render.AudioRenderCategory.Media); //<SnippetEnumerateAudioRenderDevices> Windows.Devices.Enumeration.DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Media.Devices.MediaDevice.GetAudioRenderSelector()); // Show UI to allow the user to select a device Windows.Devices.Enumeration.DeviceInformation selectedDevice = ShowMyDeviceSelectionUI(devices); settings.PrimaryRenderDevice = selectedDevice; //</SnippetEnumerateAudioRenderDevices> }
private static void PrintInfo(Windows.Devices.Enumeration.DeviceInformation info) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Id:" + info.Id); sb.AppendLine("EnclosureLocation:" + info.EnclosureLocation); sb.AppendLine("IsDefault:" + info.IsDefault); sb.AppendLine("IsEnabled:" + info.IsEnabled); sb.AppendLine("Kind:" + info.Kind); sb.AppendLine("IsPaired:" + info.Pairing.IsPaired); info.Properties.ToList().ForEach(p => { sb.AppendLine("\t" + p.Key + ":" + p.Value);; }); Console.WriteLine(sb); }
static private async void DeviceWatcher_Added(DeviceWatcher sender, Windows.Devices.Enumeration.DeviceInformation deviceInfo) { Debug.WriteLine(String.Format("Added {0}{1}", deviceInfo.Id, deviceInfo.Name)); // Protect against race condition if the task runs after the app stopped the deviceWatcher. if (sender == deviceWatcher) { CSLibrary.DeviceFinder.DeviceInfomation di = new CSLibrary.DeviceFinder.DeviceInfomation(); di.deviceName = deviceInfo.Name; di.ID = (uint)_deviceDB.Count; di.nativeDeviceInformation = (object)deviceInfo; _deviceDB.Add(deviceInfo); RaiseEvent <DeviceFinderArgs>(OnSearchCompleted, new DeviceFinderArgs(di)); } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected override async void OnNavigatedTo(NavigationEventArgs e) { // Request the right to have background tasks run in the future. This need only be done once // after the app is installed, but it is harmless to do it every time the app is launched. if (await BackgroundExecutiondManager.RequestAccessAsync() == BackgroundAccessStatus.Denied) { // TODO: What? } // Acquire the set of background tasks that we already have registered. Store them into a dictionary, keyed // by task name. (For each LE device, we will use a task name that is derived from its Bluetooth address). Dictionary <string, BackgroundTaskRegistration> taskRegistrations = new Dictionary <string, BackgroundTaskRegistration>(); foreach (BackgroundTaskRegistration reg in BackgroundTaskRegistration.AllTasks.Values) { taskRegistrations[reg.Name] = reg; } // Get the list of paired Bluetooth LE devicdes, and add them to our 'devices' list. Associate each device with // its pre-existing registration if any, and remove that registration from our dictionary. Devices.Clear(); foreach (DeviceInformation di in await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelector())) { BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(di.Id); Racer device = new Racer(bleDevice); if (taskRegistrations.ContainsKey(device.TaskName)) { device.TaskRegistration = taskRegistrations[device.TaskName]; taskRegistrations.Remove(device.TaskName); } Devices.Add(device); } // Unregister any remaining background tasks that remain in our dictionary. These are tasks that we registered // for Bluetooth LE devices that have since been unpaired. foreach (BackgroundTaskRegistration reg in taskRegistrations.Values) { reg.Unregister(false); } }
/// <summary> /// Get all available BT devices. /// </summary> /// <exception cref="UnauthorizedAccessException">You have not set correct capabilities for your platform.</exception> /// <returns>Returns all available BT devices.</returns> public async override Task <List <DeviceInformation> > GetAllDevicesAsync() { var selector = RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort); DeviceInformationCollection platformDevices; try { platformDevices = await PlatformDeviceInformation.FindAllAsync(selector); } catch (UnauthorizedAccessException) { if (Debugger.IsAttached) { // This exception likely occured becaused you have not added this to Package.appxmanifest: /* * <m2:DeviceCapability Name="bluetooth.rfcomm"> * <m2:Device Id="any"> * <m2:Function Type="name:serialPort" /> * </m2:Device> * </m2:DeviceCapability> */ Debugger.Break(); } throw; } var devices = new List <DeviceInformation>(); foreach (var platformDevice in platformDevices) { var device = new DeviceInformation(); device.DisplayName = platformDevice.Name; device.PlatformDeviceObject = platformDevice; devices.Add(device); } return(devices); }
public static async Task <I2CMpuDevice> CreateMpuDeviceAsync(string deviceName) { Log.WriteLine("finding device {0}", deviceName != null ? deviceName : "(default)"); Windows.Devices.Enumeration.DeviceInformation info = null; if (deviceName != null) { info = await FindAsync(I2cDevice.GetDeviceSelector(deviceName)); } else { info = await FindAsync(I2cDevice.GetDeviceSelector()); } Log.WriteLine("I2c device info {0} null", info == null ? "is" : "is not"); var settings = new I2cConnectionSettings(DefaultMpuAddress); settings.BusSpeed = I2cBusSpeed.FastMode; var d = new I2CMpuDevice(); d.Device = await AsAsync(I2cDevice.FromIdAsync(info.Id, settings)); return(d); }
public OnDeviceConnectedEventArgs(Boolean isDeviceSuccessfullyConnected, Windows.Devices.Enumeration.DeviceInformation deviceInformation) { this.isDeviceSuccessfullyConnected = isDeviceSuccessfullyConnected; this.deviceInformation = deviceInformation; }
public DeviceListItem(Windows.Devices.Enumeration.DeviceInformation deviceInfo) { this.deviceInfo = deviceInfo; }
private async void ShadowDriverDeviceWatcher_Added(Windows.Devices.Enumeration.DeviceWatcher sender, Windows.Devices.Enumeration.DeviceInformation args) { ShadowDriverDevice = await CustomDevice.FromIdAsync(args.Id, DeviceAccessMode.ReadWrite, DeviceSharingMode.Exclusive); if (ShadowDriverDevice != null) { await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { ViewModel.DeviceConnectStatus = "Connected"; }); } }
private DeviceInformation(Windows.Devices.Enumeration.DeviceInformation deviceInformation) { _deviceInformation = deviceInformation; }
/// <summary> /// Invoked when the device watcher finds a proximity sensor /// </summary> /// <param name="sender">The device watcher</param> /// <param name="device">Device information for the proximity sensor that was found</param> private void OnProximitySensorAdded(Windows.Devices.Enumeration.DeviceWatcher sender, Windows.Devices.Enumeration.DeviceInformation device) { if (_sensor == null && Windows.Devices.Sensors.ProximitySensor.FromId(device.Id) is Windows.Devices.Sensors.ProximitySensor foundSensor) { _sensor = foundSensor; } }
/// <summary> /// Constructor /// </summary> /// <param name="DeviceInterface">The device interface for this entry</param> public DeviceListEntry(Windows.Devices.Enumeration.DeviceInformation DeviceInterface) { this.Device = DeviceInterface; }
private async void MainWindow_Loaded(object sender, RoutedEventArgs ea) { setLanguageList(); bool hasCamera = await setCameraListAsync(); if (hasCamera) { await InitializeMediaCaptureAsync(); setBrightnessControl(); initializeTimer(); } return; #region local functions in MainWindow_Loaded void setLanguageList() { IReadOnlyList <UwpLanguage> langList = UwpOcrEngine.AvailableRecognizerLanguages; this.LangComboBox.ItemsSource = langList; this.LangComboBox.DisplayMemberPath = nameof(UwpLanguage.DisplayName); this.LangComboBox.SelectedValuePath = nameof(UwpLanguage.LanguageTag); var ocrEngine = UwpOcrEngine.TryCreateFromUserProfileLanguages(); this.LangComboBox.SelectedValue = ocrEngine.RecognizerLanguage.LanguageTag; } async Task <bool> setCameraListAsync() { var devices = await UwpDeviceInformation.FindAllAsync(UwpDeviceClass.VideoCapture); if (devices.Count == 0) { hideCameraUI(); return(false); } setupCameraComboBox(devices); return(true); void hideCameraUI() { this.CameraLabel.Visibility = Visibility.Collapsed; this.CameraComboBox.Visibility = Visibility.Collapsed; this.MonitorCameraButton.Visibility = Visibility.Collapsed; this.CameraControlGrid.Visibility = Visibility.Collapsed; this.OcrCameraButtan.Visibility = Visibility.Collapsed; } void setupCameraComboBox(IReadOnlyList <UwpDeviceInformation> deviceList) { this.CameraComboBox.ItemsSource = deviceList; this.CameraComboBox.DisplayMemberPath = nameof(UwpDeviceInformation.Name); this.CameraComboBox.SelectedValuePath = nameof(UwpDeviceInformation.Id); this.CameraComboBox.SelectedIndex = 0; } } void setBrightnessControl() { // [明るさ] スライダーを設定 var brightCtl = _mediaCapture.BrightnessControl; this.BrightSlider.Minimum = brightCtl.Capabilities.Min; this.BrightSlider.Maximum = brightCtl.Capabilities.Max; if (brightCtl.TryGetValue(out double bright)) { this.BrightSlider.Value = bright; } // [コントラスト] スライダーを設定 var contrastCtl = _mediaCapture.ContrastControl; this.ContrastSlider.Minimum = contrastCtl.Capabilities.Min; this.ContrastSlider.Maximum = contrastCtl.Capabilities.Max; if (contrastCtl.TryGetValue(out double contrast)) { this.ContrastSlider.Value = contrast; } } void initializeTimer() { // CapturePhotoToStreamAsync() が、どうも毎秒1回程度しかキャプチャさせてくれないようだ。 // タイマー動作にする必要はなかったかもしれない。 _dispatcherTimer = new DispatcherTimer(DispatcherPriority.Normal) { Interval = TimeSpan.FromMilliseconds(333), }; _dispatcherTimer.Tick += new EventHandler(OnTimerTickAsync); _dispatcherTimer.Start(); } #endregion } // END MainWindow_Loaded
/// <summary> /// Event handler for arrival of Fx2 devices /// </summary> /// <param name="sender"></param> /// <param name="devInterface">The device interface which was added</param> private async void OnFx2Added(Windows.Devices.Enumeration.DeviceWatcher sender, Windows.Devices.Enumeration.DeviceInformation devInterface) { await MainPage.Current.Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, () => { MainPage.Current.NotifyUser(String.Format("OnFx2Added: {0}", devInterface.Id), NotifyType.StatusMessage); // search the device list for a device with a matching interface ID DeviceListEntry match = FindInList(devInterface.Id); // If we found a match then mark it as verified and return if (match != null) { match.Matched = true; return; } // Create a new element for this device interface, and queue up the query of its // device information match = new DeviceListEntry(devInterface); // Add the new element to the end of the list of devices m_Fx2Devices.Add(match); } ); }