Fix serial io exception handling. Fix file system data fetch.
This commit is contained in:
parent
8178dea15a
commit
53e1f88e1a
@ -286,8 +286,7 @@ class BambuVirtualPrinter:
|
|||||||
@gcode_executor.register("M23")
|
@gcode_executor.register("M23")
|
||||||
def _select_sd_file(self, data: str) -> bool:
|
def _select_sd_file(self, data: str) -> bool:
|
||||||
filename = data.split(maxsplit=1)[1].strip()
|
filename = data.split(maxsplit=1)[1].strip()
|
||||||
self.file_system.select_file(filename)
|
return self.file_system.select_file(filename)
|
||||||
return True
|
|
||||||
|
|
||||||
@gcode_executor.register("M26")
|
@gcode_executor.register("M26")
|
||||||
def _set_sd_position(self, data: str) -> bool:
|
def _set_sd_position(self, data: str) -> bool:
|
||||||
|
@ -313,8 +313,7 @@ class GCodeExecutor:
|
|||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log.error(f"Error during gcode {gcode_info}")
|
self._log.error(f"Error during gcode {gcode_info}")
|
||||||
self._log.error(e, exc_info=True)
|
raise
|
||||||
return False
|
|
||||||
|
|
||||||
def _gcode_with_info(self, gcode):
|
def _gcode_with_info(self, gcode):
|
||||||
return f"{gcode} ({GCODE_DOCUMENTATION.get(gcode, 'Info not specified')})"
|
return f"{gcode} ({GCODE_DOCUMENTATION.get(gcode, 'Info not specified')})"
|
||||||
|
@ -76,6 +76,8 @@ class PrinterSerialIO(threading.Thread, BufferedIOBase):
|
|||||||
continue
|
continue
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._error_detected = e
|
self._error_detected = e
|
||||||
|
self.input_bytes.task_done()
|
||||||
|
self.input_bytes.clear()
|
||||||
break
|
break
|
||||||
|
|
||||||
self._log.debug("Closing IO read loop")
|
self._log.debug("Closing IO read loop")
|
||||||
|
@ -95,10 +95,12 @@ class RemoteSDCardFileList:
|
|||||||
|
|
||||||
def _get_file_data(self, file_path: str) -> FileInfo | None:
|
def _get_file_data(self, file_path: str) -> FileInfo | None:
|
||||||
self._logger.debug(f"_getSdFileData: {file_path}")
|
self._logger.debug(f"_getSdFileData: {file_path}")
|
||||||
|
|
||||||
|
# replace if name is an alias
|
||||||
file_name = Path(file_path).name.lower()
|
file_name = Path(file_path).name.lower()
|
||||||
full_file_name = self._file_alias_cache.get(file_name, None)
|
file_name = self._file_alias_cache.get(file_name, file_name)
|
||||||
if full_file_name is not None:
|
|
||||||
data = self._file_data_cache.get(file_name, None)
|
data = self._file_data_cache.get(file_name, None)
|
||||||
self._logger.debug(f"_getSdFileData: {data}")
|
self._logger.debug(f"_getSdFileData: {data}")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@ -133,10 +135,8 @@ class RemoteSDCardFileList:
|
|||||||
file_name = Path(file_path).name
|
file_name = Path(file_path).name
|
||||||
file_info = self._get_file_data(file_name)
|
file_info = self._get_file_data(file_name)
|
||||||
if file_info is None:
|
if file_info is None:
|
||||||
file_info = self._get_file_data(file_name)
|
self._logger.error(f"{file_name} open failed")
|
||||||
if file_info is None:
|
return False
|
||||||
self._logger.error(f"{file_name} open failed")
|
|
||||||
return False
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
self._selected_file_info is not None
|
self._selected_file_info is not None
|
||||||
|
@ -135,7 +135,7 @@ def printer(output_test_folder, settings, profile_manager, log_test, ftps_sessio
|
|||||||
profile_manager,
|
profile_manager,
|
||||||
data_folder=output_test_folder,
|
data_folder=output_test_folder,
|
||||||
serial_log_handler=log_test,
|
serial_log_handler=log_test,
|
||||||
read_timeout=5.0,
|
read_timeout=0.01,
|
||||||
faked_baudrate=115200,
|
faked_baudrate=115200,
|
||||||
)
|
)
|
||||||
serial_obj._bambu_client = MagicMock()
|
serial_obj._bambu_client = MagicMock()
|
||||||
@ -161,17 +161,30 @@ def test_list_sd_card(printer: BambuVirtualPrinter):
|
|||||||
def test_cannot_start_print_without_file(printer: BambuVirtualPrinter):
|
def test_cannot_start_print_without_file(printer: BambuVirtualPrinter):
|
||||||
printer.write(b"M24\n")
|
printer.write(b"M24\n")
|
||||||
printer.flush()
|
printer.flush()
|
||||||
|
|
||||||
result = printer.readlines()
|
result = printer.readlines()
|
||||||
assert result[0] == b"ok"
|
assert result[0] == b"ok"
|
||||||
assert isinstance(printer.current_state, IdleState)
|
assert isinstance(printer.current_state, IdleState)
|
||||||
|
|
||||||
|
|
||||||
|
def test_non_existing_file_not_ok(printer: BambuVirtualPrinter):
|
||||||
|
printer.write(b"M23 non_existing.3mf\n")
|
||||||
|
printer.flush()
|
||||||
|
result = printer.readlines()
|
||||||
|
assert result[0] == b"ok"
|
||||||
|
assert printer.file_system.selected_file is None
|
||||||
|
|
||||||
|
|
||||||
def test_print_started_with_selected_file(printer: BambuVirtualPrinter):
|
def test_print_started_with_selected_file(printer: BambuVirtualPrinter):
|
||||||
assert printer.file_system.selected_file is None
|
assert printer.file_system.selected_file is None
|
||||||
|
|
||||||
|
printer.write(b"M20\n")
|
||||||
|
printer.flush()
|
||||||
|
printer.readlines()
|
||||||
|
|
||||||
printer.write(b"M23 print.3mf\n")
|
printer.write(b"M23 print.3mf\n")
|
||||||
printer.flush()
|
printer.flush()
|
||||||
|
result = printer.readlines()
|
||||||
|
assert result[0] == b"ok"
|
||||||
|
|
||||||
assert printer.file_system.selected_file is not None
|
assert printer.file_system.selected_file is not None
|
||||||
assert printer.file_system.selected_file.file_name == "print.3mf"
|
assert printer.file_system.selected_file.file_name == "print.3mf"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user