Understand Serial Objects

The Serial object is the main object that you will use for testing. This chapter will explain the basic concepts of the Serial object.

Note

This chapter is mainly for developers who want to understand the internal structure of the Serial object. If you are a user who just wants to use the Serial object, you can skip this chapter.

Serial

  • __init__()

    • decide port

      Support auto-detecting port by port location

    • _post_init()

      occupy ports globally. Used for preventing other tests from using the same port while auto-detecting ports.

    • _start()

      doing nothing

    • _finalize_init()

      doing nothing

    • start_redirect_thread()

      Start the redirect thread. Read data from the serial port and write it to the log file, optionally echoing it to the console.

  • close():

    • stop_redirect_thread()

      Stop the redirect thread.

    • close serial connection

    • release the occupied port globally

EspSerial (Inherited from Serial)

  • __init__()

    • _before_init_port() (newly added method before deciding port)

      • parent class _post_init()

    • decide port

      Support auto-detecting port by device MAC, or device target. (Espressif-chips only)

    • _post_init()

      • Call set_port_target_cache(), speed up auto-detection next time

      • erase flash if set erase_all, and not set flash_port

        since if flash_port is set, the “erase” and “flash”” process will be done earlier already.

      • parent class _post_init()

    • _start()

      Run esptool.hard_reset()

ArduinoSerial (Inherited from EspSerial)

  • __init__()

    • _start()

      Auto-flash the app if not skip_autoflash

IdfSerial (Inherited from EspSerial)

  • __init__()

    • _before_init_port()

      If flash_port is set differently from the port, the target chip will always be flashed with the given port(without the port-app cache)

      • Occupying the flash_port globally

      • erase flash if set erase_all

      • Flash the app if not set skip_autoflash

      • set_port_target_cache() for the flash port

      • set_port_app_cache() for the flash port

    • _post_init()

      • if set flash_port, do nothing

      • otherwise, check port-app cache, if the app has been flashed, skip the auto-flash process

      • Run parent _post_init()

    • _start()

      • if the target has been flashed while _before_init_port(), set the port-app cache with the port and app and do nothing

      • otherwise, run flash() automatically the app if not set skip_autoflash

      • Run parent _start()

  • flash()

    • flash the app

    • set_port_app_cache() for the flash port

  • close()

    • release the occupied flash port globally

    • Run parent close()