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>
163 lines
6.3 KiB
Python
163 lines
6.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script for trigger control functionality.
|
|
"""
|
|
|
|
from tektronix_base import TektronixOscilloscopeBase
|
|
|
|
|
|
def main():
|
|
"""Test trigger 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 trigger settings
|
|
print("Getting current trigger settings...")
|
|
current_coupling = scope.get_trigger_coupling()
|
|
current_slope = scope.get_trigger_slope()
|
|
current_source = scope.get_trigger_source()
|
|
current_mode = scope.get_trigger_mode()
|
|
print(f"✓ Current trigger coupling: {current_coupling}")
|
|
print(f"✓ Current trigger slope: {current_slope}")
|
|
print(f"✓ Current trigger source: {current_source}")
|
|
print(f"✓ Current trigger mode: {current_mode}")
|
|
|
|
# Get trigger level for current source
|
|
# Extract channel number from source
|
|
if current_source.startswith('CH'):
|
|
channel = int(current_source[2])
|
|
current_level = scope.get_trigger_level(channel)
|
|
print(f"✓ Current trigger level for {current_source}: {current_level} V\n")
|
|
else:
|
|
current_level = 0.0
|
|
channel = 1
|
|
print(f" (Source is {current_source}, not a channel)\n")
|
|
|
|
# Test trigger coupling
|
|
print("Testing trigger coupling modes:")
|
|
test_couplings = ['DC', 'HFRej', 'LFRej', 'NOISErej']
|
|
for coupling in test_couplings:
|
|
print(f" Setting coupling to {coupling}...")
|
|
scope.set_trigger_coupling(coupling)
|
|
actual_coupling = scope.get_trigger_coupling()
|
|
print(f" ✓ Actual coupling: {actual_coupling}")
|
|
|
|
# Test trigger slope
|
|
print("\nTesting trigger slope modes:")
|
|
test_slopes = ['RISe', 'FALL', 'EITher']
|
|
for slope in test_slopes:
|
|
print(f" Setting slope to {slope}...")
|
|
scope.set_trigger_slope(slope)
|
|
actual_slope = scope.get_trigger_slope()
|
|
print(f" ✓ Actual slope: {actual_slope}")
|
|
|
|
# Test trigger source
|
|
print("\nTesting trigger source selection:")
|
|
test_sources = ['CH1', 'CH2', 'CH3', 'CH4']
|
|
for source in test_sources:
|
|
print(f" Setting source to {source}...")
|
|
scope.set_trigger_source(source)
|
|
actual_source = scope.get_trigger_source()
|
|
print(f" ✓ Actual source: {actual_source}")
|
|
|
|
# Test trigger source with integer
|
|
print("\nTesting trigger source with integer (2)...")
|
|
scope.set_trigger_source(2)
|
|
actual_source = scope.get_trigger_source()
|
|
print(f"✓ Actual source: {actual_source}")
|
|
|
|
# Test trigger level
|
|
print("\nTesting trigger level settings:")
|
|
test_levels = [0.0, 0.5, 1.0, -0.5, 2.5]
|
|
for level in test_levels:
|
|
print(f" Setting CH1 trigger level to {level} V...")
|
|
scope.set_trigger_level(1, level)
|
|
actual_level = scope.get_trigger_level(1)
|
|
print(f" ✓ Actual level: {actual_level} V")
|
|
|
|
# Test trigger level with channel string
|
|
print("\nTesting trigger level with channel string ('CH2')...")
|
|
scope.set_trigger_level('CH2', 1.5)
|
|
actual_level = scope.get_trigger_level('CH2')
|
|
print(f"✓ Actual level: {actual_level} V")
|
|
|
|
# Test trigger mode
|
|
print("\nTesting trigger modes:")
|
|
test_modes = ['AUTO', 'NORMal']
|
|
for mode in test_modes:
|
|
print(f" Setting trigger mode to {mode}...")
|
|
scope.set_trigger_mode(mode)
|
|
actual_mode = scope.get_trigger_mode()
|
|
print(f" ✓ Actual mode: {actual_mode}")
|
|
|
|
# Restore original settings
|
|
print(f"\nRestoring original trigger settings...")
|
|
scope.set_trigger_coupling(current_coupling)
|
|
scope.set_trigger_slope(current_slope)
|
|
scope.set_trigger_source(current_source)
|
|
scope.set_trigger_mode(current_mode)
|
|
if current_source.startswith('CH'):
|
|
scope.set_trigger_level(channel, current_level)
|
|
print(f"✓ Restored trigger coupling: {scope.get_trigger_coupling()}")
|
|
print(f"✓ Restored trigger slope: {scope.get_trigger_slope()}")
|
|
print(f"✓ Restored trigger source: {scope.get_trigger_source()}")
|
|
print(f"✓ Restored trigger mode: {scope.get_trigger_mode()}")
|
|
|
|
# Test invalid inputs
|
|
print("\nTesting invalid coupling (should raise ValueError)...")
|
|
try:
|
|
scope.set_trigger_coupling("INVALID")
|
|
print("✗ ERROR: Should have raised ValueError!")
|
|
except ValueError as e:
|
|
print(f"✓ Correctly raised ValueError: {e}")
|
|
|
|
print("\nTesting invalid slope (should raise ValueError)...")
|
|
try:
|
|
scope.set_trigger_slope("INVALID")
|
|
print("✗ ERROR: Should have raised ValueError!")
|
|
except ValueError as e:
|
|
print(f"✓ Correctly raised ValueError: {e}")
|
|
|
|
print("\nTesting invalid source (should raise ValueError)...")
|
|
try:
|
|
scope.set_trigger_source("CH5")
|
|
print("✗ ERROR: Should have raised ValueError!")
|
|
except ValueError as e:
|
|
print(f"✓ Correctly raised ValueError: {e}")
|
|
|
|
print("\nTesting invalid channel for trigger level (should raise ValueError)...")
|
|
try:
|
|
scope.set_trigger_level(5, 0.0)
|
|
print("✗ ERROR: Should have raised ValueError!")
|
|
except ValueError as e:
|
|
print(f"✓ Correctly raised ValueError: {e}")
|
|
|
|
print("\nTesting invalid trigger mode (should raise ValueError)...")
|
|
try:
|
|
scope.set_trigger_mode("INVALID")
|
|
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()
|