Skip to content

Commit df35af3

Browse files
Added error message that occurs when trying to open binary gcode.
1 parent 7f7720b commit df35af3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

bricklayers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,14 @@ def process_gcode(self, gcode_stream):
18381838
#logger.debug("Finished.")
18391839

18401840

1841+
def gcode_opener(path, flags):
1842+
file=os.open(path, flags)
1843+
header=os.pread(file,4,0)
1844+
if header==bytes("GCDE","ascii"):
1845+
os.close(file) #do not leak the file descriptor
1846+
print(f"{error_marker}The specified output folder '{input_file}' is a binary gcode file, which is not supported. Disable binary gcode in your slicer settings", file=sys.stderr)
1847+
sys.exit(1) # Exit immediately
1848+
return file
18411849

18421850
# Main execution
18431851
if __name__ == "__main__":
@@ -2169,7 +2177,7 @@ def expand_ranges(ranges):
21692177
# print(final_output_file)
21702178

21712179
# Open the input and output files using Generators:
2172-
with open(input_file, "r", encoding="utf-8", errors="replace", newline="") as infile, open(final_output_file, "w", encoding="utf-8", newline="\n") as outfile:
2180+
with open(input_file, 'r', encoding="utf8", newline="",opener=gcode_opener) as infile, open(final_output_file, 'w') as outfile:
21732181
# Pass the file generator (line-by-line) to process_gcode
21742182
gcode_stream = (line for line in infile) # Efficient generator
21752183

0 commit comments

Comments
 (0)