title: Sending hex data over RS-232 between an Arduino and a Mac OS X system
body: <p>I'm using <em><a href="http://www.elechouse.com/elechouse/index.php?main_page=product_info&amp;cPath=168_170&amp;products_id=2151&amp;zenid=3cvei81u5rqgti4d6l5p36n7r6" rel="nofollow noreferrer">Voice Recognition Module -- Arduino Compatible</a></em>. It says there to use AccessPort, but since I'm on Mac OS X it won't work. I don't know of any other solution but to write my own in Python while I'm open to any other language that works.</p>
  <p>I found some solutions over here about <a href="http://pyserial.sourceforge.net/" rel="nofollow noreferrer">pySerial</a> but as of now it doesn't seem to work.</p>
  <pre><code>import serial
  import struct
  
  def C(val):
      return struct.pack('H', val)
  
  ser = serial.Serial(port='/dev/tty.PL2303-00001004', baudrate=9600, timeout=1)
  ser.nonblocking()
  
  ser.write(C(0xaa11))
  print ser.read().__repr__()
  ser.close()
  </code></pre>
  <p>It opens, write two bytes and doesn't read anything. <code>0xaa11</code> is used to start recording. My device seems to be in waiting mode since the red <a href="http://en.wikipedia.org/wiki/Light-emitting_diode" rel="nofollow noreferrer">LEDs</a> flash rapidly. Even if I do <code>0xaa00</code>, it doesn't do much either. I even tried to change the byte order to <code>0x00aa</code>, <code>0x11aa</code> and so on, but I never receive my <code>0xcc</code> or <code>0xe0</code> error code.</p>
  <p>In the documentation it says to send it as hex, so my guess is that accessport converts hex to a <code>Short</code> which use two bytes. <code>0xaa00</code> is a two bytes number. I even tried to change the <a href="http://en.wikipedia.org/wiki/Baud" rel="nofollow noreferrer">baud</a> rate to <code>38400</code> in case someone before me did set that to this speed.</p>
  <p>I'd be happy to read anything from that serial port because as of now I can write, it does nothing and reads nothing...</p>
  <p>As of now, I'll try to install AccessPort with crossover. If it still doesn't work, I'll have to find a Windows box. I could even write my own bridge with my Arduino board since the driver I'm using might be buggy.</p>
  <p>In case it matters, I'm using a USB to Serial PL2303.</p>
  <h3>Edit</h3>
  <ul>
  <li><p>I plugged my output and input pin to test my USB-to-serial. I do read what I write so the driver is working fine.</p>
  </li>
  <li><p>I'll try to set it up directly with Arduino and test directly from there.</p>
  </li>
  <li><p>Sending <code>0xaa11</code> is different than sending <code>0xaa</code> and then <code>0x11</code>. The serial seems to reverse the byte order.</p>
  </li>
  <li><p>On the other hand, the documentation doesn't tell about bit endianess, so it might be the problem too.</p>
  </li>
  </ul>