Я отправляю байт 0x11 на TX, но ничего не происходит, функция
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)
никогда не вызывается.Вот мой код ..
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
peripheral.delegate = self
//peripheral.discoverServices(nil)
peripheral.discoverServices([CBUUID(string: "6E400001-B5A3-F393-E0A9-E50E24DCCA9E")])
print("Connected successfully to the device")
//On stop le scan
centralManager?.stopScan()
}
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
print("\n\n\n ✅ READING SERVICES OF PERIPHERAL ❤️ \(peripheral.name!) ❤️")
for service in peripheral.services! {
peripheral.discoverCharacteristics(nil, for: service)
print(service)
}
}
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
print("\n\n ? READING CHARARCTERISTICS OF ? \(service.uuid) ?")
let NORDIC_UART_TX_CHARACTERISTIC = CBUUID(string: "6e400002-b5a3-f393-e0a9-e50e24dcca9e")
let NORDIC_UART_RX_CHARACTERISTIC = CBUUID(string: "6e400003-b5a3-f393-e0a9-e50e24dcca9e")
for characteristic in service.characteristics! {
// Tx:
if characteristic.uuid == NORDIC_UART_TX_CHARACTERISTIC {
print("Tx char found: \(characteristic.uuid)")
let command:[UInt8] = [0x11]
let sendData: Data = Data(command)
peripheral.writeValue(sendData, for: characteristic, type:.withResponse)
}
// Rx:
if characteristic.uuid == NORDIC_UART_RX_CHARACTERISTIC {
print("Rx char found: \(characteristic.uuid)")
peripheral.setNotifyValue(true, for: characteristic)
}
}
}
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?){
print("characteristic changed: \(characteristic)")
}