2014-11-25 5 views
1

내 Windows 타블렛 앱이 블루투스를 통해 다른 장치와 통신하도록 노력하고 있습니다.블루투스 장치 나열 및 연결

먼저 장치를 검색하고 선택한 장치에 연결하려고합니다.

나는 간단한 테스트 응용 프로그램을 만들었습니다 : 빈 앞 페이지에 버튼과 목록 상자가 추가되었습니다. 그럼 난 어디서 여기에 SO에 다른 forund 다음 코드 마녀를 한 시도했다 :

ListBox1.Items.Clear(); 

    var devices = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort)); 

    foreach (var device in devices) 
    { 
     ListBox1.Items.Add(device); 
    } 

그러나 목록

가 그럼 난 그냥 열거 장치를 해봤 단지 비어 있고 원치 않는 장치를 필터링 :

var list = await DeviceInformation.FindAllAsync(); 
var uniqueList = new HashSet<string>(); 
var terminators = new List<string>() { "Audio", "Mixer", "Mic", "Realtek", "Usb", "Gmail,", "Line in", "Lyd", "Display", "surface", "@" }; 

foreach (var element in list) 
{ 

    var strToken = element.Name.ToUpper(); 

    if (!uniqueList.Add(strToken)) 
     continue; 

    var contains = false; 

    foreach (var word in terminators) 
     if (strToken.Contains(word.ToUpper())) 
      contains = true; 


    if (!contains) 
     ListBox1.Items.Add(element.Name); 
} 

그러나 이것은 의미있는 목록을 제공하지 않습니다.

나는 잘못하고 있다고 느낍니다. 제발 저를 다시 돌려주세요.

답변

2

나는 현명하지 못하다고 말하는 다른 SO 질문에 조금 더 현명하다.

Search and Connect to Bluetooth device in Windows 8/8.1 Store apps?

그래서 목록에 대한 해결책은 다음과 같습니다

ListBox1.Items.Clear(); 

    var devices = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort)); 

    foreach (var device in devices) 
    { 
     ListBox1.Items.Add(device); 
    } 
2

아직 장치 기능을 설정 한 :

1) 귀하의 장치

2)을 나열 페어링? ID와 함수 유형을 직접 정의해야합니다.

유용한 링크 : How to set device capabilities.

<m2:DeviceCapability Name="bluetooth.rfcomm"> 
    <m2:Device Id="any"> 
    <m2:Function Type="serviceId:00001101-0000-1000-8000-00805F9B34FB"/> 
    </m2:Device> 
</m2:DeviceCapability> 

또한, 당신이 짝 장치를 연결할 수없는 것이 사실이다. (Windows가 지원하지 않는 것으로 보입니다.)