Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Serial ports

When an operating system pairs with an NXT, it can expose the brick’s serial port profile as a regular serial port. The serial feature talks to that port with serialport. It works on Linux, macOS and Windows, which makes it the portable Bluetooth option.

[dependencies]
nxt-rs = { git = "https://forge.wvffle.net/wvffle/nxt-rs.git", features = ["serial"] }
use nxt_rs::prelude::*;

fn main() -> nxt_rs::Result<()> {
let brick = Brick::serial("/dev/rfcomm0").block()?;
println!("battery: {}", brick.battery().block()?);
Ok(()) }

Finding the port

OSStepsPort
LinuxPair (see Bluetooth), then sudo rfcomm bind 0 00:16:53:0A:0B:0C 1/dev/rfcomm0
macOSPair in System Settings → Bluetooth/dev/tty.NXT-DevB (or similar, see ls /dev/tty.*)
WindowsPair in Settings → Bluetooth, then More Bluetooth settings → COM PortsThe outgoing port, e.g. COM5

Details

  • I/O runs on a small blocking thread pool, so it works with any async runtime.
  • If a request is cancelled while the port is busy (for example by a timeout), the transport reports Disconnected from then on. Reconnect by opening the port again.
  • The default timeout is 3 seconds.