From e43bdedcd9331d90adfea2add08f54eb9b07bb9f Mon Sep 17 00:00:00 2001 From: Grigorios <32260282+OGrigorios@users.noreply.github.com> Date: Sun, 23 Oct 2022 10:26:25 +0200 Subject: [PATCH 1/2] Create README.md Written initial README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..bbe7803 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# k8056 +Library crate that implements the communication with a k8056 relay card, written in Rust. + +This library provides basic structs and enums that provide the specified ACSII instruction, needed to communicate with the K8056 8-CHANNEL RELAY CARD manufactured by Velleman +To send the instructions to the relay card, a serial library like [serialport](https://crates.io/crates/serialport) is needed. From dd167acda18d62743921c8e20e75659aaa770d7b Mon Sep 17 00:00:00 2001 From: Grigorios <32260282+OGrigorios@users.noreply.github.com> Date: Sun, 23 Oct 2022 15:31:19 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index bbe7803..4f33e89 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,39 @@ Library crate that implements the communication with a k8056 relay card, written This library provides basic structs and enums that provide the specified ACSII instruction, needed to communicate with the K8056 8-CHANNEL RELAY CARD manufactured by Velleman To send the instructions to the relay card, a serial library like [serialport](https://crates.io/crates/serialport) is needed. + +Working example using serialport library +``` +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)); + } +} +```