首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >L2CAP通道数据传输

L2CAP通道数据传输
EN

Stack Overflow用户
提问于 2018-06-13 22:56:32
回答 2查看 2.5K关注 0票数 3

我正在开发的BLE应用程序使用面向连接的渠道。我使用北欧半导体nrf52作为外围设备,使用iPhone 6作为中央管理器。

我使用了蓝牙SIG提供的预定义PSM值0x0025。我能够成功地连接到外设并打开L2CAP通道。

我得到了下面的错误:

**CoreBluetooth警告:未知错误: 436

62057-06-08 10:03:17.532709-0400BluetothTest407:0400**没有psm 37的已知通道匹配对端*

请告诉我如何继续,以及错误代码436的含义

下面是我的代码:

代码语言:javascript
复制
   func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
        //handling callback when a peripheral is discover
        print("Central Manager PowerOn State Check:\(central.state.rawValue)")
        if (peripheral.name?.contains("Nordic_OTSX") == true)
       {
            print(peripheral.name ??  "no name")
            print("advertisement Data : \(advertisementData) ")
            central.connect(peripheral, options: nil )
            myPeripheral = peripheral
       }
    }


    func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral)
    {
        print("didConnect\(myPeripheral.debugDescription)")
        myPeripheral.delegate = self
        myPeripheral.discoverServices(nil)
    }
    //if error while making connection
    func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?)
    {
        print("error:\(error.debugDescription)")
    }

    //after opening L2CAP Channel
   func peripheral(_ peripheral: CBPeripheral, didOpen channel: CBL2CAPChannel?, error: Error?)
    {
        print("didOpen")
        print(error.customMirror)
        print(channel!.outputStream.debugDescription)
        print(channel!.inputStream.debugDescription)
        print(channel?.outputStream.hasSpaceAvailable)
    }


    func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?)
    {
        print("*******************************************************")

        if ((error) != nil) {
            print("Error discovering services: \(error!.localizedDescription)")
            return
        }

        guard let services = peripheral.services else {
            return
        }
        //We need to discover the all characteristic
        for service in services {

            peripheral.discoverCharacteristics(nil, for: service)
            // bleService = service
        }
        print("Discovered Services: \(services)")
    }


    func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)
    {
        print("*******************************************************")
        if let charcterstics = service.characteristics
        {
            print("characteristics :")
            for char in charcterstics
            {
               /* if char.uuid == buttonCharacteristicUUID
                {
                    buttonCharacteristic = char
                    enableButtonNotifications(buttonCharacteristic!)
                    readButtonValue()
                }*/
                print(char.uuid.uuidString)
            }
        }
         peripheral.openL2CAPChannel(0x0025)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
EN

回答 2

Stack Overflow用户

发布于 2018-09-09 06:42:53

我也遇到过类似的问题。我设法通过创建一个变量在函数中保存"channel: CBL2CAPChannel?“来解决这个问题

代码语言:javascript
复制
func peripheral(_ peripheral: CBPeripheral, didOpen channel: CBL2CAPChannel?, error: Error?)

我只保存了"channel.outputStream",这是我唯一需要的。但是看起来如果你不保存它,它将被关闭。

票数 3
EN

Stack Overflow用户

发布于 2018-06-14 18:49:02

0x25 PSM用于OTS。您需要ATT PSM,它是0x1F

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50840365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档