A Rust library and terminal UI for BrainMaster Discovery 20/24E EEG amplifiers over USB serial (FTDI).
Dual backend: runtime-loaded bmrcm.dll FFI on Windows (18/18 functions) +
pure-Rust serial protocol on all OS. Frame decoding, sync detection, impedance
extraction, and conversion factors derived from the
neuromore studio open-source integration.
cargo add brainmaster| Device | Channels | Sampling Rate | Connection | Impedance |
|---|---|---|---|---|
| Discovery 20 | 20 EEG + 4 AUX (24 total) | 256 Hz | USB serial (FTDI, 460800 baud) | ✅ |
| Discovery 24E | 20 EEG + 4 AUX (24 total) | 256 Hz | USB serial (FTDI, 460800 baud) | ✅ |
Ch01 Fp1 Ch07 T3 Ch13 P4 Ch19 Pz
Ch02 F3 Ch08 T5 Ch14 O2 Ch20 A2
Ch03 C3 Ch09 Fz Ch15 F8 Ch21 Fpz
Ch04 P3 Ch10 Fp2 Ch16 T4 Ch22 Oz
Ch05 O1 Ch11 F4 Ch17 T6 Ch23 AUX23
Ch06 F7 Ch12 C4 Ch18 Cz Ch24 AUX24
Works on Windows, Linux, and macOS.
| Platform | bmrcm.dll FFI |
Pure-Rust serial | Requirements |
|---|---|---|---|
| Windows x86 | ✅ 18/18 functions | ✅ | FTDI drivers |
| Windows x64 | ❌ (32-bit DLL) | ✅ | FTDI drivers |
| Windows ARM64 | ❌ (32-bit DLL) | ✅ | FTDI drivers |
| Linux x64 | ❌ | ✅ | ftdi_sio kernel module |
| Linux ARM64 | ❌ | ✅ | ftdi_sio kernel module |
| macOS x64 | ❌ | ✅ | FTDI VCP (built-in) |
| macOS ARM64 | ❌ | ✅ | FTDI VCP (built-in) |
bmrcm.dll is a legacy Windows 32-bit DLL from BrainMaster Technologies.
The pure-Rust serial backend provides identical functionality on all
platforms — it implements the complete Discovery frame protocol directly
over the FTDI USB-serial interface.
The pure-Rust backend uses the serialport crate and requires no DLL.
It implements the complete Discovery serial frame protocol:
[0] Sync byte (cycles: 0x20 → 0x40 → 0x60 → 0x80 → 0xA0 → 0xC0 → 0xE0)
[1-2] Unused
[3] Steering (impedance channel selector, 1-28)
[4-5] Special data (impedance raw, 16-bit signed LE)
[6-77] 24 channels × 3 bytes (24-bit signed LE)
- EEG:
raw_24bit × 0.01658= µV - Impedance:
raw_16bit × 0.005= kΩ
| Function | Purpose |
|---|---|
AtlOpenPort |
Open COM port at baud rate |
AtlClosePort |
Close COM port |
AtlSetBaudRate |
Set baud rate (0x10=460800, 0x20=115200, 0x30=9600) |
AtlWriteSamplingRate |
Set device sampling rate |
AtlReadSamplingRate |
Read device sampling rate |
AtlClearSpecials |
Clear all special selections |
AtlFlush |
Flush serial buffers |
BmrLoginDevice |
Authenticate with codekey/serial/passkey |
DiscStartModule |
Start data acquisition |
DiscStopModule |
Stop data acquisition |
AtlGetBytesInQue |
Get bytes available in receive buffer |
AtlReadData |
Read raw bytes from buffer |
AtlSelectImpedanceChans |
Select impedance measurement channels |
AtlSelectSpecial |
Select special data mode |
AtlSetNotchFilters |
Configure notch filters |
AtlPeek |
Read device memory location |
AtlPoke |
Write device memory location |
AtlQueryFirmware |
Query firmware version |
use brainmaster::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let ports = DiscoveryDevice::find()?;
let mut device = DiscoveryDevice::open(&ports[0])?;
device.start()?;
for _ in 0..SAMPLING_RATE as usize * 4 {
if let Some(_frame) = device.read_frame()? {
let ch = device.channels();
println!("Fp1={:.2}µV O1={:.2}µV O2={:.2}µV",
ch.data[0], ch.data[4], ch.data[13]);
}
}
device.stop()?;
device.close();
Ok(())
}brainmaster-rs/
├── Cargo.toml
├── README.md
├── CHANGELOG.md
├── LICENSE
└── src/
├── lib.rs # Crate root + prelude
├── main.rs # CLI binary
├── bin/tui.rs # ratatui TUI (8-channel EEG charts)
├── ffi.rs # Runtime-loaded bmrcm.dll (Windows, 18 functions)
├── protocol.rs # Pure-Rust serial protocol (all OS)
├── types.rs # Frame format, channels, sync, conversion
├── device.rs # High-level device API
└── error.rs # Error types
├── examples/
│ ├── scan.rs # Port discovery
│ ├── read_eeg.rs # 4-second EEG capture
│ └── read_impedance.rs # Impedance measurement
└── tests/
└── protocol_tests.rs # Frame decode, sync, conversion tests
| Crate | Purpose |
|---|---|
| serialport | Cross-platform serial I/O (FTDI USB) |
| libloading | Runtime DLL loading (Windows, optional) |
| thiserror | Error types |
| log | Logging facade |
| env_logger | Log output |
| ratatui | Terminal UI (optional) |
| crossterm | Terminal backend (optional) |
cargo test