Skip to content

Twomag Api

This module holds the API for the 2Mag device.

ATTRIBUTE DESCRIPTION
READ_FORMAT

The read format for the device

TYPE: str

WRITE_FORMAT

The write format for the device

TYPE: str

Data

The data type for the device

TYPE: NamedTuple

CLASS DESCRIPTION
TwoMagDevice

Class for the 2Mag device

Documentation last updated: 2025-02-22

TwoMagDevice

TwoMagDevice(
    port: str | None = None,
    baudrate: int = 9600,
    timeout: int = 1,
    *,
    init_timeout: int = 5,
    data_type: NamedTuple = Data,
    read_format: str = READ_FORMAT,
    write_format: str = WRITE_FORMAT,
    simulation: bool = False,
    verbose: bool = False,
    **kwargs,
)

Bases: SerialDevice

Class for the 2Mag device

ATTRIBUTE DESCRIPTION
address

The address of the device

TYPE: str

version

The version of the device

TYPE: str

mode

The mode of the device

TYPE: str

speed

The speed of the device in RPM

TYPE: int

power

The power of the device in percentage

TYPE: int

connection_details

connection details for the device

TYPE: dict

device

device object that communicates with physical tool

TYPE: Device

flags

flags for the class

TYPE: SimpleNamespace[str, bool]

is_busy

whether the device is busy

TYPE: bool

is_connected

whether the device is connected

TYPE: bool

verbose

verbosity of class

TYPE: bool

METHOD DESCRIPTION
connect

connect to the device

disconnect

disconnect from the device

execute

execute task

resetFlags

reset all flags to class attribute _default_flags

run

alias for execute()

shutdown

shutdown procedure for tool

getPower

get the power of the device

getSpeed

get the speed of the device

getStatus

get the status of the device

setDefault

set the device to default

setPower

set the power of the device

setSpeed

set the speed of the device

start

start the device

stop

stop the device

Initialize the 2Mag device

PARAMETER DESCRIPTION
port

The port to which the device is connected. Defaults to None.

TYPE: str DEFAULT: None

baudrate

The baudrate of the device. Defaults to 9600.

TYPE: int DEFAULT: 9600

timeout

The timeout for the device. Defaults to 1.

TYPE: int DEFAULT: 1

init_timeout

The timeout for initialization. Defaults to 5.

TYPE: int DEFAULT: 5

data_type

The data type for the device. Defaults to Data.

TYPE: NamedTuple DEFAULT: Data

read_format

The read format for the device. Defaults to READ_FORMAT.

TYPE: str DEFAULT: READ_FORMAT

write_format

The write format for the device. Defaults to WRITE_FORMAT.

TYPE: str DEFAULT: WRITE_FORMAT

simulation

Whether to simulate the device. Defaults to False.

TYPE: bool DEFAULT: False

verbose

Whether to print out debug information. Defaults to False.

TYPE: bool DEFAULT: False

getPower

getPower() -> int

Get the power of the device

RETURNS DESCRIPTION
int

The power of the device in percentage

TYPE: int

getSpeed

getSpeed() -> int

Get the speed of the device

RETURNS DESCRIPTION
int

The speed of the device in RPM

TYPE: int

getStatus

getStatus() -> tuple[str, str]

Get the status of the device

RETURNS DESCRIPTION
tuple[str, str]

tuple[str,str]: The version and mode of the device

query

query(
    data: Any,
    multi_out: bool = False,
    *,
    timeout: int | float = 0.3,
    format_in: str | None = None,
    format_out: str | None = None,
    data_type: NamedTuple | None = None,
    timestamp: bool = False,
    **kwargs,
) -> Any

Query the device

PARAMETER DESCRIPTION
data

The data to query

TYPE: Any

multi_out

Whether to return multiple outputs. Defaults to False.

TYPE: bool DEFAULT: False

timeout

The timeout for the query. Defaults to 0.3.

TYPE: int | float DEFAULT: 0.3

format_in

The format of the input. Defaults to None.

TYPE: str | None DEFAULT: None

format_out

The format of the output. Defaults to None.

TYPE: str | None DEFAULT: None

data_type

The data type of the output. Defaults to None.

TYPE: NamedTuple | None DEFAULT: None

timestamp

Whether to timestamp the query. Defaults to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Any

The output of the query

TYPE: Any

setAddress

setAddress(address: str) -> bool

Set the address of the device

PARAMETER DESCRIPTION
address

The address to set the device to

TYPE: str

RETURNS DESCRIPTION
bool

Whether the address was set

TYPE: bool

setDefault

setDefault() -> bool

Set the device to default

RETURNS DESCRIPTION
bool

Whether the device was set to default

TYPE: bool

setPower

setPower(power: int) -> int

Set the power of the device

PARAMETER DESCRIPTION
power

The power to set the device to in percentage

TYPE: int

RETURNS DESCRIPTION
int

The power of the device in percentage

TYPE: int

setSpeed

setSpeed(speed: int) -> int

Set the speed of the device

PARAMETER DESCRIPTION
speed

The speed to set the device to in RPM

TYPE: int

RETURNS DESCRIPTION
int

The speed of the device in RPM

TYPE: int

start

start() -> bool

Start the device

RETURNS DESCRIPTION
bool

Whether the device was started

TYPE: bool

stop

stop() -> bool

Stop the device

RETURNS DESCRIPTION
bool

Whether the device was stopped

TYPE: bool