Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何连接到Gear S3上的蓝牙服务?_C#_Bluetooth_Tizen Wearable Sdk_Tizen Web App - Fatal编程技术网

C# 如何连接到Gear S3上的蓝牙服务?

C# 如何连接到Gear S3上的蓝牙服务?,c#,bluetooth,tizen-wearable-sdk,tizen-web-app,C#,Bluetooth,Tizen Wearable Sdk,Tizen Web App,我正在为Gear S3编写一个web应用程序,并为C#中的UWP编写一个配套Win应用程序。 我想让它做的是:S3充当BT服务器,发送数据,Win应用程序充当客户端,接收数据。 在Tizen中,我使用了registerRfcommServiceByUUID()函数,如下所示: function publishTransferService() { if(remoteDevice.isConnented){ console.log("Connection Status: " + remo

我正在为Gear S3编写一个web应用程序,并为C#中的UWP编写一个配套Win应用程序。 我想让它做的是:S3充当BT服务器,发送数据,Win应用程序充当客户端,接收数据。 在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。我不知道它在哪里丢了


提前谢谢。

我自己解决了,问题是UUID没有缓存。只需添加以下内容即可:

        var cacheMode = BluetoothCacheMode.Uncached;
        var gearServices = await gearDevice.GetRfcommServicesAsync(cacheMode);
请看这里: