Closed azaslavskis closed 3 years ago
/* This code for receiving bytes from serial port with non-standard baud rate. Applies for Sbus interface.
You need take package for cargo (Just copy names of packages and paste to your cargo.toml below labelled [dependencies])
serial-unix = "0.4.0"
serial-core = "0.4.0"
serial = "0.4.0"
libc = "0.2.79"
File of this code: main.rs
Created code by M.Zaslavskis */
extern crate serial;
use std::io::prelude::*;
use serial::prelude::*;
/* Setting for serial port before run it */
const SETTINGS: serial::PortSettings = serial::PortSettings {
baud_rate: serial::BaudOther(100000), // baud rate
char_size: serial::Bits8, // char size of serial port (unit: bits)
parity: serial::ParityEven, // Parity of serial port
stop_bits: serial::Stop2, // stop bits
flow_control: serial::FlowNone, // flow mode
};
/* Main function */
fn main() {
println!("opening port...");
let mut port = serial::open("/dev/ttyAMA0").unwrap(); // open serial port
port.configure(&SETTINGS); // setting serial port before read information or bytes (Notice: this variable can use a constant struct)
let mut buf:[u8; 1] = [0; 1]; // buffer of one arrays...
/* read bytes in infitite loop */
loop {
port.read(&mut buf[..]); // read bytes for serial port device
println!("reading bytes : {}", buf[0]); // print bytes in ternimal
}
}
/* This code for receiving bytes from serial port with non-standard baud rate. Applies for Sbus interface.
You need take package for cargo (Just copy names of packages and paste to your cargo.toml below labelled [dependencies])
mio-serial = "3.3.1"
mio = "0.7.4"
serialport = "3.3.0"
File of this code: main.rs
Date: 28th october 2020
Created code by M.Zaslavskis */
extern crate mio_serial;
extern crate serialport;
use std::io::{Read};
use std::time::Duration;
use std::path::Path;
use serialport::posix::TTYPort;
use mio_serial::unix::Serial;
fn main()
{
// Initialize for timeout
let timeout = Duration::new(1, 0);
// Initialize serial port before run a serial port
let settings:mio_serial::SerialPortSettings = mio_serial::SerialPortSettings
{
baud_rate: 100000, // baudrate
data_bits: mio_serial::DataBits::Eight, // data bits
flow_control: mio_serial::FlowControl::None, // flow control
parity: mio_serial::Parity::Even, // Parity
stop_bits: mio_serial::StopBits::Two, // Stop bits
timeout: timeout // timeout before reading serial port
};
let tty_name = Path::new("/dev/ttyACM1"); // create path of serial port
let blocking_serial = TTYPort::open(tty_name, &settings).unwrap(); // opening serial port
let mut serial = Serial::from_serial(blocking_serial).unwrap(); // call class of serial port
let mut buf = [0u8; 1]; // buffer for storing bytes of receiving data transfet
// Reading datas form serial port infinity cycle of execute code
loop {
serial.read(&mut buf); // reading data form serial port
println!("Receiving bytes: {}", buf[0]); // print into ternimal
let mut letter = String::from_utf8_lossy(&buf); // convert to letter with following ASCII Table
println!("Receiving letter: {}", letter); // print letter for checking property working with serial port
}
}
I used other library than pervious library for reading non-standard baudrate serial port, because due irrcorrectly get bytes for pervious library. In this code, library of serial port get property bytes with following ASCII table.
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS cargo:rerun-if-env-changed=PKG_CONFIG_arm-unknown-linux-gnueabihf cargo:rerun-if-env-changed=PKG_CONFIG_arm_unknown_linux_gnueabihf cargo:rerun-if-env-changed=TARGET_PKG_CONFIG cargo:rerun-if-env-changed=PKG_CONFIG cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_arm-unknown-linux-gnueabihf cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_arm_unknown_linux_gnueabihf cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR --- stderr thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "pkg-config has not been configured to support cross-compilation.\n\n Install a sysroot for the target platform and configure it via\n PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a\n cross-compiling wrapper for pkg-config and set it via\n PKG_CONFIG environment variable."', /home/bestosinworldnot/.cargo/registry/src/github.com-1ecc6299db9ec823/libudev-sys-0.1.4/build.rs:38:41 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace warning: build failed, waiting for other jobs to finish... ^C Building [===========================================> ] 33/42 bestosinworldnot@oh-ohhh:~/Documents/readuart$ clear bestosinworldnot@oh-ohhh:~/Documents/readuart$ cargo build --target=arm-unknown-linux-gnueabihf Compiling libudev-sys v0.1.4 Compiling openssl-sys v0.9.58 error: failed to run custom build command for `libudev-sys v0.1.4` Caused by: process didn't exit successfully: `/home/bestosinworldnot/Documents/readuart/target/debug/build/libudev-sys-9a06bebd4dc364a9/build-script-build` (exit code: 101) --- stdout cargo:rerun-if-env-changed=LIBUDEV_NO_PKG_CONFIG cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_arm-unknown-linux-gnueabihf cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_arm_unknown_linux_gnueabihf cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS cargo:rerun-if-env-changed=PKG_CONFIG_arm-unknown-linux-gnueabihf cargo:rerun-if-env-changed=PKG_CONFIG_arm_unknown_linux_gnueabihf cargo:rerun-if-env-changed=TARGET_PKG_CONFIG cargo:rerun-if-env-changed=PKG_CONFIG cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_arm-unknown-linux-gnueabihf cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_arm_unknown_linux_gnueabihf cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR --- stderr thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "pkg-config has not been configured to support cross-compilation.\n\n Install a sysroot for the target platform and configure it via\n PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a\n cross-compiling wrapper for pkg-config and set it via\n PKG_CONFIG environment variable."', /home/bestosinworldnot/.cargo/registry/src/github.com-1ecc6299db9ec823/libudev-sys-0.1.4/build.rs:38:41 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace warning: build failed, waiting for other jobs to finish... Building [===========================================> ] 33/42 ^C
Solution install libdev-dev:arm package .
move to ibus
we moved ibus no supprot of ibus now. in updates can be solved