gpt4 book ai didi

swift - 如何在 Swift 3 中将字节数组发送到 ble?

转载 作者:行者123 更新时间:2023-11-28 15:30:05 25 4
gpt4 key购买 nike

我正在尝试将数据发送到 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
}

最佳答案

找出写入了哪个 CBCharacteristic 属性。

  let data:[UInt8] = [0x01, 0x03, 0x012, 0x01]
let writeData = Data(bytes: data)

self.selectPeripheral.writeValue(writeData, for: writeCharacteristic,
type: WithResponse)

关于swift - 如何在 Swift 3 中将字节数组发送到 ble?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44817896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com