NetBurner 3.5.7
PDF Version
usb_throughput_test Namespace Reference

Classes

class  ThroughputStats
 

Functions

 list_com_ports ()
 
 create_test_pattern (size)
 
 is_port_available (ser)
 
 safe_read (ser, size, timeout=0.1)
 
 safe_write (ser, data)
 
 tx_thread_func (ser, stats, duration, stop_event)
 
 rx_thread_func (ser, stats, duration, stop_event, verify=False)
 
 run_tx_test (ser, duration)
 
 run_rx_test (ser, duration)
 
 run_loopback_test (ser, duration)
 
 run_bidir_test (ser, duration)
 
 print_results (stats, test_name)
 
 wait_for_device (port, timeout=10)
 
 close_port_cleanly (ser, port_name)
 
 open_port_with_timeout (port, timeout=5, retry=True)
 
 run_interactive_tests (ser, port_name)
 

Detailed Description

USB CDC Throughput Test Script for Windows 11

This script tests USB CDC throughput with a NetBurner SOMRT1061 device.
It supports multiple test modes and provides detailed statistics.

Requirements:
    pip install pyserial

Usage:
    python usb_throughput_test.py --port COM3 --test tx --duration 10
    python usb_throughput_test.py --port COM3 --test rx --duration 10
    python usb_throughput_test.py --port COM3 --test loopback --duration 10
    python usb_throughput_test.py --port COM3 --test bidir --duration 10

Author: NetBurner

Function Documentation

◆ close_port_cleanly()

usb_throughput_test.close_port_cleanly ( ser,
port_name )
Close serial port cleanly to allow reopening

◆ create_test_pattern()

usb_throughput_test.create_test_pattern ( size)
Create a test pattern buffer

◆ is_port_available()

usb_throughput_test.is_port_available ( ser)
Check if serial port is still available

◆ list_com_ports()

usb_throughput_test.list_com_ports ( )
List available COM ports

◆ open_port_with_timeout()

usb_throughput_test.open_port_with_timeout ( port,
timeout = 5,
retry = True )
Try to open serial port with timeout to handle stuck CDC driver

◆ print_results()

usb_throughput_test.print_results ( stats,
test_name )
Print final test results

◆ run_bidir_test()

usb_throughput_test.run_bidir_test ( ser,
duration )
Bidirectional Test: Simultaneous TX and RX

Uses single-threaded interleaved approach for reliability on Windows.

◆ run_interactive_tests()

usb_throughput_test.run_interactive_tests ( ser,
port_name )
Interactive test mode - keeps port open between tests.
This avoids the CDC driver bug that causes port open to hang.

◆ run_loopback_test()

usb_throughput_test.run_loopback_test ( ser,
duration )
Loopback Test: PC sends, device echoes back
Measures round-trip throughput

Key insight: On Windows, we need to be careful about concurrent 
read/write from different threads on the same serial port.

◆ run_rx_test()

usb_throughput_test.run_rx_test ( ser,
duration )
RX Test: Device sends data to PC
Device should be in 'tx' mode

Key insight: USB is host-initiated. We must read continuously
to keep the host polling the device's IN endpoint.

CRITICAL: Device will do USB reset after TX test, so we need
to handle the port disappearing.

◆ run_tx_test()

usb_throughput_test.run_tx_test ( ser,
duration )
TX Test: PC sends data to device
Device should be in 'rx' mode

◆ rx_thread_func()

usb_throughput_test.rx_thread_func ( ser,
stats,
duration,
stop_event,
verify = False )
RX thread - receives data as fast as possible.

NOTE: We cannot modify ser.timeout from a thread while main thread uses the port.
Instead, we use the existing timeout and poll in_waiting.

◆ safe_read()

usb_throughput_test.safe_read ( ser,
size,
timeout = 0.1 )
Safe read with error handling

◆ safe_write()

usb_throughput_test.safe_write ( ser,
data )
Safe write with error handling

◆ tx_thread_func()

usb_throughput_test.tx_thread_func ( ser,
stats,
duration,
stop_event )
TX thread - sends data as fast as possible

◆ wait_for_device()

usb_throughput_test.wait_for_device ( port,
timeout = 10 )
Wait for device to reconnect after crash/reset