在这里,我们尝试从 J1939 SAE 总线设备读取数据,但似乎无法使用 iOS 读取数据,我们正在使用
Core bluetooth
连接,我们已经在 Android 中完成,在 Android 中工作正常,但同一设备无法使用 iOS 读取,任何人都可以帮忙我对此。
我附上我的代码片段
按照 SEA J1939 连接
Bluetooth
设备
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")
}
}
}
iOS 设备上的原生操作系统会阻止应用程序访问 USB 和蓝牙服务,但 Apple 明确记录为白名单的设备或已注册 Apple MFI 计划(根据 NDA)的设备除外。
我使用它的解决方案通过 Raspberry Pi 连接到非 Apple 允许的 USB 和蓝牙配置文件设备,然后通过网络套接字(通过 WiFi 或有线以太网,Apple 支持)将数据从 Pi 传输到 iOS 设备在 iOS 上通过各种适配器),或使用核心蓝牙 BLE(已列入白名单,但速度慢得多)。
我也有类似的问题。我需要一个库,可以通过 Android Studio 收听 Can 消息。我做了很多研究,但我只能找到一个名为“CANdroid-lib-1.0”的库,并且我在将其添加到我的项目中时遇到了一些问题,你能帮助我吗?谢谢你。