title: packet creation in ruby
body: <p>I'm trying to create a packet to send over serial using ruby-serialport. This seems like it should be simple, and it works when I just write a string:</p>
  
  <pre><code>packet = "\xFF\x03\x10\x01\x01\xFE"
  sp.write(packet)
  =&gt;hardware does what it's supposed to, opens the door represented by the 4th hex value
  </code></pre>
  
  <p>but I obviously need to do it programmatically, and I can't figure out the right way. Here are just a few of the things I've tried:</p>
  
  <pre><code>door = 1    
  packet = "\xFF\x03\x10" + door.to_s(16) + "\x01\xFE"
  sp.write(packet)
  =&gt; can't convert fixnum into string
  </code></pre>
  
  <p>and</p>
  
  <pre><code>door = 1
  packet = "\xFF\x03\x10" + door.to_a.pack('H*') + "\x01\xFE"
  sp.write(packet)
  =&gt; to_a will be obsolete
  can't convert fixnum into string
  </code></pre>
  
  <p>and</p>
  
  <pre><code>door = 1
  sp.write("\xFF\x03\x10")
  sp.write(door)
  sp.write("\x01\xFE")
  =&gt;no response from hardware
  </code></pre>
  
  <p>Can anyone help me out on how to properly convert a number into the right hex notation for serialport and joining to the other hex strings? Thanks in advance!</p>