Function robust_arduino_serial::read_i16
[−]
[src]
pub fn read_i16<T: Read>(file: &mut T) -> Result<i16, Error>
Read two bytes from a file/serial port and convert it to a 16 bits int
Example
use std::io::Cursor; use std::io::SeekFrom; use std::io::prelude::*; use robust_arduino_serial::*; let mut buffer = Cursor::new(Vec::new()); let number: i16 = -355; // Write the number to the buffer write_i16(&mut buffer, number).unwrap(); // Go to the beginning of the buffer buffer.seek(SeekFrom::Start(0)).unwrap(); // Read 16 bits (two bytes) from the buffer let read_number: i16 = robust_arduino_serial::read_i16(&mut buffer).unwrap(); assert_eq!(read_number, number);