File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -61,12 +61,20 @@ pub fn is_data_ready() -> bool {
6161}
6262
6363/// Write a byte to serial port (for stdout output)
64+ /// Has timeout to prevent hanging on hardware without COM1
6465pub fn write_serial ( byte : u8 ) {
6566 unsafe {
6667 let mut port_lsr = Port :: < u8 > :: new ( COM1 + 5 ) ;
67- // Wait for transmit buffer to be empty
68- while port_lsr. read ( ) & 0x20 == 0 { }
69- let mut port_data = Port :: < u8 > :: new ( COM1 ) ;
70- port_data. write ( byte) ;
68+ // Wait for transmit buffer to be empty (with timeout)
69+ let mut timeout = 10000u32 ;
70+ while port_lsr. read ( ) & 0x20 == 0 && timeout > 0 {
71+ timeout -= 1 ;
72+ }
73+ if timeout > 0 {
74+ let mut port_data = Port :: < u8 > :: new ( COM1 ) ;
75+ port_data. write ( byte) ;
76+ }
77+ // If timeout reached, silently skip (no COM1 available)
7178 }
7279}
80+
You can’t perform that action at this time.
0 commit comments