API Reference v9.2.0
Connectionclass
Module: zaber_motion.ascii
Class representing access to particular connection (serial port, TCP connection).
The following examples illustrate how you can obtain an instance of this type:
Example 1
Example 2
Example 3
Example 4
Example 5
from zaber_motion.ascii import Connection
connection = Connection.open_serial_port('COM3')from zaber_motion.ascii import Connection
connection = Connection.open_tcp('zaber-12345.local')from zaber_motion.ascii import Connection
connection = Connection.open_iot('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx')from zaber_motion.ascii import Connection
connection = Connection.open_network_share('localhost')from zaber_motion.ascii import Connection
from zaber_motion.ascii import Transport
transport = Transport.open()
connection = Connection.open_custom(transport)Related Guides:
Index
Constants
c
c
c
Properties
p
p
p
p
Events
e
connection.alertEvent invoked when an alert is received from a device.
Emitted Data
AlertEvent Alert message received from the device.e
connection.disconnectedEvent invoked when connection is interrupted or closed.
Emitted Data
MotionLibException Error that caused disconnection.e
connection.unknown_responseEvent 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
connection.detect_devices(identify_devices = True)Attempts to detect any devices present on this connection.
Arguments
| Name | Type | Description |
|---|---|---|
| identify_devices | bool | Determines whether device identification should be performed as well. |
Return Value
List[Device] Array of detected devices.m
m
m
m
connection.generic_command(command, device = 0, axis = 0, check_errors = True, timeout = 0)Sends a generic ASCII command to this connection. For more information refer to the ASCII Protocol Manual.
Arguments
| Name | Type | Description |
|---|---|---|
| command | str | Command and its parameters. |
| device | int | Optional device address to send the command to. |
| axis | int | Optional axis number to send the command to. |
| check_errors | bool | Controls whether to throw an exception when the device rejects the command. |
| timeout | int | The timeout, in milliseconds, for a device to respond to the command. Overrides the connection default request timeout. |
Return Value
Response A response to the command.m
connection.generic_command_multi_response(command, device = 0, axis = 0, check_errors = True, timeout = 0)Sends a generic ASCII command to this connection and expect multiple responses, either from one device or from many devices. Responses are returned in order of arrival. For more information refer to the ASCII Protocol Manual.
Arguments
| Name | Type | Description |
|---|---|---|
| command | str | Command and its parameters. |
| device | int | Optional device address to send the command to. |
| axis | int | Optional axis number to send the command to. |
| check_errors | bool | Controls whether to throw an exception when a device rejects the command. |
| timeout | int | The timeout, in milliseconds, for a device to respond to the command. Overrides the connection default request timeout. |
Return Value
List[Response] All responses to the command.m
connection.generic_command_no_response(command, device = 0, axis = 0)Sends a generic ASCII command to this connection without expecting a response and without adding a message ID. For more information refer to the ASCII Protocol Manual.
Arguments
| Name | Type | Description |
|---|---|---|
| command | str | Command and its parameters. |
| device | int | Optional device address to send the command to. Specifying -1 omits the number completely. |
| axis | int | Optional axis number to send the command to. Specifying -1 omits the number completely. |
m
connection.get_device(device_address)Gets a Device class instance which allows you to control a particular device on this connection. Devices are numbered from 1.
Arguments
| Name | Type | Description |
|---|---|---|
| device_address | int | Address of device intended to control. Address is configured for each device. |
Return Value
Device Device instance.m
connection.home_all(wait_until_idle = True)Homes all of the devices on this connection.
Arguments
| Name | Type | Description |
|---|---|---|
| wait_until_idle | bool | Determines whether the function should return immediately or wait until the devices are homed. |
Return Value
List[int] The addresses of the devices that were homed by this command.s
Connection.open_custom(transport)Opens a connection using a custom transport.
Arguments
| Name | Type | Description |
|---|---|---|
| transport | Transport | The custom connection transport. |
Return Value
Connection An object representing the connection.s
Connection.open_iot(cloud_id, token = "unauthenticated", connection_name = None, realm = None, api = "https://api.zaber.io")Opens a secured connection to a cloud connected device chain. Use this method to connect to devices on your account.
Arguments
| Name | Type | Description |
|---|---|---|
| cloud_id | str | The cloud ID to connect to. |
| token | str | The token to authenticate with. By default the connection will be unauthenticated. |
| connection_name | Optional[str] | The name of the connection to open. Can be left empty to default to the only connection present. Otherwise, use serial port name for serial port connection or hostname:port for TCP connection. |
| realm | Optional[str] | The realm to connect to. Can be left empty for the default account realm. |
| api | str | The URL of the API to receive connection info from. |
Return Value
Connection An object representing the connection.s
Connection.open_serial_port(port_name, baud_rate = DEFAULT_BAUD_RATE, direct = False, test_port = False)Opens a serial port, if Zaber Launcher controls the port, the port will be opened through Zaber Launcher. Zaber Launcher allows sharing of the port between multiple applications, If port sharing is not desirable, use the `direct` parameter.
Arguments
| Name | Type | Description |
|---|---|---|
| port_name | str | Name of the port to open. |
| baud_rate | int | Optional baud rate (defaults to 115200). |
| direct | bool | If true will connect to the serial port directly, failing if the connection is already opened by a message router instance. |
| test_port | bool | Some operating systems may allow opening a serial port that is not writable. Tests if the serial port is writable, and throws an exception if it is not. |
Return Value
Connection An object representing the port.s
Connection.open_tcp(host_name, port = TCP_PORT_CHAIN)Opens a TCP connection.
Arguments
| Name | Type | Description |
|---|---|---|
| host_name | str | Hostname or IP address. |
| port | int | Optional port number (defaults to 55550). |
Return Value
Connection An object representing the connection.m
connection.renumber_devices(first_address = 1)Renumbers devices present on this connection. After renumbering, devices need to be identified again.
Arguments
| Name | Type | Description |
|---|---|---|
| first_address | int | This is the address that the device closest to the computer is given. Remaining devices are numbered consecutively. |
Return Value
int Total number of devices that responded to the renumber.m
m
connection.stop_all(wait_until_idle = True)Stops all of the devices on this connection.
Arguments
| Name | Type | Description |
|---|---|---|
| wait_until_idle | bool | Determines whether the function should return immediately or wait until the devices are stopped. |
Return Value
List[int] The addresses of the devices that were stopped by this command.