fc43fbe4b0
- Merged four separate hardware control projects into unified platform - Created unified requirements.txt with all dependencies - Added comprehensive .gitignore - Added project overview README Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
102 lines
3.8 KiB
Python
102 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script for horizontal mode control functionality.
|
|
"""
|
|
|
|
from tektronix_base import TektronixOscilloscopeBase
|
|
|
|
|
|
def main():
|
|
"""Test horizontal mode functions on oscilloscope at 192.168.10.105"""
|
|
|
|
scope_ip = "192.168.10.105"
|
|
|
|
print(f"Connecting to oscilloscope at {scope_ip}...")
|
|
|
|
scope = TektronixOscilloscopeBase(resource_name=scope_ip)
|
|
|
|
try:
|
|
# Connect to scope
|
|
scope.connect()
|
|
print(f"✓ Connected to {scope.identify()}\n")
|
|
|
|
# Get current horizontal settings
|
|
print("Getting current horizontal settings...")
|
|
current_record_length = scope.get_record_length()
|
|
current_sample_rate = scope.get_sample_rate()
|
|
current_time_scale = scope.get_time_scale()
|
|
print(f"✓ Current record length: {current_record_length} samples")
|
|
print(f"✓ Current sample rate: {current_sample_rate} S/s")
|
|
print(f"✓ Current time scale: {current_time_scale} s/div\n")
|
|
|
|
# Test setting record length
|
|
print("Testing record length changes:")
|
|
test_lengths = [1000, 10000, 100000]
|
|
for length in test_lengths:
|
|
print(f" Setting record length to {length}...")
|
|
scope.set_record_length(length)
|
|
actual_length = scope.get_record_length()
|
|
print(f" ✓ Actual record length: {actual_length}")
|
|
|
|
# Test setting sample rate
|
|
print("\nTesting sample rate changes:")
|
|
test_rates = [1e6, 10e6, 100e6] # 1 MS/s, 10 MS/s, 100 MS/s
|
|
for rate in test_rates:
|
|
print(f" Setting sample rate to {rate:.0f} S/s...")
|
|
scope.set_sample_rate(rate)
|
|
actual_rate = scope.get_sample_rate()
|
|
print(f" ✓ Actual sample rate: {actual_rate:.0f} S/s")
|
|
|
|
# Test setting time scale
|
|
print("\nTesting time scale changes:")
|
|
test_scales = [1e-6, 10e-6, 100e-6, 1e-3] # 1 µs/div, 10 µs/div, 100 µs/div, 1 ms/div
|
|
for scale in test_scales:
|
|
print(f" Setting time scale to {scale:.6f} s/div...")
|
|
scope.set_time_scale(scale)
|
|
actual_scale = scope.get_time_scale()
|
|
print(f" ✓ Actual time scale: {actual_scale:.6f} s/div")
|
|
|
|
# Restore original settings
|
|
print(f"\nRestoring original settings...")
|
|
scope.set_record_length(current_record_length)
|
|
scope.set_sample_rate(current_sample_rate)
|
|
scope.set_time_scale(current_time_scale)
|
|
print(f"✓ Restored record length: {scope.get_record_length()}")
|
|
print(f"✓ Restored sample rate: {scope.get_sample_rate()}")
|
|
print(f"✓ Restored time scale: {scope.get_time_scale()}")
|
|
|
|
# Test invalid inputs
|
|
print("\nTesting invalid record length (should raise ValueError)...")
|
|
try:
|
|
scope.set_record_length(-1)
|
|
print("✗ ERROR: Should have raised ValueError!")
|
|
except ValueError as e:
|
|
print(f"✓ Correctly raised ValueError: {e}")
|
|
|
|
print("\nTesting invalid sample rate (should raise ValueError)...")
|
|
try:
|
|
scope.set_sample_rate(0)
|
|
print("✗ ERROR: Should have raised ValueError!")
|
|
except ValueError as e:
|
|
print(f"✓ Correctly raised ValueError: {e}")
|
|
|
|
print("\nTesting invalid time scale (should raise ValueError)...")
|
|
try:
|
|
scope.set_time_scale(-1.0)
|
|
print("✗ ERROR: Should have raised ValueError!")
|
|
except ValueError as e:
|
|
print(f"✓ Correctly raised ValueError: {e}")
|
|
|
|
except Exception as e:
|
|
print(f"✗ Error: {type(e).__name__}: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
finally:
|
|
if scope.is_connected:
|
|
scope.disconnect()
|
|
print("\n✓ Disconnected from oscilloscope")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|