Connection Backends

Backends are used by nxt.locator.find(). You will usually not use them directly.

USB

class nxt.backend.usb.USBSock(dev)

USB socket connected to a NXT brick.

bsize = 60

Block size.

type = 'usb'

Connection type, used to evaluate latency.

connect()

Connect to NXT brick.

Returns:

Connected brick.

Return type:

Brick

close()

Close the connection.

send(data)

Send raw data.

Parameters:

data (bytes) – Data to send.

recv()

Receive raw data.

Returns:

Received data.

Return type:

bytes

class nxt.backend.usb.Backend

USB backend.

find(**kwargs)

Find bricks connected using USB.

Parameters:

kwargs – Parameters are ignored.

Returns:

Iterator over all found bricks.

Return type:

Iterator[Brick]

nxt.backend.usb.get_backend()

Get an instance of the Bluetooth backend.

Returns:

Bluetooth backend.

Return type:

Backend

Bluetooth

class nxt.backend.bluetooth.BluetoothSock(bluetooth, host)

Bluetooth socket connected to a NXT brick.

bsize = 118

Block size.

type = 'bluetooth'

Connection type, used to evaluate latency.

connect()

Connect to NXT brick.

Returns:

Connected brick.

Return type:

Brick

close()

Close the connection.

send(data)

Send raw data.

Parameters:

data (bytes) – Data to send.

recv()

Receive raw data.

Returns:

Received data.

Return type:

bytes

class nxt.backend.bluetooth.Backend(bluetooth)

Bluetooth backend.

find(host=None, name=None, **kwargs)

Find bricks connected using Bluetooth.

Parameters:
  • host (str or None) – Bluetooth address (example: "00:16:53:01:02:03").

  • name (str or None) – Brick name (example: "NXT").

  • kwargs – Other parameters are ignored.

Returns:

Iterator over all found bricks.

Return type:

Iterator[Brick]

nxt.backend.bluetooth.get_backend()

Get an instance of the Bluetooth backend if available.

Returns:

Bluetooth backend.

Return type:

Backend or None

Device file

class nxt.backend.devfile.DevFileSock(filename)

Device file socket connected to a NXT brick.

bsize = 118

Block size.

type = 'bluetooth'

Connection type, used to evaluate latency.

connect()

Connect to NXT brick.

Returns:

Connected brick.

Return type:

Brick

close()

Close the connection.

send(data)

Send raw data.

Parameters:

data (bytes) – Data to send.

recv()

Receive raw data.

Returns:

Received data.

Return type:

bytes

class nxt.backend.devfile.Backend

Device file backend.

This uses a device file present on Linux or macOS /dev file system, which allows to connect to the NXT brick without needing a Bluetooth python package.

You only need to use this backend if the bluetooth backend is not working for you.

On Linux, you need to pair the NXT brick, then you can use the rfcomm tool:

sudo rfcomm bind 0 00:16:53:01:02:03

Where 00:16:53:01:02:03 is the Bluetooth address of your NXT brick. This will create a /dev/rfcomm0 device file which can be used to communicate with the NXT brick.

On macOS, you need to pair the NXT brick, then open Bluetooth preferences, select the NXT brick, click “Edit serial ports”. It should show “NXT-DevB-1”. If not, add a serial port using:

  • Port name: NXT-DevB-1

  • Device service: Dev B

  • Port type: RS-232

This should create a /dev/tty.NXT-DevB-1 device file which can be used to communicate with the NXT brick.

find(name=None, filename=None, **kwargs)

Find bricks connected using Bluetooth using device file.

Parameters:
  • name (str or None) – Brick name (example: "NXT").

  • filename (str or None) – Device file name (example: "/dev/rfcomm0").

  • kwargs – Other parameters are ignored.

Returns:

Iterator over all found bricks.

Return type:

Iterator[Brick]

nxt.backend.devfile.get_backend()

Get an instance of the device file backend.

Returns:

Device file backend.

Return type:

Backend

Socket

class nxt.backend.socket.SocketSock(host, port)

Socket socket connected to a NXT brick.

bsize = 60

Block size, conservative.

type

Connection type, used to evaluate latency, known on connection.

connect()

Connect to NXT brick.

Returns:

Connected brick.

Return type:

Brick

close()

Close the connection.

send(data)

Send raw data.

Parameters:

data (bytes) – Data to send.

recv()

Receive raw data.

Returns:

Received data.

Return type:

bytes

class nxt.backend.socket.Backend

Socket backend.

To be used with nxt_server script to access a NXT brick over the network.

find(server_host='localhost', server_port=2727, **kwargs)

Find bricks connected using a socket.

Parameters:
  • server_host (str) – Server address or name, default to localhost.

  • server_port (str or int) – Server port, default to 2727.

  • kwargs – Other parameters are ignored.

Returns:

Iterator over all found bricks.

Return type:

Iterator[Brick]

nxt.backend.socket.get_backend()

Get an instance of the Socket backend.

Returns:

Socket backend.

Return type:

Backend