| Crates.io | lib60870 |
| lib.rs | lib60870 |
| version | 0.4.0 |
| created_at | 2025-12-04 14:01:16.154803+00 |
| updated_at | 2025-12-04 14:43:04.220333+00 |
| description | Safe Rust bindings to lib60870-C, an IEC 60870-5-101/104 protocol implementation |
| homepage | |
| repository | https://github.com/tomas789/lib60870-sys |
| max_upload_size | |
| id | 1966504 |
| size | 516,497 |
Safe Rust bindings to lib60870-C, an IEC 60870-5-101/104 protocol implementation.
| Platform | Status |
|---|---|
| Linux | ✅ Fully supported |
| macOS | ✅ Fully supported |
| Windows | ⚠️ Experimental (build works, runtime issues) |
Note: Windows support is experimental. The library compiles successfully but may have runtime issues related to DLL dependencies. Contributions to improve Windows support are welcome!
[dependencies]
lib60870 = { git = "https://github.com/..." }
# With TLS support:
lib60870 = { git = "https://github.com/...", features = ["tls"] }
use lib60870::client::ConnectionBuilder;
use lib60870::types::{CauseOfTransmission, QOI_STATION};
fn main() {
let mut conn = ConnectionBuilder::new("127.0.0.1", 2404)
.originator_address(3)
.build()
.expect("Failed to create connection");
// Set up handlers
conn.set_handlers(
|event| println!("Connection event: {:?}", event),
|asdu| {
println!("Received ASDU: {:?}", asdu);
for obj in asdu.parse_objects() {
println!(" {:?}", obj);
}
true
},
);
// Connect and send interrogation
if conn.connect() {
println!("Connected!");
conn.send_start_dt();
conn.send_interrogation(CauseOfTransmission::Activation, 1, QOI_STATION);
std::thread::sleep(std::time::Duration::from_secs(5));
}
// Connection automatically closed on drop
}
Run this example:
cargo run --example client
use lib60870::server::ServerBuilder;
use lib60870::types::{CauseOfTransmission, Quality};
fn main() {
let mut server = ServerBuilder::new()
.local_port(2404)
.build()
.expect("Failed to create server");
server.set_connection_event_handler(|event| {
println!("Connection: {:?}", event);
});
server.set_interrogation_handler(|conn, asdu, qoi| {
println!("Interrogation for group {}", qoi);
conn.send_act_con(&asdu, false);
// Send response data here...
conn.send_act_term(&asdu);
true
});
server.start();
println!("Server running on port 2404");
// Send periodic data
loop {
server.send_measured_scaled(
CauseOfTransmission::Periodic,
1, // Common address
100, // IOA
42, // Value
Quality::GOOD,
);
std::thread::sleep(std::time::Duration::from_secs(1));
}
}
Run this example:
cargo run --example server
For advanced use cases, raw FFI bindings are available via the sys module:
use lib60870::sys;
let version = unsafe { sys::Lib60870_getLibraryVersionInfo() };
println!("lib60870 v{}.{}.{}", version.major, version.minor, version.patch);
| Feature | Description |
|---|---|
tls |
Enable TLS support (downloads mbedtls 2.28) |
debug |
Enable printf debug output |
no-threads |
Disable threading (for embedded systems) |
tcp-keepalive |
Enable TCP keep-alive |
The build script (build.rs) automatically:
tls feature is enabled)All downloads are cached in target/ so subsequent builds are fast.
lib60870 is dual-licensed under GPLv3 and a commercial license. See lib60870 repository for details.