【问题标题】:Receive Response over Bluetooth SPP as Client - Tizen .NET作为客户端通过蓝牙 SPP 接收响应 - Tizen .NET
【发布时间】:2020-01-28 08:12:37
【问题描述】:

我正在尝试通过 BT SPP 接收连接到服务器的客户端设备的响应。 创建客户端套接字并启动绑定后 Client = device.CreateSocket(ServiceUuid); Client.ConnectionStateChanged += ClientConnectionStateChanged; device.ConnectionStateChanged += DeviceConnectionStateChanged; device.CreateBond();

我在bonding回调Client.Connect();中调用connect方法,然后订阅OnDataReceived事件Client.DataReceived += OnDataReceived;

现在一切正常,但永远不会调用 OnDataReceived,就好像没有返回数据一样。 但是由于我也在控制在辅助设备上运行的服务器,所以我知道有数据正在发回,那为什么没有收到呢?

【问题讨论】:

    标签: c# .net xamarin tizen xamarin.tizen


    【解决方案1】:

    DataReceived() 函数请参考以下测试代码。

    [https://review.tizen.org/gerrit/gitweb?p=test/tct/csharp/api.git;a=blob;f=tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSIBluetoothServerSocket.cs;h=a52a38bb2ce46e384ca24897c27a694173d47fff;hb=refs/heads/tizen][1]

    303         public async Task DataReceived_CLIENT_EVENT()
    304         {
    305             try
    306             {
    307                 /* We can't occupy the precondition, if BT feature is not supported in Manual TC */
    308                 if (_isBluetoothSupported == false)
    309                 {
    310                     BluetoothHelper.DisplayLabel("DataReceived_CLIENT_EVENT");
    311                     await ManualTest.WaitForConfirm();
    312                     return;
    313                 }
    314 
    315                 BluetoothSetup.CreateClientSocketUtil();
    316                 if (BluetoothSetup.Client == null)
    317                 {
    318                     ManualTest.DisplayCustomLabel("Precondition failed: Test device should be paired to the remote device.");
    319                     await ManualTest.WaitForConfirm();
    320                     return;
    321                 }
    322 
    323                 await BluetoothSetup.ConnectSocketUtil();
    324                 BluetoothSetup.Client.DataReceived += (sender, args) =>
    325                 {
    326                     Log.Info(Globals.LogTag, "DataReceived in client: "+args.Data.Data);
    327                     BluetoothHelper.DisplayPassLabel("DataReceived_SERVER_EVENT");
    328                 };
    329                 await ManualTest.WaitForConfirm();
    

    另外,请在 ConnectionStateChanged 回调中检查 Result 是否成功。

    【讨论】:

      猜你喜欢
      • 2015-10-21
      • 2015-09-02
      • 1970-01-01
      • 1970-01-01
      • 2016-01-28
      • 1970-01-01
      • 1970-01-01
      • 2022-11-05
      • 1970-01-01
      相关资源
      最近更新 更多