Z轴可利用代码控制移动

This commit is contained in:
2026-10-10 14:10:59 +08:00
parent b827c5ffee
commit 264275b1e6
9 changed files with 406 additions and 40 deletions
@@ -17,6 +17,7 @@ No test here touches a controller or a DLL.
from __future__ import annotations
import ctypes
import logging
import time
from pathlib import Path
@@ -25,6 +26,7 @@ from orisys_autocal.motion import (
DEFAULT_BAS_TASK,
INIT_OK,
INIT_RUNNING,
BusStatus,
ConnectionSpec,
DemoTransport,
MotionService,
@@ -224,6 +226,44 @@ def test_adopted_program_without_a_known_file_says_so():
assert "文件名" in result.message or "file name" in result.message
def test_connect_reads_axis_4_and_does_not_write_parameters(caplog):
"""Connecting must not replace configuration the vendor software just set."""
transport = DemoTransport()
writes: list[tuple] = []
transport.set_units = lambda axis, value: writes.append(("units", axis, value))
transport.set_speed = lambda axis, value: writes.append(("speed", axis, value))
transport.set_accel = lambda axis, value: writes.append(("accel", axis, value))
transport.bas_download = lambda filename, run_mode=1: writes.append(("bas", filename))
service = MotionService(transport)
with caplog.at_level(logging.INFO):
result = service.connect(ConnectionSpec(mode="demo"))
assert result.ok, result.message
assert writes == []
readback = [record.message for record in caplog.records if record.message.startswith("connect axis 4")]
assert readback, caplog.text
assert "mpos=" in readback[-1]
assert "not written" in caplog.text
def test_axis_4_jog_reuses_the_shared_motion_call_and_logs_position(caplog):
service = MotionService(DemoTransport())
assert service.connect(ConnectionSpec(mode="demo")).ok
service._bus = BusStatus(bus_type="ecat", init_status=INIT_OK, total_axes=4) # noqa: SLF001
with caplog.at_level(logging.INFO):
result = service.jog(4, True)
assert result.ok, result.message
assert result.code == 0
logged = [record.message for record in caplog.records if record.message.startswith("jog axis 4")]
assert logged, caplog.text
assert "ok=True" in logged[-1]
assert "code=0" in logged[-1]
assert "mpos=" in logged[-1]
def test_reinit_needs_the_bus_not_to_be_mid_run():
service = MotionService(DemoTransport())
service.connect(ConnectionSpec(mode="demo"))