#!/usr/bin/python import os import time import sys import serial import time import random sport = serial.Serial('/dev/ttyUSB0'.encode('ascii'),9600, timeout=2 ) sport2 = serial.Serial('/dev/ttyUSB1'.encode('ascii'),9600, timeout=2 ) def sendCommand( command ): global sport command = command + '\n' sport.write( command ) #sport.flushOutput() print command def getBuffer( d = 0.0 ): global sport time.sleep( d ) rv = sport.read( 100 ) print "- RECV %s (%f)" % (rv, d) return 0 def sendCommand2( command ): global sport2 command = command + '\n' sport2.write( command ) #sport.flushOutput() print command def getBuffer2( d = 0.0 ): global sport2 time.sleep( d ) rv = sport2.read( 100 ) print "- RECV %s (%f)" % (rv, d) return 0 def turnTable( positions =1 ): sendCommand( "+turn%1d-" % positions ) rv = getBuffer( 1.0 ) def addBev( bev, time ): sendCommand( "+valve%s%d.%d-" % (bev, int(time), int((time*10.0)%10 )) ) rv = getBuffer( time + 1.0 ) def mix( time = 2 ): sendCommand2( "+mix%02d-" % time ) rv = getBuffer2( time + 0.5 ) clusterA = [ 'f', 'b', 'c' ] clusterB = [ 'a', 'e', 'd' ] filled = [ 'c', 'b', 'f', 'd', 'a' ] if len(sys.argv) > 1: boozes = sys.argv[1:] else: boozes = [ random.choice( filled ), random.choice( filled ) ] turnTable(1) for x in clusterA: if x in boozes: addBev( x, random.randint(2,4)*1.1 ) turnTable(1) for x in clusterB: if x in boozes: addBev( x, random.randint(2,4)*1.1 ) turnTable(1) mix() time.sleep(1) turnTable(2) #turnTable() #turnTable() #turnTable() #turnTable()