NetBurner 3.5.7
PDF Version
test_modbus_timing Namespace Reference

Functions

int crc16_modbus (bytes data)
 
bytes make_frame (bytes payload)
 
 send_frame (serial.Serial ser, bytes frame)
 
 send_bytes_with_delay (serial.Serial ser, bytes data, float delay_s)
 
 wait_inter_frame (float multiplier=5.0)
 
 print_test (str name, str description)
 
 test_valid_single_frame (serial.Serial ser)
 
 test_valid_back_to_back (serial.Serial ser)
 
 test_inter_char_violation_mid_frame (serial.Serial ser)
 
 test_inter_char_violation_near_end (serial.Serial ser)
 
 test_inter_char_borderline_under (serial.Serial ser)
 
 test_inter_char_borderline_over (serial.Serial ser)
 
 test_inter_frame_violation (serial.Serial ser)
 
 test_various_slave_addresses (serial.Serial ser)
 
 test_large_frame (serial.Serial ser)
 
 test_multiple_violations (serial.Serial ser)
 

Detailed Description

Modbus RTU Timing Test Script

Sends raw serial data to test the SerialReceiveModbus example's ability to
detect valid and invalid Modbus RTU timing. Connects via a USB-to-serial
adapter to the NetBurner device's UART0 (port 2) at 9600 baud, 8E1.

Tests cover:
  - Valid frames with tight inter-character timing
  - Inter-character violations (gap > 1.5 char times within a frame)
  - Inter-frame violations (gap < 3.5 char times between frames)
  - Borderline timing near the 1.5 char-time threshold

Usage:
    python test_modbus_timing.py COM3        # Windows
    python test_modbus_timing.py /dev/ttyUSB0  # Linux
    python test_modbus_timing.py COM3 3      # Run only test 3

Requires: pip install pyserial

Function Documentation

◆ crc16_modbus()

int test_modbus_timing.crc16_modbus ( bytes data)
Calculate Modbus RTU CRC-16.

◆ make_frame()

bytes test_modbus_timing.make_frame ( bytes payload)
Append Modbus CRC-16 to a payload.

◆ print_test()

test_modbus_timing.print_test ( str name,
str description )
Print test header.

◆ send_bytes_with_delay()

test_modbus_timing.send_bytes_with_delay ( serial.Serial ser,
bytes data,
float delay_s )
Send bytes one at a time with a fixed delay between each.

◆ send_frame()

test_modbus_timing.send_frame ( serial.Serial ser,
bytes frame )
Send a complete frame as a single write (tight inter-character timing).

◆ test_inter_char_borderline_over()

test_modbus_timing.test_inter_char_borderline_over ( serial.Serial ser)
Send bytes with gaps just OVER the 1.5 char-time limit.

◆ test_inter_char_borderline_under()

test_modbus_timing.test_inter_char_borderline_under ( serial.Serial ser)
Send bytes with gaps just UNDER the 1.5 char-time limit.

◆ test_inter_char_violation_mid_frame()

test_modbus_timing.test_inter_char_violation_mid_frame ( serial.Serial ser)
Send a frame with a deliberate inter-character gap violation mid-frame.

◆ test_inter_char_violation_near_end()

test_modbus_timing.test_inter_char_violation_near_end ( serial.Serial ser)
Send a frame with inter-character violation near the end (before CRC).

◆ test_inter_frame_violation()

test_modbus_timing.test_inter_frame_violation ( serial.Serial ser)
Send two frames with insufficient inter-frame silence.

◆ test_large_frame()

test_modbus_timing.test_large_frame ( serial.Serial ser)
Send a larger valid frame to test buffer handling.

◆ test_multiple_violations()

test_modbus_timing.test_multiple_violations ( serial.Serial ser)
Send a frame with multiple inter-character violations.

◆ test_valid_back_to_back()

test_modbus_timing.test_valid_back_to_back ( serial.Serial ser)
Send two valid frames with proper inter-frame silence.

◆ test_valid_single_frame()

test_modbus_timing.test_valid_single_frame ( serial.Serial ser)
Send a single valid Modbus RTU frame.

◆ test_various_slave_addresses()

test_modbus_timing.test_various_slave_addresses ( serial.Serial ser)
Send valid frames to different slave addresses.

◆ wait_inter_frame()

test_modbus_timing.wait_inter_frame ( float multiplier = 5.0)
Wait for a specified number of character times.