2017-10-02 49 views
0

Bluetooth印刷を実装するアプリケーションを開発しています。このプロセスの一環として、タイプのみのプリンタデバイスで検出されたデバイスを制限したいと考えています。現在、Bluetoothデバイスを検出するためのコードは次のとおりです。プリンタのBluetoothデバイスのみを検出する方法[C#、UWP]

public List<ScannerInfo> GetPrinters() 
    { 
     // Declare results 
     List<ScannerInfo> result = new List<ScannerInfo>(); 

     // Get all the bluetooth and bluetooth serial devices 
     DeviceInformationCollection pairedBluetoothDevices = Task.Run(async() => 
      await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelector())).Result; 
     DeviceInformationCollection pairedBluetoothSerialDevices = Task.Run(async() => 
       await DeviceInformation.FindAllAsync(
        RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort))) 
      .Result; 

     // Get scanner data 
     foreach (DeviceInformation pairedBluetoothSerialDevice in pairedBluetoothSerialDevices) 
     { 
      var d = DeviceInformation.CreateFromIdAsync(pairedBluetoothSerialDevice.Id); 
      // Create object 
      ScannerInfo newScanner = new ScannerInfo 
      { 
       Id = pairedBluetoothSerialDevice.Id, 
       Name = pairedBluetoothSerialDevice.Name 
      }; 

      // Correct name (this is necessary as following the anniversary update the serial object name no longer holds the bluetooth device name, only the prototcol name. 
      // Therefore we attempt to get this by matching id components via the full bluetooth device list, which is what the user sees in windows settings). 
      foreach (var pairedBluetoothDevice in pairedBluetoothDevices) 
      { 
       if (pairedBluetoothSerialDevice.Id.Contains(pairedBluetoothDevice.Id)) 
       { 
        newScanner.Name = pairedBluetoothDevice.Name; 
        break; 
       } 
      } 

      // Add to result set 
      result.Add(newScanner); 
     } 

     // Return items 
     return result; 
    } 

私はアドバイスをお願い致します。

答えて

1

DeviceInformation.FindAllAsyncのプリンタデバイスをフィルタする方法のセレクタとして、Advanced Query Syntax(AQS)フィルタを使用できます。

Quickstart: enumerating commonly used devicesでは、PrinterInterfaceClass GUIDとして{0ECEF634-6EF0-472A-8085-5AD023ECBCCD}を使用しています。試してみることもできます。

Build a device selectorもご利用ください。

+0

ありがとうございます。私は見て、非常に感謝します! –

関連する問題