mpylab.device.mc_virtual module

Virtual motor controller driver for tests without positioning hardware.

class mpylab.device.mc_virtual.MOTORCONTROLLER(SearchPaths=None)

Bases: MOTORCONTROLLER

Simulate motor position and speed as elapsed time advances.

Parameters:

SearchPaths (sequence of path-like, optional) – Directories searched for the virtual device configuration.

GetDescription()

Return virtual identification.

Returns:

(0, identification).

Return type:

tuple

GetSpeed()

Return virtual angular speed.

Returns:

(0, speed) in degrees per second.

Return type:

tuple

GetState()

Advance and return virtual motion state.

Returns:

(status, position_deg, direction).

Return type:

tuple

GetVirtual()

Return the fixed virtual-mode flag.

Returns:

(0, True).

Return type:

tuple

Goto(pos)

Start moving toward an absolute angle.

Parameters:

pos (float) – Target angle in degrees, normalized to one revolution.

Returns:

(0, current_position); movement then progresses with time.

Return type:

tuple

Init(ini=None, channel=None, ignore_bus=None)

Initialize state without opening a hardware bus.

Parameters:
  • ini (path-like or file-like, optional) – Virtual motor-controller configuration source.

  • channel (int or str, optional) – Logical channel.

  • ignore_bus (bool, optional) – Accepted for compatibility; the hardware bus is always ignored.

Returns:

Device status; zero indicates success.

Return type:

int

Move(direction)

Start or stop continuous movement.

Parameters:

direction ({-1, 0, 1}) – Movement direction; zero stops motion.

Returns:

(0, direction).

Return type:

tuple

Quit()

Stop virtual motion.

Returns:

Zero.

Return type:

int

SetSpeed(speed)

Set virtual angular speed.

Parameters:

speed (float) – Non-negative speed in degrees per second.

Returns:

(0, speed).

Return type:

tuple

query(cmd, tmpl=None)

Write a command and return its response.

Parameters:
  • cmd (str) – Supported command.

  • tmpl (str, optional) – Regular expression used to parse the response.

Returns:

Raw or parsed response.

Return type:

str or dict

read(tmpl=None)

Read the last virtual response.

Parameters:

tmpl (str, optional) – Regular expression with named groups.

Returns:

Raw response, parsed groups, or an empty dictionary.

Return type:

str or dict

write(cmd)

Handle one virtual command.

Parameters:

cmd (str) – Supported command.

Returns:

Zero.

Return type:

int

mpylab.device.mc_virtual.main()

Run a short virtual motor controller smoke test.