rfid-silion-compat 0.1.0

Async Rust library for Silion RFID readers with serial and Web Serial support
Documentation

rfid-silion-compat

Async Rust reader library for Silion RFID reader protocol communication.

This crate provides:

  • A high-level reader API (SilionReader) for common reader operations
  • Async inventory session support
  • Optional native serial transport (tokio-serial)
  • Optional browser Web Serial + wasm-bindgen JS bindings
  • Supporting low-level protocol modules (command, parsers, frame) for advanced use

The protocol implementation follows Silion reader protocol docs: https://en.silion.com.cn/En/doc_center/ModuleAPI_Docs/Communication_Protocol_Doc/html/Protocol_Introduction.html

Crate Features

  • serial: enables native serial transport via tokio-serial
  • web-serial: enables wasm/browser support and JS bindings (for wasm32 targets)

Default features are empty.

Requirements

Core Rust development:

  1. Rust toolchain (stable)

For browser/wasm workflows:

  1. wasm-pack
  2. Node.js + npm

Install wasm-pack:

cargo install wasm-pack

Install

Add to your project:

cargo add rfid-silion-compat

Enable native serial support when needed:

cargo add rfid-silion-compat --features serial

Or directly in Cargo.toml:

[dependencies]
rfid-silion-compat = { version = "*", features = ["serial"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

Quick Start

Build protocol packets

cargo run --example build_packets

High-level reader API with mock transport

cargo run --example high_level_host

Native serial reader example

cargo run --features serial --example serial_query -- /dev/ttyUSB0 115200

Minimal Rust API usage

use rfid_silion_compat::SerialTransport;
use rfid_silion_compat::SilionReader;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
	let transport = SerialTransport::open("/dev/ttyUSB0", 115_200)?;
	let mut reader = SilionReader::new(transport);

	let version = reader.get_version().await?;
	println!("Firmware: {:02X?}", version.firmware_version);

	let temperature = reader.get_current_temperature().await?;
	println!("Temperature: {temperature} C");

	Ok(())
}

Build with the serial feature enabled.

For API-oriented documentation, see crate-level rustdoc in src/lib.rs and module docs in src/silion_reader.rs, src/command.rs, src/parsers.rs, and src/frame.rs.

Browser and Web Serial

A browser demo is available in examples/web/README.md.

Build browser output directly:

wasm-pack build --target web --out-dir examples/web/pkg -- --features web-serial

Then serve:

cd examples/web
python3 -m http.server 8080

Open http://localhost:8080 in a browser with Web Serial support.

Build npm Package from wasm

Use the helper script:

./scripts/build-npm-package.sh

What it does:

  1. Reads version from Cargo.toml
  2. Runs wasm-pack build --target bundler --release -- --features web-serial
  3. Updates pkg/package.json to match Cargo version

Publish package:

npm publish ./pkg

NPM Package (JavaScript/TypeScript)

This repository also ships an npm package for browser-based JS/TS usage:

  • Package name: rfid-silion-compat
  • npm-focused docs: npm/README.md

Validate Locally

cargo check
cargo test
cargo check --features serial
cargo check --target wasm32-unknown-unknown --features web-serial

Contributing and Governance

License

Licensed under either of:

Project Layout