我正在尝试将数据发送到ble,但我的设备只接受字节数组。如何将数据转换为字节数组并在Swift 3中发送?
print("hex value is",hexRepresentation)
print("pairing code",pairingcode)
var aaa = calcchecksum(data:"4A6BF961585C3F86DCEB562CEC51A4CE")
if let auxData = (hexRepresentation+"4A6BF961585C3F86DCEB562CEC51A4CE"+aaa).data(using: .utf8), let lChar = self.mainCharacteristic {
let bytearraydata = [UInt8](auxData) as Data?
aPeripheral.writeValue(bytearraydata, for: lChar, type: .withResponse
}
答案 0 :(得分:1)
查找写入的CBC特性属性。
let data:[UInt8] = [0x01, 0x03, 0x012, 0x01]
let writeData = Data(bytes: data)
self.selectPeripheral.writeValue(writeData, for: writeCharacteristic,
type: WithResponse)