runner.py 976 Bytes
Newer Older
gijs's avatar
gijs committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import chiplotle
from settings import db
import time

PLOTTER_SIGNATURE = '7595'
PLOTTER_PORT= '/dev/ttyUSB0'
VIRTUAL = True

if VIRTUAL:
  plotter = chiplotle.tools.plottertools.instantiate_virtual_plotter()
else:
  plotter = chiplotle.tools.plottertools._instantiate_plotter._instantiate_plotter(PLOTTER_PORT, PLOTTER_SIGNATURE)

while True:
  plotcursor = db.plots.find({'plotted': False}).sort('timestamp', 1).limit(1)

  if plotcursor.count() > 0:
    plot = plotcursor[0]

    if plot:
      try:
        plotter.write(str(plot['hpgl'].decode('utf-8')))
        plotter._serial_port.flush()
        

        db.plots.update({'_id': plot['_id']}, {'$set': {'plotted': True}})
        
        if VIRTUAL:
          chiplotle.tools.io.view(plotter)
          plotter = chiplotle.tools.plottertools.instantiate_virtual_plotter()
      except:
        print 'Something went wrong while plotting'
        pass

  time.sleep(4)