65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to verify the integrated optimization system
|
|
"""
|
|
|
|
|
|
def test_optimization_integration():
|
|
print("🧪 Testing Batch Reading Optimization Integration")
|
|
print("=" * 60)
|
|
|
|
try:
|
|
# Test global configuration
|
|
from main import USE_OPTIMIZED_BATCH_READING
|
|
|
|
print(f"✅ Global optimization setting: {USE_OPTIMIZED_BATCH_READING}")
|
|
|
|
# Test PLC client with optimization
|
|
from core.plc_client import PLCClient, OPTIMIZED_BATCH_READER_AVAILABLE
|
|
|
|
print(f"✅ Optimization available: {OPTIMIZED_BATCH_READER_AVAILABLE}")
|
|
|
|
# Create PLC client instance
|
|
plc_client = PLCClient(logger=None)
|
|
print(f"✅ PLCClient created successfully")
|
|
print(f"✅ Batch reader initialized: {plc_client.batch_reader is not None}")
|
|
|
|
# Test batch reading stats
|
|
stats = plc_client.get_batch_reading_stats()
|
|
print(f"\n📊 Batch Reading Statistics:")
|
|
for key, value in stats.items():
|
|
print(f" • {key}: {value}")
|
|
|
|
# Test with sample configuration
|
|
sample_config = {
|
|
"test_var_1": {"area": "db", "db": 1, "offset": 0, "type": "real"},
|
|
"test_var_2": {"area": "db", "db": 1, "offset": 4, "type": "int"},
|
|
"test_var_3": {
|
|
"area": "db",
|
|
"db": 1,
|
|
"offset": 6,
|
|
"bit": 0,
|
|
"type": "bool",
|
|
},
|
|
}
|
|
|
|
print(f"\n🧪 Testing batch read with sample config (no PLC connection)...")
|
|
results = plc_client.read_variables_batch(sample_config)
|
|
print(f"✅ Batch read completed: {len(results)} results")
|
|
print(f" Results: {list(results.keys())}")
|
|
|
|
print(f"\n✅ All integration tests passed successfully!")
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Integration test failed: {e}")
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
success = test_optimization_integration()
|
|
exit(0 if success else 1)
|