2015-07-04 16 views
6

Tôi đang phát triển ứng dụng Windows Phone 8.1 cửa hàng (XAML) phải in trên máy in Bluetooth.Điện thoại Windows 8.1 streamsocket.connectSync tạo "Không có thêm dữ liệu. (Ngoại lệ từ HRESULT: 0x80070103)"

Thiết bị này được tìm thấy thành công với hai phương pháp đầu tiên:

PeerFinder.AllowBluetooth = True 
      PeerFinder.Role = PeerRole.Client 
      PeerFinder.AlternateIdentities.Item("Bluetooth:SDP") = "{00001101-0000-1000-8000-00805F9B34FB}" 
      'PeerFinder.AlternateIdentities.Item("Bluetooth:Paired") = "" 

      Dim devs = Await PeerFinder.FindAllPeersAsync() 
      Dim dev As PeerInformation = devs(0) 

      Dim btdevs = Await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelector()) 
      Dim btdv = btdevs(0) 

Và không tìm thấy trong:

  Dim dfdevs1 = Await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort)) 
      ' same result with Await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(New Guid("00001101-0000-1000-8000-00805F9B34FB"))) 

Thật không may, chỉ có phương pháp cuối cùng sẽ cung cấp cho tôi "remoteServiceName" cho việc sử dụng trong StreamSocket.ConnectAsync

Tôi đã thử kết hợp khác nhau cho StreamSocket.ConnectAsync:

dim _soc = New StreamSocket() 
Await _soc.ConnectAsync(dev.HostName, "1") 

"Không có thêm dữ liệu. (Ngoại lệ từ HRESULT: 0x80070103)"

Tương tự cho

dim _soc = New StreamSocket() 
Await _soc.ConnectAsync(dev.HostName, "{00001101-0000-1000-8000-00805F9B34FB}" 

Và như bạn có thể tưởng tượng giống nhau cho

dim _soc = New StreamSocket() 
Await _soc.ConnectAsync(btdv.HostName, "{00001101-0000-1000-8000-00805F9B34FB}" 

Tôi thực sự ra khỏi ý tưởng sau một ngày kể từ khi đập đầu của tôi. Và điều khiến tôi khó chịu nhất là kết hợp mã đầu tiên hoạt động hoàn hảo cho Windows Phone 8.0

Và có, trong AppManifest mọi thứ được đặt:

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

Bất kỳ ý tưởng nào cũng sẽ được đánh giá cao.

Trả lời

1

Tôi cũng đang nghiên cứu vấn đề này khi chúng tôi nói và tôi đã đạt được tiến bộ tốt. Đối với tôi, vấn đề xảy ra sau khi tôi nâng cấp từ WP8 lên WP8.1 (Silverlight).

Hãy chắc chắn rằng appxmanifest của bạn có các quyền sau đây thiết lập: (! Ít nhất, cho đến nay trong thử nghiệm của tôi)

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

Dưới đây là mẫu mã của tôi xuất hiện để cho phép kết nối thông qua

   PeerFinder.AlternateIdentities["Bluetooth:SDP"] = "{00001101-0000-1000-8000-00805f9b34fb}"; 

       //find the device from the device list we are trying to connect to 
       var selector = RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort); 
       var dev = await DeviceInformation.FindAllAsync(selector, null); 
       var devA = dev.Where(f => f.Name.Equals(_item.Device.DisplayName)).FirstOrDefault(); 

       //get the service 
       RfcommDeviceService service = await RfcommDeviceService.FromIdAsync(devA.Id); 

       //create the connection 
       await Common.Instance.Socket.ConnectAsync(service.ConnectionHostName, service.ConnectionServiceName); 
       MetaData.Instance.BlueBoxRef = _item.Device.DisplayName.Substring(8); 
       NavigationService.Navigate(new Uri("/OpenDevice.xaml", UriKind.RelativeOrAbsolute)); 

Tôi vẫn cần kiểm tra xem điều này có hoạt động trên các thiết bị khác hay không nhưng hãy cho tôi biết cách bạn tiếp tục!

Các vấn đề liên quan