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
| OS | Steps | Port |
|---|---|---|
| Linux | Pair (see Bluetooth), then sudo rfcomm bind 0 00:16:53:0A:0B:0C 1 | /dev/rfcomm0 |
| macOS | Pair in System Settings → Bluetooth | /dev/tty.NXT-DevB (or similar, see ls /dev/tty.*) |
| Windows | Pair in Settings → Bluetooth, then More Bluetooth settings → COM Ports | The 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
Disconnectedfrom then on. Reconnect by opening the port again. - The default timeout is 3 seconds.