You are here: Lua Scripting Resources eGuide > Lua Scripting API Reference Guide > ASI Library > connect

21.7.5 connect

error = port:connect(connectionCallback[, object])

Sends an asynchronous request for connection to the port. When the request is processed, the result is reported to the specified callback.

Parameter

Type

Description

port

in port object

The port to connect to.

connectionCallback

in function

Callback to receive connection events.

object

in any (optional)

If an object is provided, it will be passed as the first parameter to the specified callback function. The object can be of any type except nil.

error

out string (optional)

If successful nil is returned, an error message otherwise.

Introduced in platform.apiLevel = '2.7'.

Callback Function

connectionCallback ([object,] port, event[, error])

The callback function provided in connect will be called when the state of the connection to the port changes.

Parameter

Type

Description

object

in any (optional)

If an object was provided as a parameter to the function connect, it will be passed as the first parameter to this callback function.

port

in port object

The port requesting to connect or disconnect.

event

in asi table constant

The connection event (please see table below).

error

in string (optional)

If successfully connected or disconnected the parameter will be nil, an error message otherwise.

Event Constants

Connection event

Description

asi.CONNECTED

The connection was successful and the port is ready for input/output operations.

asi.CONNECTING_FAILED

The connection failed.
An error message is received.

asi.DISCONNECTED

The port has been disconnected.
An error message is received if the port has been removed from the system.

Introduced in platform.apiLevel = '2.7'.