|
3 | 3 | from openlifu.io.LIFUInterface import LIFUInterface |
4 | 4 |
|
5 | 5 | # set PYTHONPATH=%cd%\src;%PYTHONPATH% |
6 | | -# python notebooks/test_multiple_modules.py |
| 6 | +# python examples\legacy\test_multiple_modules.py |
7 | 7 | """ |
8 | 8 | Test script to automate: |
9 | 9 | 1. Connect to the device. |
|
24 | 24 | print("Enumerate TX7332 chips") |
25 | 25 | num_tx_devices = interface.txdevice.enum_tx7332_devices() |
26 | 26 | if num_tx_devices > 0: |
| 27 | + |
27 | 28 | print(f"Number of TX7332 devices found: {num_tx_devices}") |
28 | 29 |
|
| 30 | + for tx_index in range(num_tx_devices): |
| 31 | + module_id = tx_index // 2 |
| 32 | + device_info = interface.txdevice.write_register(identifier=tx_index, address=0x20 + module_id, value=0x30 + tx_index) |
| 33 | + fill_value = 0x40 + tx_index |
| 34 | + interface.txdevice.write_block(identifier=tx_index, start_address=0x40, reg_values=[fill_value] * (0x50 - 0x40)) |
| 35 | + print(f"Wrote to TX{tx_index} (module {module_id}): reg 0x{0x20 + module_id:02X} = 0x{0x30 + tx_index:02X} and block 0x40-0x4F = 0x{fill_value:02X}") |
| 36 | + |
| 37 | + module_count = int(num_tx_devices/2) |
| 38 | + for module_index in range(module_count): |
| 39 | + |
| 40 | + ping_result = interface.txdevice.ping(module=module_index) |
| 41 | + print(f"Module {module_index} ping result: {ping_result}") |
| 42 | + |
| 43 | + version = interface.txdevice.get_version(module=module_index) |
| 44 | + print(f"Module {module_index} Version: {version}") |
| 45 | + |
| 46 | + hw_id = interface.txdevice.get_hardware_id(module=module_index) |
| 47 | + print(f"Module {module_index} HW ID: {hw_id}") |
| 48 | + |
| 49 | + echo_data, echo_len = interface.txdevice.echo(module=module_index, echo_data=b'The cat, a sleek silhouette with emerald eyes and whiskers like twin antennae, hopped onto the sunlit windowsill.') |
| 50 | + print(f"Module {module_index} Echo Test Returned: {echo_data} STATUS: {'PASS' if echo_data == b'The cat, a sleek silhouette with emerald eyes and whiskers like twin antennae, hopped onto the sunlit windowsill.' else 'FAIL'}") |
| 51 | + |
| 52 | + temp = interface.txdevice.get_temperature(module=module_index) |
| 53 | + print(f"Module {module_index} Temperature: {temp}") |
| 54 | + |
| 55 | + ambient = interface.txdevice.get_ambient_temperature(module=module_index) |
| 56 | + print(f"Module {module_index} Ambient Temperature: {ambient}") |
| 57 | + |
| 58 | + config = interface.txdevice.read_config(module=module_index) |
| 59 | + print(f"Module {module_index} Config (read): {config.get_json_str() if config else None}") |
| 60 | + if config is not None: |
| 61 | + config.json_data['module_id'] = module_index |
| 62 | + updated_config = interface.txdevice.write_config(config, module=module_index) |
| 63 | + print(f"Module {module_index} Config (write): {updated_config.get_json_str() if updated_config else None}") |
| 64 | + |
| 65 | + for local_tx in range(2): |
| 66 | + tx_index = module_index * 2 + local_tx |
| 67 | + expected_reg = 0x30 + tx_index |
| 68 | + value = interface.txdevice.read_register(identifier=tx_index, address=0x20 + module_index) |
| 69 | + status = 'PASS' if value == expected_reg else 'FAIL' |
| 70 | + print(f"Module {module_index} TX{local_tx} (global {tx_index}) reg 0x{0x20 + module_index:02X} = 0x{value:02X} (expected 0x{expected_reg:02X}) {status}") |
| 71 | + |
| 72 | + fill_value = 0x40 + tx_index |
| 73 | + block_count = 0x50 - 0x40 |
| 74 | + read_values = interface.txdevice.read_block(identifier=tx_index, start_address=0x40, count=block_count) |
| 75 | + if read_values is None: |
| 76 | + print(f"Module {module_index} TX{local_tx} (global {tx_index}) read_block FAIL (no response)") |
| 77 | + else: |
| 78 | + mismatches = [(0x40 + i, v, fill_value) for i, v in enumerate(read_values) if v != fill_value] |
| 79 | + if mismatches: |
| 80 | + for addr, got, exp in mismatches: |
| 81 | + print(f"Module {module_index} TX{local_tx} (global {tx_index}) reg 0x{addr:02X} = 0x{got:02X} (expected 0x{exp:02X}) FAIL") |
| 82 | + else: |
| 83 | + print(f"Module {module_index} TX{local_tx} (global {tx_index}) write_block/read_block 0x40-0x4F value=0x{fill_value:02X} PASS") |
| 84 | + |
| 85 | + """ |
29 | 86 | print("Write Demo Registers to TX7332 chips") |
30 | 87 | for device_index in range(num_tx_devices): |
31 | 88 | interface.txdevice.demo_tx7332(device_index) |
|
40 | 97 | print("Failed to stop trigger.") |
41 | 98 | else: |
42 | 99 | print("Failed to start trigger.") |
43 | | - |
| 100 | + """ |
44 | 101 | else: |
45 | 102 | raise Exception("No TX7332 devices found.") |
0 commit comments