diff --git a/src/serial.rs b/src/serial.rs index 3ed01a3..fee3279 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -65,8 +65,9 @@ impl SerialInterface { } pub fn recv_bytes(&mut self) -> Result> { - let mut buffer: Vec = Vec::new(); - self.interface.read_to_end(&mut buffer); + let available_bytes = self.interface.bytes_to_read()?.try_into()?; + let mut buffer: Vec = vec![0; available_bytes]; + self.interface.read(&mut buffer)?; let improv_packet_offset = find_begin_of_improv_packet(&buffer).unwrap();