API Reference v9.2.0

Connectionclass

Module: ZaberMotionBinary

Class representing access to particular connection (serial port, TCP connection) using the legacy Binary protocol.

To use this type, add import ZaberMotionBinary to the top of your source code.

Constants

c

defaultBaudRate

Connection.defaultBaudRate
Int Default baud rate for serial connections.
Value
9600
c

tcpPortChain

Connection.tcpPortChain
Int Commands sent over this port are forwarded to the device chain. The bandwidth may be limited as the commands are forwarded over a serial connection.
Value
55550
c

tcpPortDeviceOnly

Connection.tcpPortDeviceOnly
Int Commands send over this port are processed only by the device and not forwarded to the rest of the chain. Using this port typically makes the communication faster.
Value
55551

Properties

p

interfaceId

readonly
connection.interfaceId
Int The interface ID identifies thisConnection instance with the underlying library.
p

isOpen

readonlythrows
try connection.isOpen
Bool Returns whether the connection is open. Does not guarantee that the subsequent requests will succeed.

Events

e

Disconnected

connection.Disconnected
Event invoked when connection is interrupted or closed.
Emitted Data
MotionLibException Error that caused disconnection.
e

ReplyOnly

connection.ReplyOnly
Event invoked when a reply-only command such as a move tracking message is received from a device.
Emitted Data
ReplyOnlyEvent Reply-only message received from the device.
e

UnknownResponse

connection.UnknownResponse
Event invoked when a response from a device cannot be matched to any known request.
Emitted Data
UnknownResponseEvent Reply that could not be matched to a request.

Methods

m

close()

asyncthrows
try await connection.close()
Close the connection.
m

detectDevices()

asyncthrows
try await connection.detectDevices(identifyDevices = true)
Attempts to detect any devices present on this connection.
Arguments
NameTypeDescription
identifyDevicesBoolDetermines whether device identification should be performed as well.
Return Value
[Device] Array of detected devices.
m

genericCommand()

asyncthrows
try await connection.genericCommand(device, command, data = 0, timeout = 0.0, checkErrors = true)
Sends a generic Binary command to this connection. For more information please refer to the Binary Protocol Manual.
Arguments
NameTypeDescription
deviceIntDevice address to send the command to. Use zero for broadcast.
commandCommandCodeCommand to send.
dataIntOptional data argument to the command. Defaults to zero.
timeoutDoubleNumber of seconds to wait for a response from the device. 0 or negative defaults to 0.5s.
checkErrorsBoolControls whether to throw an exception when the device rejects the command.
Return Value
Message A response to the command.
m

genericCommandMultiResponse()

asyncthrows
try await connection.genericCommandMultiResponse(command, data = 0, timeout = 0.0, checkErrors = true)
Sends a generic Binary command to this connection and expects responses from one or more devices. Responses are returned in order of arrival. For more information please refer to the Binary Protocol Manual.
Arguments
NameTypeDescription
commandCommandCodeCommand to send.
dataIntOptional data argument to the command. Defaults to zero.
timeoutDoubleNumber of seconds to wait for all responses from the device chain. 0 or negative defaults to 0.5s.
checkErrorsBoolControls whether to throw an exception when any device rejects the command.
Return Value
[Message] All responses to the command.
m

genericCommandNoResponse()

asyncthrows
try await connection.genericCommandNoResponse(device, command, data = 0)
Sends a generic Binary command to this connection without expecting a response. For more information please refer to the Binary Protocol Manual.
Arguments
NameTypeDescription
deviceIntDevice address to send the command to. Use zero for broadcast.
commandCommandCodeCommand to send.
dataIntOptional data argument to the command. Defaults to zero.
m

getDevice()

throws
try connection.getDevice(deviceAddress)
Gets a Device class instance which allows you to control a particular device on this connection. Devices are numbered from 1.
Arguments
NameTypeDescription
deviceAddressIntAddress of device intended to control. Address is configured for each device.
Return Value
Device Device instance.
s

openSerialPort()

asyncthrows
try await Connection.openSerialPort(portName, baudRate = Connection.defaultBaudRate, useMessageIds = false)
Opens a serial port.
Arguments
NameTypeDescription
portNameStringName of the port to open.
baudRateIntOptional baud rate (defaults to 9600).
useMessageIdsBoolEnable use of message IDs (defaults to disabled). All your devices must be pre-configured to match.
Return Value
Connection An object representing the port.
s

openTcp()

asyncthrows
try await Connection.openTcp(hostName, port = Connection.tcpPortChain, useMessageIds = false)
Opens a TCP connection.
Arguments
NameTypeDescription
hostNameStringHostname or IP address.
portIntOptional port number (defaults to 55550).
useMessageIdsBoolEnable use of message IDs (defaults to disabled). All your devices must be pre-configured to match.
Return Value
Connection An object representing the connection.
m

renumberDevices()

asyncthrows
try await connection.renumberDevices()
Renumbers devices present on this connection. After renumbering, you must identify devices again.
Return Value
Int Total number of devices that responded to the renumber.
m

toString()

throws
try connection.toString()
Returns a string that represents the connection.
Return Value
String A string that represents the connection.