1 个不稳定版本
0.1.0 | 2022年10月26日 |
---|
#1478 在 硬件支持
5KB
61 行
k8056
实现与k8056继电器卡通信的库crate,使用Rust编写。
此库提供基本的structs和enums,它们提供所需的ACSII指令,用于与Velleman制造的K8056 8通道继电器卡通信。要向继电器卡发送指令,需要一个如serialport的串行库。
使用serialport库的示例
use serialport;
use k8056::uart::{Command, Idx};
use std::thread;
use std::time::Duration;
fn main() {
let mut port = serialport::new("/dev/ttyUSB0", 2_400)
.timeout(Duration::from_millis(10))
.data_bits(serialport::DataBits::Eight)
.parity(serialport::Parity::None)
.stop_bits(serialport::StopBits::One)
.open()
.expect("Failed to open port");
// Just a bunch of Commands to show how to initialize them
let cmd = Command::Byte(0x1C);
let cmd = Command::Emergency;
let cmd = Command::Force;
let cmd = Command::Display;
let cmd = Command::Address(Idx::new(2));
port.write(&cmd.to_bytes(1)).expect("Write failed!");
for i in 1..9 {
let cmd = Command::Toggle(Idx::new(i));
port.write(&cmd.to_bytes(1)).expect("Write failed!");
thread::sleep(Duration::from_millis(1000));
}
for i in (1..9).rev() {
let cmd = Command::Toggle(Idx::new(i));
port.write(&cmd.to_bytes(1)).expect("Write failed!");
thread::sleep(Duration::from_millis(1000));
}
}