Swift Send Hex Data Over TCP Socket
<p>I'm working on a solution to send commands to a point of sale receipt printer and having some issues getting the command format right.  Ive got a socket open to the device and thats working, because incorrect commands are printed.  What the SPEC calls for in this command is to send the following:</p>

<p>1B 07 or in decimal 27 7.  Which in ASCII is ESC_KEY BEL.  The only example the spec shows is for .NET:</p>

<p>MSComm1.Output = Chr$(&amp;H1B) &amp; Chr$(&amp;H07)</p>

<p>What I've been trying:</p>

<p>// Socket is open previously using CFStreamCreatePairWithSocketToHost.</p>

<pre><code>var cmd = "27 07"
if let dataString = "\(cmd)\r".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false), let oStream = self.outputStream {
        self.outputData.append(dataString)

        if oStream.hasSpaceAvailable {
            oStream.write(UnsafePointer((self.outputData.first! as NSData).bytes), maxLength: self.outputData.first!length)
        }
    }
</code></pre>

<p>The data is getting there, but I think the format of the message is wrong.  Any help would be appreciated.</p>