runner.py 1023 Bytes
Newer Older
gijs's avatar
gijs committed
1 2 3 4 5 6
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import chiplotle
from settings import db
import time
gijs's avatar
gijs committed
7
from plottertools.memory import enlargeMemory 
gijs's avatar
gijs committed
8

gijs's avatar
gijs committed
9 10 11
# PLOTTER_SIGNATURE = '7550'
# PLOTTER_PORT= '/dev/ttyUSB0'
VIRTUAL = False
gijs's avatar
gijs committed
12 13 14 15

if VIRTUAL:
  plotter = chiplotle.tools.plottertools.instantiate_virtual_plotter()
else:
gijs's avatar
gijs committed
16 17 18
  plotter = chiplotle.tools.plottertools.instantiate_plotters()[0]

enlargeMemory(plotter)
gijs's avatar
gijs committed
19 20 21 22 23 24 25 26 27

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

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

    if plot:
      try:
gijs's avatar
gijs committed
28
        plotter.write('IN;{};PG;'.format(str(plot['hpgl'].decode('utf-8'))))
gijs's avatar
gijs committed
29 30 31 32 33 34 35 36 37 38 39 40 41
        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)