title: Writing Byte Arrays to serial with Ruby
body: <p>I'm not clear on how to write simple byte code arrays with ruby, <em>more-so</em> I'm absolutely stumped on how to use the <a href="http://github.com/toholio/ruby-serialport" rel="noreferrer">Ruby SerialPort</a> library, well to be honest I have it working pretty well however I have only been successful in sending ASCII over the serial port. </p>
  
  <p>For example it's really simple to write ASCII:</p>
  
  <pre><code>@sp = SerialPort.new "/dev/tty.usbserial-A6004cNN", 19200
  @sp.write "test"
  </code></pre>
  
  <p>Which obviously writes <code>test</code> to that serial device. This works fine and I've been able to get all the expected results sent to a micro-controller (<a href="http://www.arduino.cc/" rel="noreferrer">arduino</a>) in this case. The issue is that I need to write output which the serial device will read like so:</p>
  
  <pre><code>{0x01,0x09,0x04,0x00, 'f',0xff,0xcc,0x33}
  </code></pre>
  
  <p>I've tried using <a href="http://www.ruby-doc.org/core/classes/String.html#M000760" rel="noreferrer"><code>str.unpack</code></a> but am still unable to produce the desired hex values output as bytes as above.</p>
  
  <p>In Java it is simple using it's serial library:</p>
  
  <pre><code>byte[] cmd = { 0x01,0x09,0x04,0x00, 'f',(byte)0xff,(byte)0xcc,(byte)0x33 };
  serialPort.write( cmd );
  </code></pre>
  
  <p>How can I output the proper bytecode to my serial device with Ruby? </p>