积极答复者
WP8的蓝牙开发可以支持蓝牙模块吗?

问题
-
private async void ConnectToDevice(PeerInformation peer) { if (_socket != null) { // Disposing the socket with close it and release all resources associated with the socket _socket.Dispose(); } try { _socket = new StreamSocket(); string serviceName = (String.IsNullOrWhiteSpace(peer.ServiceName)) ? txtServiceName.Text : peer.ServiceName; // Note: If either parameter is null or empty, the call will throw an exception await _socket.ConnectAsync(peer.HostName, serviceName); // If the connection was successful, the RemoteAddress field will be populated MessageBox.Show(String.Format(AppResources.Msg_ConnectedTo, _socket.Information.RemoteAddress.DisplayName)); } catch (Exception ex) { // In a real app, you would want to take action dependent on the type of // exception that occurred. MessageBox.Show(ex.Message); _socket.Dispose(); _socket = null; } }
其中ConnectAsync要两个参数,第一个HostName可以通过PeerFinder.FindAllPeersAsync()返回的对象得到,但是第2个参数ServiceName是空的,请问我该怎么去连接蓝牙模块,也没有说明上的TCP端口什么的。。。求救。。。
答案
-
你好,
目前,WP8的Bluetooth支持AppToApp和AppToDevice两种模式,你的应用应该是AppToDevice模式。
具体编程可以参考这篇文章:Windows Phone 8 蓝牙编程
Keep Fighting
- 已标记为答案 Amy PengMicrosoft employee, Moderator 2013年11月19日 2:34
全部回复
-
你好,
目前,WP8的Bluetooth支持AppToApp和AppToDevice两种模式,你的应用应该是AppToDevice模式。
具体编程可以参考这篇文章:Windows Phone 8 蓝牙编程
Keep Fighting
- 已标记为答案 Amy PengMicrosoft employee, Moderator 2013年11月19日 2:34
-
你好,
MSDN上AppToDevice的例子需要加入 Service Name ,具体可以参考英文论坛上的这个帖子:
WP8 - Bluetooth - App to device issue
Keep Fighting