|
NetBurner 3.5.7
PDF Version |
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) | |
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
| usb_throughput_test.close_port_cleanly | ( | ser, | |
| port_name ) |
Close serial port cleanly to allow reopening
| usb_throughput_test.create_test_pattern | ( | size | ) |
Create a test pattern buffer
| usb_throughput_test.is_port_available | ( | ser | ) |
Check if serial port is still available
| usb_throughput_test.list_com_ports | ( | ) |
List available COM ports
| usb_throughput_test.open_port_with_timeout | ( | port, | |
| timeout = 5, | |||
| retry = True ) |
Try to open serial port with timeout to handle stuck CDC driver
| usb_throughput_test.print_results | ( | stats, | |
| test_name ) |
Print final test results
| usb_throughput_test.run_bidir_test | ( | ser, | |
| duration ) |
Bidirectional Test: Simultaneous TX and RX Uses single-threaded interleaved approach for reliability on Windows.
| 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.
| 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.
| 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.
| usb_throughput_test.run_tx_test | ( | ser, | |
| duration ) |
TX Test: PC sends data to device Device should be in 'rx' mode
| 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.
| usb_throughput_test.safe_read | ( | ser, | |
| size, | |||
| timeout = 0.1 ) |
Safe read with error handling
| usb_throughput_test.safe_write | ( | ser, | |
| data ) |
Safe write with error handling
| usb_throughput_test.tx_thread_func | ( | ser, | |
| stats, | |||
| duration, | |||
| stop_event ) |
TX thread - sends data as fast as possible
| usb_throughput_test.wait_for_device | ( | port, | |
| timeout = 10 ) |
Wait for device to reconnect after crash/reset