Guest User

Untitled

a guest
Feb 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. var manager: CBCentralManager!
  2. var device: CBPeripheral?
  3. var characteristics: [CBCharacteristic]?
  4. var serviceUUID = "1234"
  5. var char1 = "FFE1"
  6. let deviceName = "HMSoft"
  7.  
  8. func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
  9. DidDiscoverChar.text = "Characteristic found!"
  10.  
  11. device = peripheral
  12. characteristics = service.characteristics
  13.  
  14. var value: UInt8 = 1
  15.  
  16. let data = NSData(bytes: &value, length: MemoryLayout<UInt8>.size)
  17.  
  18. for characteristic in service.characteristics as [CBCharacteristic]!
  19. {
  20. if(characteristic.uuid.uuidString == "FFE1")
  21. {
  22. device?.writeValue(data as Data, for: characteristic,type: CBCharacteristicWriteType.withoutResponse)
  23.  
  24. }
  25. }
  26. }
  27.  
  28. @IBAction func ledOn(_ sender: AnyObject) {
  29. var value: UInt8 = 1
  30. let data = NSData(bytes: &value, length: MemoryLayout<UInt8>.size)
  31.  
  32. device?.writeValue(data as Data, for: characteristics,type: CBCharacteristicWriteType.withoutResponse)
  33. }
  34.  
  35. device?.writeValue(data as Data, for: characteristics,type: CBCharacteristicWriteType.withoutResponse)
Add Comment
Please, Sign In to add comment