From d04063c2e90695c2a9cd8b437ecdc086335948f8 Mon Sep 17 00:00:00 2001 From: janis Date: Mon, 16 May 2022 16:01:35 +0200 Subject: [PATCH] Fixed an error that could cause the app to crash if cloned from the repository. --- .../bin/lib/communication.py | 8 ++--- .../bin/lib/comport_search.py | 2 +- BiogasControllerApp-V2.2/bin/lib/lib.py | 2 +- .../biogascontrollerapp.py | 34 +++++++++++-------- BiogasControllerApp-V2.2/config/settings.ini | 6 ++-- BiogasControllerApp-V2.2/log/logging.md | 5 +++ 6 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 BiogasControllerApp-V2.2/log/logging.md diff --git a/BiogasControllerApp-V2.2/bin/lib/communication.py b/BiogasControllerApp-V2.2/bin/lib/communication.py index 768f6d6..6bfce41 100644 --- a/BiogasControllerApp-V2.2/bin/lib/communication.py +++ b/BiogasControllerApp-V2.2/bin/lib/communication.py @@ -85,12 +85,12 @@ class SwitchMode: def __init__(self): pass - def enable_fastmode(self): - com.connect(19200,"") + def enable_fastmode(self, special_port): + com.connect(19200, special_port) com.send("FM") com.quitcom() - def disable_fastmode(self): - com.connect(19200, "") + def disable_fastmode(self, special_port): + com.connect(19200, special_port) com.send("NM") com.quitcom() diff --git a/BiogasControllerApp-V2.2/bin/lib/comport_search.py b/BiogasControllerApp-V2.2/bin/lib/comport_search.py index 020e75a..cadd619 100644 --- a/BiogasControllerApp-V2.2/bin/lib/comport_search.py +++ b/BiogasControllerApp-V2.2/bin/lib/comport_search.py @@ -7,7 +7,7 @@ class ComportService: self.__import = [] self.__working = [] - def get_comport(self, special_port=""): + def get_comport(self, special_port): self.__comport = [comport.device for comport in serial.tools.list_ports.comports()] self.__pos = 0 if special_port != "": diff --git a/BiogasControllerApp-V2.2/bin/lib/lib.py b/BiogasControllerApp-V2.2/bin/lib/lib.py index 7c5f507..52aa379 100644 --- a/BiogasControllerApp-V2.2/bin/lib/lib.py +++ b/BiogasControllerApp-V2.2/bin/lib/lib.py @@ -47,7 +47,7 @@ class Com: return 0 def decode_int(self, value): - self.i = int(value, base = 16) + self.i = int(value, base=16) return self.i def decode_float(self, value): diff --git a/BiogasControllerApp-V2.2/biogascontrollerapp.py b/BiogasControllerApp-V2.2/biogascontrollerapp.py index 017b566..00a0916 100644 --- a/BiogasControllerApp-V2.2/biogascontrollerapp.py +++ b/BiogasControllerApp-V2.2/biogascontrollerapp.py @@ -45,7 +45,11 @@ logger.setLevel(config['Dev Settings']['log_level']) logger.info(f"Logger initialized, app is running Version: {version_app}") ################################################################# - +if config['Port Settings']['specificPort'] == "None" or "\"\"": + special_port = "" +else: + special_port = config['Port Settings']['specificPort'] +print(type(special_port)) cvr = bin.lib.csv_parsers.CsvRead() cvw = bin.lib.csv_parsers.CsvWrite() com = bin.lib.lib.Com() @@ -95,7 +99,7 @@ class DetailInfo(Popup): def infos(self): self.err = "" try: - com.connect(19200, "") + com.connect(19200, special_port) com.quitcom() except Exception as err: self.err += "Errormessage:\n" @@ -106,13 +110,13 @@ class DetailInfo(Popup): def error_tips(self): self.err_tip = "" try: - com.connect(19200, "") + com.connect(19200, special_port) com.quitcom() except Exception as err: self.err_tip += "Possible way to resolve the issue: \n\n" if str(err)[0:10] == "[Errno 13]": if platform.system() == "Linux": - self.err_tip += f"Open a terminal and type in: sudo chmod 777 {bin.lib.comport_search.ComportService().get_comport()}" + self.err_tip += f"Open a terminal and type in: sudo chmod 777 {bin.lib.comport_search.ComportService().get_comport(special_port)}" elif platform.system() == "Macintosh": self.err_tip += "Give permission to access the cable" elif platform.system() == "Windows": @@ -130,7 +134,7 @@ class DetailInfo(Popup): self.err_tip += "Unknown OS" elif str(err)[0:34] == "could not open port '/dev/ttyUSB0'": self.err_tip += "Please connect the PC with the microcontroller!" - elif str(err)[0:26] == f"could not open port '{bin.lib.comport_search.ComportService().get_comport()}'": + elif str(err)[0:26] == f"could not open port '{bin.lib.comport_search.ComportService().get_comport(special_port)}'": self.err_tip += "Try using a different cable or close all monitoring software (like MSI Afterburner)" else: self.err_tip += "Special Error, consult the manual of Serial" @@ -171,7 +175,7 @@ class HomeScreen(Screen): self.connected = 1 self.info = f"You are currently running Version {version_app} - If you encounter a bug, please report it!" try: - com.connect(19200, "") + com.connect(19200, special_port) com.quitcom() except Exception as e: self.connected = 0 @@ -180,7 +184,7 @@ class HomeScreen(Screen): def tryconnection(self): try: - com.connect(19200, "") + com.connect(19200, special_port) com.quitcom() self.connected = 1 self.manager.current = "Readout" @@ -213,7 +217,7 @@ class ReadoutScreen(Screen): def comstart(self, pu_on): try: - com.connect(19200, "") + com.connect(19200, special_port) self.go = 1 except Exception as e: self.go = 0 @@ -331,9 +335,9 @@ class ReadoutScreen(Screen): if self.com_ok == 1: if text == "Normal Mode": - bin.lib.communication.SwitchMode().disable_fastmode() + bin.lib.communication.SwitchMode().disable_fastmode(special_port) else: - bin.lib.communication.SwitchMode().enable_fastmode() + bin.lib.communication.SwitchMode().enable_fastmode(special_port) logger.info("Switched mode, restarting COM") self.openpupups() self.comstart(0) @@ -451,7 +455,7 @@ class Program(Screen): def read_data(self): try: - com.connect(19200, "") + com.connect(19200, special_port) self.go = 1 except Exception as e: self.go = 0 @@ -556,7 +560,7 @@ class Program(Screen): self.__transmit.append(self.ids.s4_t.text) logger.debug("trying to send...") try: - self.coms.change_all(self.__transmit, "") + self.coms.change_all(self.__transmit, special_port) logger.info("Transmission successful") logger.debug("purging fields...") self.ids.s1_a.text = "" @@ -633,7 +637,7 @@ class ProgramTemp(Screen): def read_data(self): logger.info("Trying to establish connection...") try: - com.connect(19200, "") + com.connect(19200, special_port) self.go = 1 except Exception as e: self.go = 0 @@ -712,7 +716,7 @@ class ProgramTemp(Screen): self.__transmit.append(self.ids.temp_s3.text) self.__transmit.append(self.ids.temp_s4.text) logger.debug("Transmitting...") - self.coms.change_temp(self.__transmit, "") + self.coms.change_temp(self.__transmit, special_port) self.ids.temp_s1.text = "" self.ids.temp_s2.text = "" self.ids.temp_s3.text = "" @@ -741,7 +745,7 @@ class ReadData(Screen): def read_data(self): logger.info("Trying to connect to the microcontroller") try: - com.connect(19200, "") + com.connect(19200, special_port) self.go = 1 except Exception as e: self.go = 0 diff --git a/BiogasControllerApp-V2.2/config/settings.ini b/BiogasControllerApp-V2.2/config/settings.ini index 20c6197..20a4dbf 100644 --- a/BiogasControllerApp-V2.2/config/settings.ini +++ b/BiogasControllerApp-V2.2/config/settings.ini @@ -7,10 +7,10 @@ sizeW = 800 [Dev Settings] # Settings generally aimed towards the devs of this software! -verbose = True +verbose = False log_level = DEBUG -disableConnectionCheck = True +disableConnectionCheck = False [Info] version = V2.3.0 -subVersion = -dev1 +subVersion = diff --git a/BiogasControllerApp-V2.2/log/logging.md b/BiogasControllerApp-V2.2/log/logging.md new file mode 100644 index 0000000..ee2d608 --- /dev/null +++ b/BiogasControllerApp-V2.2/log/logging.md @@ -0,0 +1,5 @@ +What is getting logged? +Generally this app logs how and when you interact with the app and sometimes, which values you enter. +No logs are being sent to anybody automatically, you can choose to attach the log file to the bug report. +This helps the devs a lot, as they can better understand the state of the app as it crashed. The logs are +all found in this folder here. \ No newline at end of file