Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var manager: CBCentralManager!
- var device: CBPeripheral?
- var characteristics: [CBCharacteristic]?
- var serviceUUID = "1234"
- var char1 = "FFE1"
- let deviceName = "HMSoft"
- func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
- DidDiscoverChar.text = "Characteristic found!"
- device = peripheral
- characteristics = service.characteristics
- var value: UInt8 = 1
- let data = NSData(bytes: &value, length: MemoryLayout<UInt8>.size)
- for characteristic in service.characteristics as [CBCharacteristic]!
- {
- if(characteristic.uuid.uuidString == "FFE1")
- {
- device?.writeValue(data as Data, for: characteristic,type: CBCharacteristicWriteType.withoutResponse)
- }
- }
- }
- @IBAction func ledOn(_ sender: AnyObject) {
- var value: UInt8 = 1
- let data = NSData(bytes: &value, length: MemoryLayout<UInt8>.size)
- device?.writeValue(data as Data, for: characteristics,type: CBCharacteristicWriteType.withoutResponse)
- }
- device?.writeValue(data as Data, for: characteristics,type: CBCharacteristicWriteType.withoutResponse)
Add Comment
Please, Sign In to add comment