API Reference v9.2.0

Translatorclass

Module: ZaberMotionGcode

Represents a live G-Code translator. It allows to stream G-Code blocks to a connected device. It requires a stream to be setup on the device. Requires at least Firmware 7.11.

The following example illustrates how you can obtain an instance of this type:

import ZaberMotionAscii
import ZaberMotionGcode

let connection = try await Connection.openSerialPort(portName: "COM3")
let device = try connection.getDevice(deviceAddress: 1)
let streams = device.streams
let stream = try streams.getStream(streamId: 1)
let translator = try await Translator.setup(stream: stream)
Related Guides:

Properties

p

coordinateSystem

readonlythrows
try translator.coordinateSystem
String Current coordinate system.
p

translatorId

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

Methods

m

flush()

asyncthrows
try await translator.flush(waitUntilIdle = true)
Flushes the remaining stream commands waiting in optimization buffer into the underlying stream. The flush is also performed by M2 and M30 codes.
Arguments
NameTypeDescription
waitUntilIdleBoolDetermines whether to wait for the stream to finish all the movements.
Return Value
[String] The remaining stream commands.
m

getAxisCoordinateSystemOffset()

throws
try translator.getAxisCoordinateSystemOffset(coordinateSystem, axis, unit)
Gets offset of an axis in a given coordinate system.
Arguments
NameTypeDescription
coordinateSystemStringCoordinate system (e.g. G54).
axisStringLetter of the axis.
unitUnitsUnits of position.
Return Value
Double Offset in translator units of the axis.
m

getAxisPosition()

throws
try translator.getAxisPosition(axis, unit)
Gets position of translator's axis. This method does not query device but returns value from translator's state.
Arguments
NameTypeDescription
axisStringLetter of the axis.
unitUnitsUnits of position.
Return Value
Double Position of translator's axis.
m

resetAfterStreamError()

throws
try translator.resetAfterStreamError()
Resets internal state after device rejected generated command. Axis positions become uninitialized.
m

resetPosition()

asyncthrows
try await translator.resetPosition()
Resets position of the translator from the underlying stream. Call this method after performing a movement outside of translator.
m

setAxisHomePosition()

throws
try translator.setAxisHomePosition(axis, position, unit)
Sets the home position of translator's axis. This position is used by G28.
Arguments
NameTypeDescription
axisStringLetter of the axis.
positionDoubleThe home position.
unitUnitsUnits of position.
m

setAxisPosition()

throws
try translator.setAxisPosition(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
NameTypeDescription
axisStringLetter of the axis.
positionDoubleThe position.
unitUnitsUnits of position.
m

setAxisSecondaryHomePosition()

throws
try translator.setAxisSecondaryHomePosition(axis, position, unit)
Sets the secondary home position of translator's axis. This position is used by G30.
Arguments
NameTypeDescription
axisStringLetter of the axis.
positionDoubleThe home position.
unitUnitsUnits of position.
m

setFeedRateOverride()

throws
try translator.setFeedRateOverride(coefficient)
Allows to scale feed rate of the translated code by a coefficient.
Arguments
NameTypeDescription
coefficientDoubleCoefficient of the original feed rate.
m

setTraverseRate()

throws
try translator.setTraverseRate(traverseRate, unit)
Sets the speed at which the device moves when traversing (G0).
Arguments
NameTypeDescription
traverseRateDoubleThe traverse rate.
unitUnitsUnits of the traverse rate.
s

setup()

asyncthrows
try await Translator.setup(stream, config = nil)
Sets up the translator on top of a provided stream.
Arguments
NameTypeDescription
streamStreamThe stream to setup the translator on. The stream must be already setup in a live or a store mode.
configTranslatorConfig?Configuration of the translator.
Return Value
Translator New instance of translator.
m

translate()

asyncthrows
try await translator.translate(block)
Translates a single block (line) of G-code. The commands are queued in the underlying stream to ensure smooth continues movement. Returning of this method indicates that the commands are queued (not necessarily executed).
Arguments
NameTypeDescription
blockStringBlock (line) of G-code.
Return Value
TranslateResult Result of translation containing the commands sent to the device.