# API Reference v10.3.1 (Python)

## OfflineTranslator (class)

Module: zaber_motion.gcode

Represents an offline G-Code translator. It allows to translate G-Code blocks to Zaber ASCII protocol stream commands. This translator does not need a connected device to perform translation.

Requires at least Firmware 7.11.

The following examples illustrate how you can obtain an instance of this type:

```py
from zaber_motion.ascii import Connection
from zaber_motion.gcode import OfflineTranslator

connection = Connection.open_serial_port("COM3")
device = connection.get_device(1)
offline_translator = OfflineTranslator.setup_from_device(device, [1, 2])
```

```py
from zaber_motion.gcode import OfflineTranslator

offline_translator = OfflineTranslator.setup(...)
```

Related Guides:

- [G-Code](https://software.zaber.com/motion-library/docs/guides/library_features/gcode.md)

### Properties

#### `coordinate_system` (read-only)

`offline_translator.coordinate_system`

Type: `str`

Current coordinate system.

#### `translator_id` (read-only)

`offline_translator.translator_id`

Type: `int`

The ID of the translator that serves to identify native resources.

### Methods

#### `flush()`

`offline_translator.flush()`

Flushes the remaining stream commands waiting in optimization buffer. The flush is also performed by M2 and M30 codes.

##### Return Value

Type: `List[str]`

The remaining stream commands.

#### `get_axis_coordinate_system_offset()`

`offline_translator.get_axis_coordinate_system_offset(coordinate_system, axis, unit)`

Gets offset of an axis in a given coordinate system.

##### Arguments

| Name | Type | Description |
| --- | --- | --- |
| `coordinate_system` | `str` | Coordinate system (e.g. G54). |
| `axis` | `str` | Letter of the axis. |
| `unit` | [`LengthUnits`](https://software.zaber.com/motion-library/api/py/root/units.md) | Units of position. |

##### Return Value

Type: `float`

Offset in translator units of the axis.

#### `get_axis_position()`

`offline_translator.get_axis_position(axis, unit)`

Gets position of translator's axis. This method does not query device but returns value from translator's state.

##### Arguments

| Name | Type | Description |
| --- | --- | --- |
| `axis` | `str` | Letter of the axis. |
| `unit` | [`LengthUnits`](https://software.zaber.com/motion-library/api/py/root/units.md) | Units of position. |

##### Return Value

Type: `float`

Position of translator's axis.

#### `reset_after_stream_error()`

`offline_translator.reset_after_stream_error()`

Resets internal state after device rejected generated command. Axis positions become uninitialized.

#### `set_axis_home_position()`

`offline_translator.set_axis_home_position(axis, position, unit)`

Sets the home position of translator's axis. This position is used by G28.

##### Arguments

| Name | Type | Description |
| --- | --- | --- |
| `axis` | `str` | Letter of the axis. |
| `position` | `float` | The home position. |
| `unit` | [`LengthUnits`](https://software.zaber.com/motion-library/api/py/root/units.md) | Units of position. |

#### `set_axis_position()`

`offline_translator.set_axis_position(axis, position, unit)`

Sets position of translator's axis. Use this method to set position after performing movement outside of the translator. This method does not cause any movement.

##### Arguments

| Name | Type | Description |
| --- | --- | --- |
| `axis` | `str` | Letter of the axis. |
| `position` | `float` | The position. |
| `unit` | [`LengthUnits`](https://software.zaber.com/motion-library/api/py/root/units.md) | Units of position. |

#### `set_axis_secondary_home_position()`

`offline_translator.set_axis_secondary_home_position(axis, position, unit)`

Sets the secondary home position of translator's axis. This position is used by G30.

##### Arguments

| Name | Type | Description |
| --- | --- | --- |
| `axis` | `str` | Letter of the axis. |
| `position` | `float` | The home position. |
| `unit` | [`LengthUnits`](https://software.zaber.com/motion-library/api/py/root/units.md) | Units of position. |

#### `set_feed_rate_override()`

`offline_translator.set_feed_rate_override(coefficient)`

Allows to scale feed rate of the translated code by a coefficient.

##### Arguments

| Name | Type | Description |
| --- | --- | --- |
| `coefficient` | `float` | Coefficient of the original feed rate. |

#### `set_traverse_rate()`

`offline_translator.set_traverse_rate(traverse_rate, unit)`

Sets the speed at which the device moves when traversing (G0).

##### Arguments

| Name | Type | Description |
| --- | --- | --- |
| `traverse_rate` | `float` | The traverse rate. |
| `unit` | [`VelocityUnits`](https://software.zaber.com/motion-library/api/py/root/units.md) | Units of the traverse rate. |

(static)

#### `setup()` (async available)

`OfflineTranslator.setup(definition, config = None)`

Sets up translator from provided device definition and configuration.

##### Arguments

| Name | Type | Description |
| --- | --- | --- |
| `definition` | [`DeviceDefinition`](https://software.zaber.com/motion-library/api/py/gcode/devicedefinition.md) | Definition of device and its peripherals. The definition must match a device that later performs the commands. |
| `config` | [`Optional[TranslatorConfig]`](https://software.zaber.com/motion-library/api/py/gcode/translatorconfig.md) | Configuration of the translator. |

##### Return Value

Type: [`OfflineTranslator`](https://software.zaber.com/motion-library/api/py/gcode/offlinetranslator.md)

New instance of translator.

(static)

#### `setup_from_device()` (async available)

`OfflineTranslator.setup_from_device(device, axes, config = None)`

Sets up an offline translator from provided device, axes, and configuration.

##### Arguments

| Name | Type | Description |
| --- | --- | --- |
| `device` | [`Device`](https://software.zaber.com/motion-library/api/py/ascii/device.md) | Device that later performs the command streaming. |
| `axes` | `List[int]` | Axis numbers that are later used to setup the stream. For a lockstep group specify only the first axis of the group. |
| `config` | [`Optional[TranslatorConfig]`](https://software.zaber.com/motion-library/api/py/gcode/translatorconfig.md) | Configuration of the translator. |

##### Return Value

Type: [`OfflineTranslator`](https://software.zaber.com/motion-library/api/py/gcode/offlinetranslator.md)

New instance of translator.

#### `translate()`

`offline_translator.translate(block)`

Translates a single block (line) of G-code.

##### Arguments

| Name | Type | Description |
| --- | --- | --- |
| `block` | `str` | Block (line) of G-code. |

##### Return Value

Type: [`TranslateResult`](https://software.zaber.com/motion-library/api/py/gcode/translateresult.md)

Result of translation containing the stream commands.
