Crates.io | lsl |
lib.rs | lsl |
version | 0.1.1 |
source | src |
created_at | 2020-10-23 05:20:35.466398 |
updated_at | 2020-10-26 17:42:13.553241 |
description | Lab streaming layer (liblsl) bindings for rust. |
homepage | |
repository | https://github.com/labstreaminglayer/liblsl-rust |
max_upload_size | |
id | 304569 |
size | 116,360 |
Safe high-level bindings for the liblsl
library, the main network library of
the lab streaming layer (LSL).
The lab streaming layer is a peer-to-peer pub/sub system on the local network that allows for real-time exchange of multi-channel time series (plus their meta-data) between applications and machines, with built-in cross-device time synchronization.
The most common use case is in lab spaces to make, e.g., instrument data from different pieces of hardware (e.g., sensors) accessible in real time to client programs (e.g., experimentation scripts, recording programs, stream viewers, or live processing software). One of the main features of LSL is the uniform API that allows clients to read formatted multi-channel data from many device types (such as EEG, eye tracking, audio, human interface devices, events, etc.) with the same few lines of code.
See the scripts in the examples/ folder of the git repo for the fully-commented version of the below code. Examples for other use cases can be found there too.
use lsl;
use lsl::Pushable;
fn main() -> Result<(), lsl::Error> {
// declare a stream and create an outlet
let info = lsl::StreamInfo::new(
"BioSemi", "EEG", 8, 100.0,
lsl::ChannelFormat::Float32, "myid234365")?;
let outlet = lsl::StreamOutlet::new(&info, 0, 360)?;
// stream some 8-channel data
loop {
let sample = vec![1, 2, 3, 4, 5, 6, 7, 8];
outlet.push_sample(&sample)?;
std::thread::sleep(std::time::Duration::from_millis(10));
}
}
use lsl;
use lsl::Pullable;
fn main() -> Result<(), lsl::Error> {
// resolve a data stream and create an inlet to read from it
let res = lsl::resolve_bypred("name='BioSemi' and type='EEG'", 1, lsl::FOREVER)?;
let inl = lsl::StreamInlet::new(&res[0], 360, 0, true)?;
// read the streaming data and print the multi-channel samples
loop {
let (sample, ts): (Vec<f32>, _) = inl.pull_sample(lsl::FOREVER)?;
println!("got {:?} at time {}", sample, ts);
}
}
Add a new entry to your dependencies in Cargo.toml
:
[dependencies]
lsl = "0.1.1"
Add the following to your code:
use lsl;
git clone --recurse-submodules https://github.com/labstreaminglayer/liblsl-rust
This crate currently links against the liblsl
library statically (dynamic linking against the
system library, if present, is planned for a future release). To compile the crate (and the native
library), you need:
brew install cmake
on MacOS if you have Homebrew or
sudo apt-get install cmake
on Ubuntu), this might already pull in the second dependency (the
system compiler), so building may already work.build-essentials
, and on MacOS XCode CLI).With these dependencies met, the package should compile for you. The following targets have been tested with this crate so far:
* x86_64-pc-windows-msvc
* x86_64-unknown-linux-gnu
* x86_64-apple-darwin
Doocumentation for the most recent release can be found at docs.rs.
The lsl
crate depends on a lower-level lsl-sys
crate that provides the raw (unsafe) native
library bindings. Using that crate directly is not recommended (you might as well be coding in C).
These bindings are autogenerated and can be updated to a newer upstream native library version by
following the instructions in that crate's readme.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion
in the lsl
crate by you, shall be licensed as MIT, without any additional terms or conditions.