title: safe and fast method for communicating a mix list of integers and booleans between pyserial and Arduino
body: <p>I want to send and receive a mix list of integers and booleans between pyserial and an Arduino. I have figured the Arduino to pyserial out, well partly:</p>
  
  <p>Arduino code:</p>
  
  <pre><code>...
  bool var1 = ...;
  int var2 = ...;
  ...
  
  
  void setup() {
     ...
     Serial.begin(9600);
     ...
  }
  
  void loop() {
      ...
      // here I send the data in CSV format
      Serial.print(var1);
      Serial.print(", ");
      Serial.print(var2);
      Serial.print(", ");
      ...
      Serial.println(var_n);
      ...
  }
  </code></pre>
  
  <p>and the pyserial side:</p>
  
  <pre class="lang-py prettyprint-override"><code>import serial
  
  serPort = serial.Serial("COM7")
  
  dataRaw = serPort.readline().strip()
  dataList = dataRaw.decode('ascii').split(', ')
  data = [int(d) for d in dataList]
  
  serPort.close()
  </code></pre>
  
  <p>however, the first issue is that python stops at <code>readline</code>. What I want to have is </p>
  
  <ol>
  <li>to be sure serial buffer on both sides does not overflow. basically, if the receiver buffer is full the sender keeps the data in its send buffer till receiver buffer has some vacancy.</li>
  <li>I want the <code>readline</code> to be run only if the receive buffer has received a new line. Basically some form of interrupt function, which is triggered when a new line is put in the receive buffer.</li>
  <li>I want to read lines complete. so the text between to <code>/n</code> characters (carriage return?) must be read. </li>
  </ol>
  
  <p>Although I'm kinda cheating here and get the boolean information as an integer in python, it does the job for me. However, I have no idea how should I send a similar mixed list from pyserial to Arduino. Consider the python list:</p>
  
  <pre><code>data = [12345, True, 67890, False, ...]
  </code></pre>
  
  <p>How can I send the list above to the Arduino also in a safe and fast way? I don't think that Arduino has regex or can afford complicated split, strip, ... string operations. What is the best way to send a list as above and then receive it on the Arduino side?</p>
  
  <p><strong>P.S.</strong> I did not ask this question on <a href="http://arduino.stackexchange.com">arduino.stackexchange</a> because it is more general in terms of including serial communication and using python. </p>