def safe_projekt_as(self, data, name): path = self.file_picker_save(f"{self.get_last_dir()}\\{name}") if path: self.save_json_file(data, path) FileHandling.path_of_open_projekt = path status_text.add_line_to_status_text( f"Save Projekt: { name } unter {path}")
def init_plotter(self): self.ser.write(b'\x1b.[ZF5;') # switch online self.ser.write(b'OC;') # position abfragen tmp = self.read_rs232() x, y = self.read_pos() status_text.add_line_to_status_text("X = {}, Y = {}".format(x, y))
def import_file(self): data = None path = self.file_picker_open() if path: data = self.open_json_file(path) self.safe_last_dir(path) status_text.add_line_to_status_text(f"import: {path}") return data
def open_projekt(self, pfad=None): data = None path = self.file_picker_open(pfad) if path: data = self.open_json_file(path) FileHandling.path_of_open_projekt = path status_text.add_line_to_status_text(f"projekt: {path} geöffnet") return data
def safe_projekt(self, data, name): if FileHandling.path_of_open_projekt is None: self.safe_projekt_as(data, name) else: self.save_json_file(data, FileHandling.path_of_open_projekt) status_text.add_line_to_status_text( f"Save Projekt: {name} unter {FileHandling.path_of_open_projekt}" )
def safe(self, path, data): try: f = open(path, "w+") f.write(data) f.close() except OSError as err: status_text.add_line_to_status_text("OS error: {0}".format(err)) except: status_text.add_line_to_status_text("Unexpected error:", sys.exc_info()[0])
def read_rs232(self): status_text.add_line_to_status_text("rs232 read") buffer = "" while True: oneByte = self.ser.read(1) if oneByte == b"\r": # method should returns bytes return buffer else: # print(oneByte.decode("ascii")) buffer += oneByte.decode("ascii")
def prozess_start(self): if not self.plotter_running: status_text.add_line_to_status_text("starte prozess") self.plotter_running = True thread_pool = concurrent.futures.ThreadPoolExecutor() self.thread = thread_pool.submit(self._prozess_run, self.hpgl_code) # start thread # self._prozess_run(self.hpgl_code) else: status_text.add_line_to_status_text("läuft schon") pass
def open(self, path): try: data = None f = open(path, "r") data = f.read() f.close() except OSError as err: status_text.add_line_to_status_text("OS error: {0}".format(err)) except: status_text.add_line_to_status_text("Unexpected error:", sys.exc_info()[0]) return data
def init_rs232(self, settings: model_Settings.Settings): # self.ser = serial.Serial() self.ser = None self.ser = serial.Serial() self.ser.baudrate = settings.setings["com_port"]["baudrate"] self.ser.port = settings.setings["com_port"]["RS232port"] self.ser.parity = settings.setings["com_port"]["parity"] self.ser.stopbits = settings.setings["com_port"]["stopbits"] self.ser.bytesize = settings.setings["com_port"]["bytesize"] self.ser.timeout = settings.setings["com_port"]["timeout"] self.ser.xonxoff = settings.setings["com_port"]["xonxoff"] self.ser.rtscts = settings.setings["com_port"]["rtscts"] try: self.ser.open() self.sio = io.TextIOWrapper(io.BufferedRWPair(self.ser, self.ser)) status_text.add_line_to_status_text("ser.is_open --> " + str(self.ser.is_open) + " one " + self.ser.name) except: status_text.add_line_to_status_text("Port " + self.ser.name + " kannn nicht geöfnet werden")
def prozess_stop(self): if self.plotter_running: self.plotter_running = False time.sleep(1) while (not self.thread.done()): self.ser.cancel_write() self.ser.cancel_read() status_text.add_line_to_status_text("cancel rs232 write") time.sleep(1) status_text.add_line_to_status_text("gestopt") else: status_text.add_line_to_status_text("läuft gar nicht") pass
def export_file(self, data, name): path = self.file_picker_save(f"{self.get_last_dir()}\\{name}") if path: self.save_json_file(data, path) self.safe_last_dir(path) status_text.add_line_to_status_text(f"export: {path}")
def reinit_rs232(self, settings: model_Settings.Settings): self.ser.close() status_text.add_line_to_status_text("COM prot closed") time.sleep(1) self.init_rs232(settings)
def __del__(self): # x, y = self.read_pos() # print("X = {}, Y = {}".format(x, y)) # self.ser.write(b'\x1b.[ZF6;') # switch offline self.ser.close() status_text.add_line_to_status_text("COM prot closed")
def move(self, x, y): command = 'PU' + str(x * 100) + ',' + str(y * 100) + ';' self.ser.write(command.encode()) x, y = self.read_pos() status_text.add_line_to_status_text("X = {}, Y = {}".format(x, y))