在这里,我们正在尝试从 J1939 SAE 总线设备读取数据,但似乎无法通过 iOS 读取我们正在使用Core bluetooth
我们在 android 中完成的连接,并且在 android 中工作正常,但同一设备无法使用 iOS 读取,任何人都可以帮助我。
在这里我附上我的代码片段
连接Bluetooth
设备为 SEA J1939
var manager:CBCentralManager!
manager.connect(connectPeripheral, options: nil)
connectPeripheral.delegate = self
蓝牙连接成功
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
print("Connected!")
self.showAlertOneButton(withTitle: "", with: key.KBluetoothConnect, firstButton: key.KOk) { (UIAlertAction) in
self.navigationItem.rightBarButtonItem?.tintColor = UIColor.blue
self.vwBLTSub.removeFromSuperview()
//all services
self.connectPeripheral.discoverServices(nil)
}
}
从设备读取数据
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService,
error: Error?) {
guard let characteristics = service.characteristics else { return }
for characteristic in characteristics {
print(characteristic)
if characteristic.properties.contains(.read) {
print("\(characteristic.uuid): properties contains .read")
peripheral.readValue(for: characteristic)
}
if characteristic.properties.contains(.notify) {
print("\(characteristic.uuid): properties contains .notify")
}
}
}