Skip to content

Commit d295c90

Browse files
Update lower level hardware interface (OpenwaterHealth#75)
* updates to test multiple modules * remove upper limit on identifier * update watertank testing script * updates for testing functionality * update to allow putting either device in test mode * added get and set fan speed * added status and RGB functionality * removed unecessary address * fixed txdevice ping * update test scripts * updates to test multiple modules * remove upper limit on identifier * update watertank testing script * update to allow putting either device in test mode * updates for testing functionality * added get and set fan speed * added status and RGB functionality * removed unecessary address * fixed txdevice ping * update test scripts * Remove spurious empty file * remove empty file --------- Co-authored-by: Ebrahim Ebrahim <ebrahim.ebrahim@kitware.com>
1 parent 3a78135 commit d295c90

21 files changed

Lines changed: 3631 additions & 70 deletions

notebooks/OpenLIFU_2x_1.json

Lines changed: 1931 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/pinmap.json

Lines changed: 969 additions & 0 deletions
Large diffs are not rendered by default.

notebooks/run_self_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
3. Test Device functionality.
1212
"""
1313
print("Starting LIFU Test Script...")
14-
interface = LIFUInterface(test_mode=False)
14+
interface = LIFUInterface()
1515
tx_connected, hv_connected = interface.is_device_connected()
1616
if tx_connected and hv_connected:
1717
print("LIFU Device Fully connected.")

notebooks/stress_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def run_test(interface, iterations):
8686

8787
if __name__ == "__main__":
8888
print("Starting LIFU Test Script...")
89-
interface = LIFUInterface(test_mode=False)
89+
interface = LIFUInterface()
9090

9191
# Number of iterations to run
9292
test_iterations = 1000 # Change this to the desired number of iterations

notebooks/test_console.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
5+
import base58
6+
7+
from openlifu.io.LIFUInterface import LIFUInterface
8+
9+
# set PYTHONPATH=%cd%\src;%PYTHONPATH%
10+
# python notebooks/test_console.py
11+
"""
12+
Test script to automate:
13+
1. Connect to the device.
14+
2. Test HVController: Turn HV on/off and check voltage.
15+
3. Test Device functionality.
16+
"""
17+
print("Starting LIFU Test Script...")
18+
interface = LIFUInterface(TX_test_mode=False)
19+
tx_connected, hv_connected = interface.is_device_connected()
20+
if tx_connected and hv_connected:
21+
print("LIFU Device Fully connected.")
22+
else:
23+
print(f'LIFU Device NOT Fully Connected. TX: {tx_connected}, HV: {hv_connected}')
24+
25+
if not hv_connected:
26+
print("HV Controller not connected.")
27+
sys.exit()
28+
29+
print("Ping the device")
30+
interface.hvcontroller.ping()
31+
32+
print("Toggle LED")
33+
interface.hvcontroller.toggle_led()
34+
35+
print("Get Version")
36+
version = interface.hvcontroller.get_version()
37+
print(f"Version: {version}")
38+
39+
print("Echo Data")
40+
echo, echo_len = interface.hvcontroller.echo(echo_data=b'Hello LIFU!')
41+
if echo_len > 0:
42+
print(f"Echo: {echo.decode('utf-8')}") # Echo: Hello LIFU!
43+
else:
44+
print("Echo failed.")
45+
46+
print("Get HW ID")
47+
hw_id = interface.hvcontroller.get_hardware_id()
48+
print(f"HW ID: {hw_id}")
49+
encoded_id = base58.b58encode(bytes.fromhex(hw_id)).decode()
50+
print(f"OW-LIFU-CON-{encoded_id}")
51+
52+
print("Get Temperature1")
53+
temp1 = interface.hvcontroller.get_temperature1()
54+
print(f"Temperature1: {temp1}")
55+
56+
print("Get Temperature2")
57+
temp2 = interface.hvcontroller.get_temperature2()
58+
print(f"Temperature2: {temp2}")
59+
60+
print("Set Bottom Fan Speed to 20%")
61+
btfan_speed = interface.hvcontroller.set_fan_speed(fan_id=0, fan_speed=20)
62+
print(f"Bottom Fan Speed: {btfan_speed}")
63+
64+
print("Set Top Fan Speed to 40%")
65+
tpfan_speed = interface.hvcontroller.set_fan_speed(fan_id=1, fan_speed=40)
66+
print(f"Bottom Fan Speed: {tpfan_speed}")
67+
68+
print("Get Bottom Fan Speed")
69+
btfan_speed = interface.hvcontroller.get_fan_speed(fan_id=0)
70+
print(f"Bottom Fan Speed: {btfan_speed}")
71+
72+
print("Get Top Fan Speed")
73+
tpfan_speed = interface.hvcontroller.get_fan_speed(fan_id=1)
74+
print(f"Bottom Fan Speed: {tpfan_speed}")
75+
76+
print("Set RGB LED")
77+
rgb_led = interface.hvcontroller.set_rgb_led(rgb_state=2)
78+
print(f"RGB STATE: {rgb_led}")
79+
80+
print("Get RGB LED")
81+
rgb_led_state = interface.hvcontroller.get_rgb_led()
82+
print(f"RGB STATE: {rgb_led_state}")
83+
84+
print("Test 12V...")
85+
if interface.hvcontroller.turn_12v_on():
86+
print("12V ON Press enter to TURN OFF:")
87+
input() # Wait for the user to press Enter
88+
if interface.hvcontroller.turn_12v_off():
89+
print("12V OFF.")
90+
else:
91+
print("Failed to turn off 12V")
92+
else:
93+
print("Failed to turn on 12V.")
94+
95+
# Set High Voltage Level
96+
print("Set HV Power to +/- 12V")
97+
if interface.hvcontroller.set_voltage(voltage=12.0):
98+
print("Voltage set to 12.0 V.")
99+
else:
100+
print("Failed to set voltage.")
101+
102+
# Get Set High Voltage Setting
103+
print("Get HV Setting")
104+
read_set_voltage = interface.hvcontroller.get_voltage()
105+
print(f"Voltage set to {read_set_voltage} V.")
106+
107+
108+
print("Test HV Supply...")
109+
if interface.hvcontroller.turn_hv_on():
110+
print("HV ON Press enter to TURN OFF:")
111+
input() # Wait for the user to press Enter
112+
if interface.hvcontroller.turn_hv_off():
113+
print("HV OFF.")
114+
else:
115+
print("Failed to turn off HV")
116+
else:
117+
print("Failed to turn on HV.")
118+
119+
print("Reset DevConsoleice:")
120+
# Ask the user for confirmation
121+
user_input = input("Do you want to reset the Console? (y/n): ").strip().lower()
122+
123+
if user_input == 'y':
124+
if interface.hvcontroller.soft_reset():
125+
print("Reset Successful.")
126+
elif user_input == 'n':
127+
print("Reset canceled.")
128+
else:
129+
print("Invalid input. Please enter 'y' or 'n'.")

notebooks/test_multiple_modules.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from __future__ import annotations
2+
3+
from openlifu.io.LIFUInterface import LIFUInterface
4+
5+
# set PYTHONPATH=%cd%\src;%PYTHONPATH%
6+
# python notebooks/test_multiple_modules.py
7+
"""
8+
Test script to automate:
9+
1. Connect to the device.
10+
2. Test HVController: Turn HV on/off and check voltage.
11+
3. Test Device functionality.
12+
"""
13+
print("Starting LIFU Test Script...")
14+
interface = LIFUInterface()
15+
tx_connected, hv_connected = interface.is_device_connected()
16+
if tx_connected and hv_connected:
17+
print("LIFU Device Fully connected.")
18+
else:
19+
print(f'LIFU Device NOT Fully Connected. TX: {tx_connected}, HV: {hv_connected}')
20+
21+
print("Ping the device")
22+
interface.txdevice.ping()
23+
24+
print("Enumerate TX7332 chips")
25+
num_tx_devices = interface.txdevice.enum_tx7332_devices()
26+
if num_tx_devices > 0:
27+
print(f"Number of TX7332 devices found: {num_tx_devices}")
28+
29+
print("Write Demo Registers to TX7332 chips")
30+
for device_index in range(num_tx_devices):
31+
interface.txdevice.demo_tx7332(device_index)
32+
33+
print("Starting Trigger...")
34+
if interface.txdevice.start_trigger():
35+
print("Trigger Running Press enter to STOP:")
36+
input() # Wait for the user to press Enter
37+
if interface.txdevice.stop_trigger():
38+
print("Trigger stopped successfully.")
39+
else:
40+
print("Failed to stop trigger.")
41+
else:
42+
print("Failed to start trigger.")
43+
44+
else:
45+
raise Exception("No TX7332 devices found.")

notebooks/test_nucleo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
3. Test Device functionality.
1212
"""
1313
print("Starting LIFU Test Script...")
14-
interface = LIFUInterface(test_mode=False, run_async=False)
14+
interface = LIFUInterface()
1515
tx_connected, hv_connected = interface.is_device_connected()
1616
if tx_connected and hv_connected:
1717
print("LIFU Device Fully connected.")

notebooks/test_reset.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from __future__ import annotations
2+
3+
from openlifu.io.LIFUInterface import LIFUInterface
4+
5+
# set PYTHONPATH=%cd%\src;%PYTHONPATH%
6+
# python notebooks/test_reset.py
7+
8+
print("Starting LIFU Test Script...")
9+
interface = LIFUInterface()
10+
tx_connected, hv_connected = interface.is_device_connected()
11+
if tx_connected and hv_connected:
12+
print("LIFU Device Fully connected.")
13+
else:
14+
print(f'LIFU Device NOT Fully Connected. TX: {tx_connected}, HV: {hv_connected}')
15+
16+
print("Reset Device:")
17+
# Ask the user for confirmation
18+
user_input = input("Do you want to reset the device? (y/n): ").strip().lower()
19+
20+
if user_input == 'y':
21+
if interface.txdevice.soft_reset():
22+
print("Reset Successful.")
23+
elif user_input == 'n':
24+
print("Reset canceled.")
25+
else:
26+
print("Invalid input. Please enter 'y' or 'n'.")

notebooks/test_solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
solution
4747

48-
ifx = openlifu.LIFUInterface(test_mode=True)
48+
ifx = openlifu.LIFUInterface()
4949

5050
ifx.set_solution(solution.to_dict())
5151

notebooks/test_temp.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from __future__ import annotations
2+
3+
import asyncio
4+
import struct
5+
import time
6+
7+
from openlifu.io.core import UART, UartPacket
8+
from openlifu.io.ctrl_if import CTRL_IF
9+
from openlifu.io.utils import format_and_print_hex, list_vcp_with_vid_pid
10+
11+
12+
async def main():
13+
# Select communication port
14+
15+
# s = UART('COM9', timeout=5)
16+
# s = UART('COM31', timeout=5)
17+
#s = UART('COM16', timeout=5)
18+
CTRL_BOARD = True # change to false and specify PORT_NAME for Nucleo Board
19+
PORT_NAME = "COM16"
20+
s = None
21+
22+
if CTRL_BOARD:
23+
vid = 0x483 # Example VID for demonstration
24+
pid = 0x57AF # Example PID for demonstration
25+
26+
com_port = list_vcp_with_vid_pid(vid, pid)
27+
if com_port is None:
28+
print("No device found")
29+
else:
30+
print("Device found at port: ", com_port)
31+
# Select communication port
32+
s = UART(com_port, timeout=5)
33+
else:
34+
s = UART(PORT_NAME, timeout=5)
35+
36+
# Initialize the USTx controller object
37+
ustx_ctrl = CTRL_IF(s)
38+
39+
print("Test PING")
40+
r = await ustx_ctrl.ping()
41+
format_and_print_hex(r)
42+
43+
print("Get Temperature")
44+
for _ in range(10): # Loop 10 times
45+
r = await ustx_ctrl.get_temperature()
46+
packet = UartPacket(buffer=r)
47+
if packet.data_len == 4:
48+
try:
49+
temperature = struct.unpack('<f', packet.data)[0]
50+
print(" Temperature (°C):", f"{temperature:.2f}")
51+
except Exception as e:
52+
print(" Error decoding float:", str(e))
53+
time.sleep(1) # Sleep for 1 second
54+
55+
s.close()
56+
57+
# Entry point
58+
if __name__ == "__main__":
59+
asyncio.run(main())

0 commit comments

Comments
 (0)