code: def write_rtt(jlink):
      
      try:
          while jlink.connected():
              bytes = list(bytearray(input(), "utf-8") + b"\x0A\x00")
              bytes_written = jlink.rtt_write(0, bytes)
      except Exception:
          print("IO write thread exception, exiting...")
          thread.interrupt_main()
          raise
docs: Writes kayboard input to JLink RTT buffer #0.
  
      This method is a loop that blocks waiting on stdin. When enter is pressed,
      LF and NUL bytes are added to the input and transmitted as a byte list.
      If the JLink is disconnected, it will exit gracefully. If any other
      exceptions are raised, they will be caught and re-raised after interrupting
      the main thread.
  
      Args:
        jlink (pylink.JLink): The JLink to write to.
  
      Raises:
        Exception on error.