1414To start the terminal clients should call the "run" function, this is the entry point to the module.
1515"""
1616
17+ import codecs
18+ import typing
1719from typing import Any
1820
1921from serial import Serial
2022from serial .tools .miniterm import Miniterm
23+ from typing_extensions import override
2124
2225
2326def run (port : str , baud : int , echo : bool = True ) -> None :
@@ -31,7 +34,7 @@ def run(port: str, baud: int, echo: bool = True) -> None:
3134 baud: Serial baud rate.
3235 echo: Echo user input back to the console.
3336 """
34- term = SerialTerminal (Serial (port = port , baudrate = str ( baud ) ), echo = echo )
37+ term = SerialTerminal (Serial (port = port , baudrate = baud ), echo = echo )
3538 term .start ()
3639
3740 try :
@@ -55,21 +58,23 @@ class SerialTerminal(Miniterm):
5558 def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
5659 """Set the rx/tx encoding and special characters."""
5760 super ().__init__ (* args , ** kwargs )
58- self .exit_character = CTRL_C
59- self .menu_character = CTRL_T
60- self .reset_character = CTRL_B
61- self .help_character = CTRL_H
61+ self .exit_character : str = CTRL_C
62+ self .menu_character : str = CTRL_T
63+ self .reset_character : str = CTRL_B
64+ self .help_character : str = CTRL_H
6265 self .set_rx_encoding ("UTF-8" )
6366 self .set_tx_encoding ("UTF-8" )
6467
6568 def reset (self ) -> None :
6669 """Send a reset signal."""
67- self .serial .sendBreak ()
70+ self .serial .send_break ()
6871
72+ @override
6973 def get_help_text (self ) -> str :
7074 """Return the text displayed when the user requests help."""
7175 return HELP_TEXT
7276
77+ @override
7378 def writer (self ) -> None :
7479 """Implements terminal behaviour."""
7580 menu_active = False
@@ -79,6 +84,9 @@ def writer(self) -> None:
7984 except KeyboardInterrupt :
8085 input_key = self .exit_character
8186
87+ if input_key is None :
88+ continue
89+
8290 if (menu_active and input_key in VALID_MENU_KEYS ) or (input_key == self .help_character ):
8391 self .handle_menu_key (input_key )
8492 menu_active = False
@@ -103,7 +111,8 @@ def _write_transformed_char(self, text: str) -> None:
103111 for transformation in self .tx_transformations :
104112 text = transformation .tx (text )
105113
106- self .serial .write (self .tx_encoder .encode (text ))
114+ encoder = typing .cast (codecs .IncrementalEncoder , self .tx_encoder )
115+ _ = self .serial .write (encoder .encode (text ))
107116
108117 def _echo_transformed_char (self , text : str ) -> None :
109118 for transformation in self .tx_transformations :
0 commit comments