From b3b7a4ea27ae6c716d612ffee54c2fd3754e6720 Mon Sep 17 00:00:00 2001 From: clerie Date: Mon, 23 Dec 2024 17:14:11 +0100 Subject: [PATCH] Read all available bytes --- src/serial.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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();