def updateDispensing(self, mixing=True): ml_left = [] dispenselist = self.dispenselist self.ser = SerialConnection() ml_left = self.ser.readLine().split(",") logging.debug(str(ml_left[0])) if not "ok" in ml_left[0]: for ingr in self.dispensing: logging.debug(ingr.feed.name) for pumpnumber in list(range(24)): if ingr.feed.motor_num == pumpnumber: if "Ready" in ml_left[0]: ingr.dispensed = 0 else: logging.debug("pumpnumber ", str(pumpnumber)) if int(ml_left[pumpnumber]) < 0: ml_left[pumpnumber] = 0 ingr.dispensed = math.ceil( (dispenselist[pumpnumber] - int(ml_left[pumpnumber])) / self.stepsforml) else: self.ser.close() del self.ser hwa = HardwareAction(self.mixit) hwa.end_dispensing(self.mixit) self.dispensing[:] = [x for x in self.dispensing if not x.done()]
def __init__(self, master, amount, turns, pumpcount=1): super(CleanScreen, self).__init__(master) self.master = master self.last_disp = 0.0 self.pumpnumber = 0 self.turn = 0 self.amount = amount self.turns = turns self.pumpcount = pumpcount self.stopCleaning = False self.desc = Text(self, relief=FLAT, wrap=NONE, state=DISABLED) backbtn = RectButton(self, text="Abbruch", command=self.handle_button_back) self.bgcolor = master.bgcolor self.configure(bg=self.bgcolor) self.desc.grid(column=0, row=0, sticky=N + E + W + S) backbtn.grid(column=0, row=1, padx=10, pady=10, sticky=E + W + S) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) try: self.ser.readData() except: try: self.ser = SerialConnection() self.ser.readData() except: logging.debug("Verbindung nicht moeglich") self.next_Pump()
def cancelDispensing(self): self.ser = SerialConnection() self.ser.sendData('@') self.ser.readLine() self.ser.close() del self.ser logging.debug("Ausschenken abgebrochen") for ingr in self.dispensing: ingr.stopFeed() self.dispensing[:] = [x for x in self.dispensing if not x.done()]
def __init__(self, master, recipe, amount): super(DispensingScreen, self).__init__(master) self.master = master self.ser = SerialConnection() self.recipe = recipe self.last_disp = 0.0 self.desc = Text(self, relief=FLAT, wrap=NONE, state=DISABLED) backbtn = RectButton(self, text="Abbruch", command=self.handle_button_back) self.bgcolor = master.bgcolor self.configure(bg=self.bgcolor) self.desc.grid(column=0, row=0, sticky=N+E+W+S) backbtn.grid(column=0, row=1, padx=10, pady=10, sticky=E+W+S) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) recipe.startDispensing(amount) self.pid = self.after(UPDATE_MS, self.update_screen)
def startDispensing(self, volume): stepsforml = self.stepsforml tot_vol = self.totalVolume() vol_mult = volume / tot_vol self.dispensing = [] sercommand = '' self.dispenselist = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] logging.info("Dispensing: %s, %d ml" % (self.getName(), volume)) for ingr in self.ingredients: ingr.milliliters = math.ceil(ingr.milliliters * vol_mult) self.dispensing.append(DispensingIngredient(ingr, vol_mult)) for ingr in self.dispensing: thisfeed = SupplyFeed.getByName(ingr.feed.name) newremaining = thisfeed.feeds[ ingr.feed.name].remaining - ingr.milliliters thisfeed.feeds[ingr.feed.name].remaining = newremaining logging.debug("remaining neu fuer " + ingr.feed.name + ": " + str(thisfeed.feeds[ingr.feed.name].remaining)) logging.info("Zutat " + ingr.feed.name + ": " + str(ingr.milliliters) + " ml") for pumpnumber in list(range(24)): if ingr.feed.motor_num == pumpnumber: self.dispenselist[pumpnumber] = int( math.ceil(ingr.milliliters * self.stepsforml)) sercommand = (','.join(map(str, self.dispenselist))) + '\n' try: self.ser.readData() except: logging.debug("keine bestehende verbindung") try: self.ser = SerialConnection() self.ser.readData() logging.debug("habe verbindung") except: logging.debug("verbindung nicht moeglich") hwa = HardwareAction(self.mixit) hwa.do_dispensing(self.mixit) self.ser.sendData(sercommand) self.ser.close() del self.ser self.updateDispensing(self.mixit)
nav_status_lock = threading.Lock() command = 6 * [0] command_lock = threading.Lock() # global variables mission_running = True mission_mode = True blocking = True thread1 = None thread2 = None obj_detection = ObjectDetection() # initializing serial connection with AUV_simulator simulator_com = SerialConnection(port='com1', baud=115200) simulator_com.start() # wait for the first not empty message from AUV_simulator while nav_status == None: receive_nav_status() # threads running start_threads() # wait for threads termination wait_for_threads_termination() # close serial connection with AUV_simulator simulator_com.close()
control_mode = False mission_mode = False #--------------------------------------------------------------------------------# # inizializing UDP connection with Unity HOST_IP = 'localhost' HOST_PORT_UDP = 29000 UDP_IP = 'localhost' UDP_PORT = 25000 unity_com = CustomUDP(HOST_IP, HOST_PORT_UDP, UDP_IP, UDP_PORT) unity_com.start() # inizializing connection with mission_manager mission_com = SerialConnection(port='com2', baud=115200) mission_com.start() # inizializing pygame pg.init() # creation GUI screen pg.display.set_caption('Zeno GUI') screen = pg.display.set_mode(SCREEN_DIM) # creation of stylised images of the AUV (top, side and back view) # note: images are square and image width is equal to dial diameter image_width = 2 * DIAL_R image_1 = create_view('images/zeno_top.bmp', image_width) # top view image_2 = create_view('images/zeno_side.bmp', image_width) # side view
from serial_connection import SerialConnection import signal def new_packet(incoming_queue): packet = incoming_queue.get() print(packet) incoming_queue.task_done() def exit_handler(signal, frame): print("Exit called") con.stop() con = SerialConnection('/dev/pts/2', 19200, new_packet, "ACK\n") items = ["esimene", "teine", "kolmas", "neljas"] con.start() for i in items: con.write(i) print("items added to write queue") # register exit handler signal.signal(signal.SIGINT, exit_handler)