In [1]:
%matplotlib inline
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import teensyio
import serial
import time
import cStringIO as StringIO


/Users/ryandwyer/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py:1318: UserWarning:  This call to matplotlib.use() has no effect
because the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

  warnings.warn(_use_error_msg)

In [2]:
s = serial.Serial(teensyio.find_teensy(),)

In [3]:
s.timeout = 1

In [10]:
s.write('r')
all_data = []
for i in xrange(40):
    time.sleep(0.25)
    nbytes = s.inWaiting()
    raw_data = s.read(nbytes)
    all_lines.append(raw_data)
nbytes = s.inWaiting()
raw_data = s.read(nbytes)
s.write('s')
all_lines.append(raw_data)
nbytes = s.inWaiting()
raw_data = s.read(nbytes)
all_lines.append(raw_data)

In [12]:
all_lines[-2].split('\r\n')


Out[12]:
['826',
 '37720 -27816',
 '37730 -27806',
 '37740 -27796',
 '37750 -27786',
 '37760 -27776',
 '37770 -27766',
 '37780 -27756',
 '37790 -27746',
 '37800 -27736',
 '37810 -27726',
 '37820 -27716',
 '3739040 -26496',
 '39050 -26486',
 '39060 -26476',
 '39070 -26466',
 '39080 -26456',
 '39090 -26446',
 '39100 -26436',
 '39110 -26426',
 '39120 -26416',
 '39130 -26406',
 '39140 -26396',
 '39150 -26386',
 '39160 -26376',
 '39170 -26366',
 '39180 -26356',
 '39190 -26346',
 '39200 -26336',
 '39210 -26326',
 '39220 -26316',
 '39230 -26306',
 '39240 -26296',
 '39250 -26286',
 '39260 -26276',
 '39270 -26266',
 '39280 -26256',
 '39290 -26246',
 '39300 -26236',
 '39310 -26226',
 '39320 -26216',
 '39330 -26206',
 '39340 -26196',
 '39350 -26186',
 '39360 -26176',
 '39370 -26166',
 '39380 -26156',
 '39390 -26146',
 '39400 -26136',
 '39410 -26126',
 '39420 -26116',
 '39430 -26106',
 '39440 -26096',
 '39450 -26086',
 '39460 -26076',
 '39470 -26066',
 '39480 -26056',
 '39490 -26046',
 '39500 -26036',
 '39510 -26026',
 '39520 -26016',
 '39530 -26006',
 '39540 -25996',
 '39550 -25986',
 '39560 -25976',
 '39570 -25966',
 '39580 -25956',
 '39590 -25946',
 '39600 -25936',
 '39610 -25926',
 '39620 -25916',
 '39630 -25906',
 '39640 -25896',
 '39650']

In [6]:
df = pd.read_csv(StringIO.StringIO(" ".join(all_lines)), sep=' ')


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-456973137fb6> in <module>()
----> 1 df = pd.read_csv(StringIO.StringIO(" ".join(all_lines)), sep=' ')

/Users/ryandwyer/anaconda/lib/python2.7/site-packages/pandas/io/parsers.pyc in parser_f(filepath_or_buffer, sep, dialect, compression, doublequote, escapechar, quotechar, quoting, skipinitialspace, lineterminator, header, index_col, names, prefix, skiprows, skipfooter, skip_footer, na_values, na_fvalues, true_values, false_values, delimiter, converters, dtype, usecols, engine, delim_whitespace, as_recarray, na_filter, compact_ints, use_unsigned, low_memory, buffer_lines, warn_bad_lines, error_bad_lines, keep_default_na, thousands, comment, decimal, parse_dates, keep_date_col, dayfirst, date_parser, memory_map, float_precision, nrows, iterator, chunksize, verbose, encoding, squeeze, mangle_dupe_cols, tupleize_cols, infer_datetime_format, skip_blank_lines)
    468                     skip_blank_lines=skip_blank_lines)
    469 
--> 470         return _read(filepath_or_buffer, kwds)
    471 
    472     parser_f.__name__ = name

/Users/ryandwyer/anaconda/lib/python2.7/site-packages/pandas/io/parsers.pyc in _read(filepath_or_buffer, kwds)
    244 
    245     # Create the parser.
--> 246     parser = TextFileReader(filepath_or_buffer, **kwds)
    247 
    248     if (nrows is not None) and (chunksize is not None):

/Users/ryandwyer/anaconda/lib/python2.7/site-packages/pandas/io/parsers.pyc in __init__(self, f, engine, **kwds)
    560             self.options['has_index_names'] = kwds['has_index_names']
    561 
--> 562         self._make_engine(self.engine)
    563 
    564     def _get_options_with_defaults(self, engine):

/Users/ryandwyer/anaconda/lib/python2.7/site-packages/pandas/io/parsers.pyc in _make_engine(self, engine)
    697     def _make_engine(self, engine='c'):
    698         if engine == 'c':
--> 699             self._engine = CParserWrapper(self.f, **self.options)
    700         else:
    701             if engine == 'python':

/Users/ryandwyer/anaconda/lib/python2.7/site-packages/pandas/io/parsers.pyc in __init__(self, src, **kwds)
   1064         kwds['allow_leading_cols'] = self.index_col is not False
   1065 
-> 1066         self._reader = _parser.TextReader(src, **kwds)
   1067 
   1068         # XXX

pandas/parser.pyx in pandas.parser.TextReader.__cinit__ (pandas/parser.c:4804)()

ValueError: No columns to parse from file

In [ ]:
df = df[:-2]

In [ ]:
df.plot(x='Start', y='acquisition')

In [ ]: