title: Sending binary data over a serial connection with pyserial
body: <p>I want to preface this with noting that I am really lost right now, so there may be things I say that don't make sense because I have no idea what I'm talking about. Feel free to dissect my question so long as it is helpful.</p>
  
  <p>Alright, so the overall project I'm working on is to write a program in python to interface with a custom built temperature control unit (built with <a href="http://pdf1.alldatasheet.com/datasheet-pdf/view/255842/ATMEL/ATMEGA8L-8PU.html" rel="nofollow">this</a> chip) and copy data from a memory buffer where data points are stored.</p>
  
  <p>I was not the one who programmed it and I'm just going off my limited experience with Arduinos (also I'm new to python). Here is some of what I was sent regarding the commands to interface with it:</p>
  
  <pre><code>#define COMMAND_PING                'p'
  //  -&gt;  'p'
  //  &lt;-  'p' uuuu
  //      uuuu - unique number == 0x03645145
  
  #define COMMAND_GET_RECORD_NUMBER   'i'
  //  -&gt; 'i'
  //  &lt;- 'i' nnnn
  //      nnnn - current record number (not written yet)
  
  #define COMMAND_GET_DATA            'd' //Length to 32-bit boundary
  //  -&gt;  'd' ssss llll
  //  &lt;-  'd' ddddddd...
  //      ssss - starting address (should, but probably don't need to be at 32-byte boundary)
  //      llll - data length - this must be a multiplicity of 32
  //      ddddddd... - data returned
  </code></pre>
  
  <p>I can use <code>con.write('p')</code> just fine and then using <code>con.readline()</code> I get back <code>\x00\x00pEQd\x03</code> which converted to hex is 7045516403 (note values sent and returned are little endian).</p>
  
  <p>My problem is with the 'd' command. I think I need to send 'd' as a string along with two 32-bit binary values but I'm not sure how to do that. I'm hardly even sure of the right questions to ask, any help you guys can give would be highly appreciated. </p>
  
  <p>Looking through internet resources (for hours) I think I might want to use struct or maybe something like <a href="http://www.gossamer-threads.com/lists/python/python/366316" rel="nofollow">this</a>? I'd really love an example showing the whole process of connecting, writing, and reading to/from the serial port.</p>