| Crates.io | oxirs-modbus |
| lib.rs | oxirs-modbus |
| version | 0.1.0 |
| created_at | 2025-12-26 15:15:33.279601+00 |
| updated_at | 2026-01-20 21:46:39.786908+00 |
| description | Modbus TCP/RTU protocol support for OxiRS semantic web platform |
| homepage | https://github.com/cool-japan/oxirs |
| repository | https://github.com/cool-japan/oxirs |
| max_upload_size | |
| id | 2005846 |
| size | 401,356 |
Modbus TCP and RTU protocol support for the OxiRS semantic web platform.
✅ Production Ready (v0.1.0) - Phase D: Industrial Connectivity Complete
oxirs-modbus provides native Rust implementations of Modbus TCP and Modbus RTU protocols, enabling real-time RDF knowledge graph updates from industrial PLCs, sensors, energy meters, and other Modbus-enabled devices.
Market Coverage: 60% of factories worldwide use Modbus for industrial automation.
[dependencies]
oxirs-modbus = "0.1.0"
use oxirs_modbus::{ModbusTcpClient, ModbusConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to Modbus TCP device (PLC, energy meter, etc.)
let mut client = ModbusTcpClient::connect("192.168.1.100:502", 1).await?;
// Read holding registers (function code 0x03)
let registers = client.read_holding_registers(0, 10).await?;
println!("Registers: {:?}", registers);
Ok(())
}
use oxirs_modbus::mapping::RegisterMap;
use oxirs_core::store::RdfStore;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load register mapping from TOML
let register_map = RegisterMap::from_file("modbus_map.toml")?;
// Connect to Modbus device
let mut client = ModbusTcpClient::connect("192.168.1.100:502", 1).await?;
// Create RDF store
let mut store = RdfStore::new();
// Poll registers and update RDF graph
loop {
let values = client.read_holding_registers(0, 100).await?;
let triples = register_map.generate_triples(&values)?;
store.insert_batch(&triples).await?;
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}
}
[[stream.external_systems]]
type = "Modbus"
protocol = "TCP"
host = "192.168.1.100"
port = 502
unit_id = 1
polling_interval_ms = 1000
connection_timeout_ms = 5000
retry_attempts = 3
[stream.external_systems.rdf_mapping]
device_id = "plc001"
base_iri = "http://factory.example.com/device"
graph_iri = "urn:factory:plc-data"
# Temperature sensor (FLOAT32 spanning two registers)
[[stream.external_systems.rdf_mapping.registers]]
address = 40001
data_type = "FLOAT32"
predicate = "http://factory.example.com/property/temperature"
unit = "CEL"
scaling = { multiplier = 0.1, offset = -50.0 }
deadband = 5 # Only update if change > 0.5°C (after scaling)
# Pressure sensor (UINT16)
[[stream.external_systems.rdf_mapping.registers]]
address = 40003
data_type = "UINT16"
predicate = "http://factory.example.com/property/pressure"
unit = "BAR"
# Motor status (single bit)
[[stream.external_systems.rdf_mapping.registers]]
address = 40010
data_type = "BIT(0)"
predicate = "http://factory.example.com/property/motorRunning"
| Code | Name | Status |
|---|---|---|
| 0x03 | Read Holding Registers | ✅ Complete |
| 0x04 | Read Input Registers | ✅ Complete |
| 0x06 | Write Single Register | ✅ Complete |
| 0x10 | Write Multiple Registers | ✅ Complete |
| 0x01 | Read Coils | ⏳ Future |
| 0x02 | Read Discrete Inputs | ⏳ Future |
| 0x0F | Write Multiple Coils | ⏳ Future |
| Modbus Type | RDF Datatype | Registers | Notes |
|---|---|---|---|
| INT16 | xsd:short | 1 | Signed 16-bit integer |
| UINT16 | xsd:unsignedShort | 1 | Unsigned 16-bit integer |
| INT32 | xsd:int | 2 | Big-endian, two consecutive registers |
| UINT32 | xsd:unsignedInt | 2 | Big-endian, two consecutive registers |
| FLOAT32 | xsd:float | 2 | IEEE 754, two consecutive registers |
| BIT(n) | xsd:boolean | 1 | Extract single bit (n = 0-15) |
Tested with (planned):
The oxirs CLI provides Modbus monitoring and configuration:
# Monitor Modbus TCP device in real-time
oxirs modbus monitor-tcp --address 192.168.1.100:502 --start 40001 --count 10
# Read registers with type interpretation
oxirs modbus read --device 192.168.1.100:502 --address 40001 --datatype float32
# Generate RDF triples from Modbus data
oxirs modbus to-rdf --device 192.168.1.100:502 --config map.toml --output data.ttl
# Start mock server for testing
oxirs modbus mock-server --port 5020
See /tmp/oxirs_cli_phase_d_guide.md for complete CLI documentation.
Dual-licensed under MIT or Apache-2.0.