     
     
     /// Send a string to the device
-    func sendMessageToDevice(var message: String) {
+    func sendMessageToDevice(message: String) {
         
         if centralManager.state != .PoweredOn || connectedPeripheral == nil { return }
         
+        let writeType: CBCharacteristicWriteType = writeWithResponse ? .WithResponse : .WithoutResponse
+        
         // write the value to all characteristics of all services
-        for service in connectedPeripheral!.services as! [CBService] {
-            for characteristic in service.characteristics as! [CBCharacteristic] {
-                connectedPeripheral!.writeValue(message.dataUsingEncoding(NSUTF8StringEncoding), forCharacteristic: characteristic, type: .WithResponse)
+        for service in connectedPeripheral!.services! {
+            for characteristic in service.characteristics! {
+                connectedPeripheral!.writeValue(message.dataUsingEncoding(NSUTF8StringEncoding)!, forCharacteristic: characteristic, type: writeType)
             }
         }
         

        
        peripheral.delegate = self
        
        // Okay, the peripheral is connected but we're not ready yet! 
        // First get all services
        // Then get all characteristics of all services
        // Once that has been done check whether our characteristic (0xFFE1) is available
        // If it is, subscribe to it, and then we're ready for communication
        // If it is not, we've failed and have to find another device..

        peripheral.discoverServices(nil)
    }

    func centralManager(central: CBCentralManager!, didDisconnectPeripheral peripheral: CBPeripheral!, error: NSError!) {
        connectedPeripheral = nil
        if delegate.respondsToSelector(Selector("serialHandlerDidDisconnect:error:")) {
            // send it to the delegate

        
    }
    
    func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) {
        
        // there is new data for us! Update the buffer!
        let newStr = NSString(data: characteristic.value!, encoding: NSUTF8StringEncoding) as! String
        buffer += newStr
        
        // notify the delegate of the new string
