MichaelRKessler commited on
Commit
5221a6c
·
1 Parent(s): 547fc33

Match G-code header command order

Browse files
Files changed (2) hide show
  1. tests/test_tiff_to_gcode.py +36 -0
  2. tiff_to_gcode.py +2 -2
tests/test_tiff_to_gcode.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import zipfile
4
+
5
+ from PIL import Image
6
+
7
+ from tiff_to_gcode import generate_snake_path_gcode
8
+
9
+
10
+ def test_gcode_header_writes_presets_before_initial_aux_commands(tmp_path) -> None:
11
+ tiff_path = tmp_path / "slice_0000.tif"
12
+ Image.new("L", (1, 1), 0).save(tiff_path)
13
+
14
+ zip_path = tmp_path / "slices.zip"
15
+ with zipfile.ZipFile(zip_path, mode="w") as archive:
16
+ archive.write(tiff_path, arcname=tiff_path.name)
17
+
18
+ gcode_path = generate_snake_path_gcode(
19
+ zip_path,
20
+ shape_name="header_order",
21
+ pressure=25,
22
+ valve=7,
23
+ port=3,
24
+ )
25
+
26
+ lines = [
27
+ line.strip()
28
+ for line in gcode_path.read_text().splitlines()
29
+ if line.strip()
30
+ ]
31
+
32
+ assert lines[0] == "G91"
33
+ assert lines[1].startswith("{preset}serialPort3.write(")
34
+ assert lines[2].startswith("{preset}serialPort3.write(")
35
+ assert lines[3].startswith("{aux_command}WAGO_ValveCommands(")
36
+ assert lines[4].startswith("{aux_command}WAGO_ValveCommands(")
tiff_to_gcode.py CHANGED
@@ -285,12 +285,12 @@ def generate_snake_path_gcode(
285
 
286
  with open(gcode_path, "w") as f:
287
  f.write("G91\n")
288
- for color in color_dict:
289
- f.write(_valve_cmd(color_dict[color], 0))
290
  for line in setpress_lines:
291
  f.write(f"{line}\n")
292
  for line in pressure_on_lines:
293
  f.write(f"{line}\n")
 
 
294
 
295
  pressure_next: str | None = None
296
  for i, move in enumerate(gcode_list):
 
285
 
286
  with open(gcode_path, "w") as f:
287
  f.write("G91\n")
 
 
288
  for line in setpress_lines:
289
  f.write(f"{line}\n")
290
  for line in pressure_on_lines:
291
  f.write(f"{line}\n")
292
+ for color in color_dict:
293
+ f.write(_valve_cmd(color_dict[color], 0))
294
 
295
  pressure_next: str | None = None
296
  for i, move in enumerate(gcode_list):