0

I am trying to send data to a ble, but my device only accepts byte arrays. How do I convert data to byte array and send it in 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
}
1

1 Answer 1

1

Find to which CBCharacteristic property is write.

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

  self.selectPeripheral.writeValue(writeData, for: writeCharacteristic, 
  type: WithResponse)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.