Function robust_arduino_serial::read_i32 [] [src]

pub fn read_i32<T: Read>(file: &mut T) -> Result<i32, Error>

Read four bytes from a file/serial port and convert it to a 32 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 big_number: i32 = 16384; // 2^14

// Write the number to the buffer
write_i32(&mut buffer, big_number);

// Go to the beginning of the buffer
buffer.seek(SeekFrom::Start(0)).unwrap();

// Read 32 bits (four bytes) from the buffer
let read_number: i32 = robust_arduino_serial::read_i32(&mut buffer).unwrap();

assert_eq!(big_number, read_number);