| Crates.io | nanonis-rs |
| lib.rs | nanonis-rs |
| version | 0.0.3 |
| created_at | 2025-12-17 09:37:52.39059+00 |
| updated_at | 2025-12-17 09:37:52.39059+00 |
| description | Rust client library for Nanonis SPM system control via TCP |
| homepage | https://github.com/kronberger-droid/nanonis-rs |
| repository | https://github.com/kronberger-droid/nanonis-rs |
| max_upload_size | |
| id | 1989836 |
| size | 3,929,145 |
A Rust client library for communicating with Nanonis SPM (Scanning Probe Microscopy) systems via the Nanonis TCP protocol. This library provides a type-safe, high-level interface for controlling scanning probe microscopes and reading measurement data.
Add this to your Cargo.toml:
[dependencies]
nanonis-rs = "0.0.3"
use nanonis_rs::{NanonisClient, NanonisError};
use std::time::Duration;
fn main() -> Result<(), NanonisError> {
// Connect to Nanonis system
let mut client = NanonisClient::builder()
.address("192.168.1.100:6501")
.timeout(Duration::from_secs(5))
.build()?;
// Get current bias voltage
let bias = client.bias_get()?;
println!("Current bias: {} V", bias);
// Set new bias voltage
client.bias_set(0.5)?;
// Read signal values
let signals = client.signals_vals_get()?;
println!("Signals: {:?}", signals);
Ok(())
}
use nanonis_rs::{NanonisClient, MotorDirection, MotorGroup};
use std::time::Duration;
fn main() -> Result<(), NanonisError> {
let mut client = NanonisClient::connect("192.168.1.100:6501")?;
// Move motor with specified steps
client.motor_start_move(
MotorDirection::ZPlus,
1000, // steps
MotorGroup::Group1,
false // non-blocking
)?;
// Wait for movement to complete
std::thread::sleep(Duration::from_millis(500));
Ok(())
}
use nanonis_rs::TCPLoggerStream;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut stream = TCPLoggerStream::connect("192.168.1.100:6502")?;
// Read streaming data
loop {
let data = stream.read_data()?;
println!("Timestamp: {}, Channels: {}",
data.timestamp, data.channels.len());
// Process data...
}
}
The library is organized into several layers:
protocol.rs): Low-level TCP message encoding/decodingtypes.rs): Protocol value types and domain-specific typesclient/): High-level API organized by functionalityerror.rs): Comprehensive error types with contextAll communication with Nanonis follows a request-response pattern with strongly-typed inputs and outputs.
Create clients using the builder pattern for advanced configuration:
use nanonis_rs::NanonisClient;
use std::time::Duration;
let client = NanonisClient::builder()
.address("192.168.1.100:6501")
.timeout(Duration::from_secs(10))
.max_response_size(100_000_000) // 100 MB
.build()?;
Or use the simpler connect method:
let client = NanonisClient::connect("192.168.1.100:6501")?;
The client implements automatic safety features:
The library uses typed errors via NanonisError:
match client.bias_get() {
Ok(bias) => println!("Bias: {} V", bias),
Err(NanonisError::Timeout(msg)) => eprintln!("Timeout: {}", msg),
Err(NanonisError::Server { code, message }) => {
eprintln!("Server error {}: {}", code, message)
}
Err(e) => eprintln!("Error: {}", e),
}
Full API documentation is available on docs.rs. The documentation includes detailed examples for each command.
This project uses Nix flakes for reproducible development environments:
# Enter development shell
nix develop
# Build the library
cargo build
# Run tests (requires Nanonis connection)
cargo test
# Build documentation
cargo doc --open
Licensed under the MIT License. See LICENSE for details.
Contributions are welcome! Please feel free to submit pull requests or open issues on GitHub.
This library implements the Nanonis TCP protocol as documented by SPECS Zurich GmbH. Nanonis is a registered trademark of SPECS Zurich GmbH.