我正在为Gear S3编写一个Web应用程序,并为C#中的UWP编写一个配套的Win-App。 我想要它做什么:S3充当BT服务器,发送数据,Win-App作为客户端,应该接收数据。 在Tizen中,我使用了registerRfcommServiceByUUID()函数,如下所示:
function publishTransferService() {
if(remoteDevice.isConnented){
console.log("Connection Status: " + remoteDevice.isConnected);
var TRANS_SERVICE_UUID = '5BCE9431-6C75-32AB-AFE0-2EC108A30860';
adapter.registerRFCOMMServiceByUUID(TRANS_SERVICE_UUID, 'My Service', ServiceSuccessCb,
function(e) {
console.log( "Could not register service record, Error: " + e.message);
});
}else{
console.error("Connection Status: " + remoteDevice.isConnected);
}
在C#中,我尝试按如下方式连接服务:
//to ulong converted MAC-Address of the Gear
ulong gearBtAddress = 145914022804881;
//create device-instance of the gear
BluetoothDevice gearDevice = await BluetoothDevice.FromBluetoothAddressAsync(gearBtAddress);
//list the services found on the gear and connect to the one with
//the same uuid as in tizen
var gearServices = await gearDevice.GetRfcommServicesAsync();
foreach (var service in gearServices.Services)
{
if(service.ServiceId == RfcommServiceId.FromUuid(Guid.Parse("5BCE9431-6C75-32AB-AFE0-2EC108A30860")))
{
_service = await RfcommDeviceService.FromIdAsync(service.ToString());
}
}
我面临的问题是,C#找不到想要的Uuid,虽然它找到了其他几个uuid。我不知道它丢失的地方?
提前致谢。
答案 0 :(得分:1)
我自己解决了,问题是,UUID是未缓存的。添加以下内容就是这样做:
var cacheMode = BluetoothCacheMode.Uncached;
var gearServices = await gearDevice.GetRfcommServicesAsync(cacheMode);