Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5d423c4
sort pins and watertank improvements
peterhollender Jun 4, 2025
2ba1e9f
adjust pin ordering
peterhollender Jun 5, 2025
4f0d8d0
fix instantiation
peterhollender Jun 5, 2025
15346bb
update test_watertank
Jun 6, 2025
27bca09
update watertank
Jun 6, 2025
ac8b4ba
Remove console supply voltage check when using external supply before…
Jun 9, 2025
9f02f5b
WIP test update for element swaps
peterhollender Jun 13, 2025
29809d3
Fix logger message for log file output.
Jun 13, 2025
6bfe1b7
point dvc back to main
peterhollender Jun 17, 2025
60da3d4
add 2x400 evt1 with pin map
peterhollender Jun 17, 2025
b986004
Add 1x400 evt1
peterhollender Jun 17, 2025
51353be
pass trigger mode. Closes #349
peterhollender Jun 18, 2025
50cf67d
Merge George's changes
peterhollender Jun 23, 2025
56dd040
Update all mode parameters to be trigger_mode
Jun 23, 2025
ee6bd77
switch mode -> trigger_mode in rest of places
peterhollender Jun 23, 2025
0b0e39f
Change max sequence time to 20 mins, default pulse width from 20ms to…
Jun 24, 2025
ac43cc5
Create status variable in class, update get_status(), create set_stat…
Jun 25, 2025
963de74
Add pulse length adjust
peterhollender Jun 25, 2025
8fa73b9
Remove duplicate TRIGGER_MODE_ definitations
peterhollender Jun 26, 2025
cdd1c08
Set status messages and add TODO's
Jun 29, 2025
1d96752
Change write block logging to debug, make exception more specific (py…
Jun 29, 2025
b282a3a
Change debug level to INFO in TXDevice, small logger info/debug switch
Jun 29, 2025
ae3edd7
added script async example
georgevigelette Jun 30, 2025
f6ae4dd
add async mode for update status messages
georgevigelette Jun 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Thumbs.db
*.swp
.vscode
/db_dvc
/logs

# ONNX checkpoints
*.onnx
5 changes: 2 additions & 3 deletions db_dvc.dvc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
outs:
- md5: 9fccb7e2954839d729ab3d0fa1abb580.dir
nfiles: 797
- md5: 696cd731bd5fadd19cc1fda1da602fb7.dir
nfiles: 802
hash: md5
path: db_dvc
size: 2357262767
110 changes: 110 additions & 0 deletions notebooks/test_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
from __future__ import annotations

import asyncio
import logging
import threading
import time

from openlifu.io.LIFUInterface import LIFUInterface

# set PYTHONPATH=%cd%\src;%PYTHONPATH%
# python notebooks/test_async.py

# Setup logging
logging.basicConfig(level=logging.INFO)

interface = None

# Callbacks
def on_connect(descriptor, port):
print(f"🔌 CONNECTED: {descriptor} on port {port}")

def on_disconnect(descriptor, port):
print(f"❌ DISCONNECTED: {descriptor} from port {port}")

def on_data_received(descriptor, packet):
print(f"📦 DATA [{descriptor}]: {packet}")

def monitor_interface():
"""Run the device monitor loop in a separate thread using asyncio."""
asyncio.run(interface.start_monitoring(interval=1))

def rebind_tx_callbacks():
"""Bind callbacks to the TX UART, if present."""
if interface.txdevice and interface.txdevice.uart:
interface.txdevice.uart.signal_connect.connect(on_connect)
interface.txdevice.uart.signal_disconnect.connect(on_disconnect)
interface.txdevice.uart.signal_data_received.connect(on_data_received)

def run_menu():
while True:
print("\n--- LIFU MENU ---")
print("1. Turn ON 12V")
print("2. Turn OFF 12V")
print("3. Ping TX")
print("4. Show Connection Status")
print("5. Exit")
choice = input("Enter choice: ").strip()

tx_connected, hv_connected = interface.is_device_connected()

if choice == "1":
if hv_connected:
print("⚡ Sending 12V ON...")
interface.hvcontroller.turn_12v_on()
time.sleep(2.0)
print("🔄 Reinitializing TX...")
rebind_tx_callbacks()
else:
print("⚠️ HV not connected.")

elif choice == "2":
if hv_connected:
print("🛑 Sending 12V OFF...")
interface.hvcontroller.turn_12v_off()
else:
print("⚠️ HV not connected.")

elif choice == "3":
if tx_connected:
print("📡 Sending PING to TX...")
resp = interface.txdevice.ping()
if resp:
print("✅ TX responded to PING.")
else:
print("❌ No response or error.")
else:
print("⚠️ TX not connected.")

elif choice == "4":
print("Status:")
print(f" TX: {'✅ Connected' if tx_connected else '❌ Not connected'}")
print(f" HV: {'✅ Connected' if hv_connected else '❌ Not connected'}")

elif choice == "5":
print("Exiting...")
interface.stop_monitoring()
break
else:
print("Invalid choice.")

if __name__ == "__main__":
interface = LIFUInterface(HV_test_mode=False, run_async=False)

# Bind callbacks for HV and (initially connected) TX
if interface.hvcontroller.uart:
interface.hvcontroller.uart.signal_connect.connect(on_connect)
interface.hvcontroller.uart.signal_disconnect.connect(on_disconnect)
interface.hvcontroller.uart.signal_data_received.connect(on_data_received)

rebind_tx_callbacks()

print("🔍 Starting LIFU monitoring...")
monitor_thread = threading.Thread(target=monitor_interface, daemon=True)
monitor_thread.start()

try:
run_menu()
except KeyboardInterrupt:
print("\n🛑 Stopped by user.")
interface.stop_monitoring()
68 changes: 68 additions & 0 deletions notebooks/test_async_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from __future__ import annotations

import sys
import time

from openlifu.io.LIFUInterface import LIFUInterface

# set PYTHONPATH=%cd%\src;%PYTHONPATH%
# python notebooks/test_async_mode.py

def main():
print("Starting LIFU Async Test Script...")
interface = LIFUInterface()
tx_connected, hv_connected = interface.is_device_connected()

if not tx_connected and not hv_connected:
print("✅ LIFU Console not connected.")
sys.exit(1)

if not tx_connected:
print("TX device not connected. Attempting to turn on 12V...")
interface.hvcontroller.turn_12v_on()
time.sleep(2)

interface.stop_monitoring()
del interface
time.sleep(3)

print("Reinitializing LIFU interface after powering 12V...")
interface = LIFUInterface()
tx_connected, hv_connected = interface.is_device_connected()

if tx_connected and hv_connected:
print("✅ LIFU Device fully connected.")
else:
print("❌ LIFU Device NOT fully connected.")
print(f" TX Connected: {tx_connected}")
print(f" HV Connected: {hv_connected}")
sys.exit(1)

print("Ping the device")
if not interface.txdevice.ping():
print("❌ Failed comms with txdevice.")
sys.exit(1)

version = interface.txdevice.get_version()
print(f"Version: {version}")

curr_mode = interface.txdevice.async_mode()
print(f"Current Async Mode: {curr_mode}")
time.sleep(1)
if curr_mode:
print("Async mode is already enabled.")
else:
print("Enabling Async Mode...")
interface.txdevice.async_mode(True)
time.sleep(1)
curr_mode = interface.txdevice.async_mode()
print(f"Async Mode Enabled: {curr_mode}")
time.sleep(1)
print("Disabling Async Mode...")
interface.txdevice.async_mode(False)
time.sleep(1)
curr_mode = interface.txdevice.async_mode()
print(f"Async Mode Enabled: {curr_mode}")

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion notebooks/test_console_dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from openlifu.io.LIFUInterface import LIFUInterface

# set PYTHONPATH=%cd%\src;%PYTHONPATH%
# python notebooks/test_update_firmware.py
# python notebooks/test_console_dfu.py
"""
Test script to automate:
1. Connect to the device.
Expand Down
2 changes: 1 addition & 1 deletion notebooks/test_thermal_stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def log_temperature():
delays = sol_dict['delays'],
apodizations= sol_dict['apodizations'],
sequence= sol_dict['sequence'],
mode="continuous",
trigger_mode="continuous",
profile_index=profile_index,
profile_increment=profile_increment
)
Expand Down
2 changes: 1 addition & 1 deletion notebooks/test_transmitter2.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
delays = sol_dict['delays'],
apodizations= sol_dict['apodizations'],
sequence= sol_dict['sequence'],
mode = "continuous",
trigger_mode = "continuous",
profile_index=profile_index,
profile_increment=profile_increment
)
Expand Down
53 changes: 47 additions & 6 deletions notebooks/test_tx_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import sys
import time

from openlifu.io.LIFUConfig import (
TRIGGER_MODE_SEQUENCE,
TRIGGER_MODE_SINGLE,
)
from openlifu.io.LIFUInterface import LIFUInterface

# set PYTHONPATH=%cd%\src;%PYTHONPATH%
Expand Down Expand Up @@ -62,19 +66,26 @@ def main():
print("❌ Failed comms with txdevice.")
sys.exit(1)

version = interface.txdevice.get_version()
print(f"Version: {version}")

while True:
params = get_user_input()
if params is None:
print("Exiting...")
if interface.txdevice.is_connected:
print("Disconnecting TX device...")
interface.txdevice.close()

break

json_trigger_data = {
"TriggerFrequencyHz": params["freq"],
"TriggerPulseCount": 1,
"TriggerPulseCount": 10,
"TriggerPulseWidthUsec": params["pulse_width"],
"TriggerPulseTrainInterval": 0,
"TriggerPulseTrainCount": 0,
"TriggerMode": 1,
"TriggerPulseTrainInterval": 300000,
"TriggerPulseTrainCount": 10,
"TriggerMode": TRIGGER_MODE_SEQUENCE, # Change to TRIGGER_MODE_CONTINUOUS or TRIGGER_MODE_SEQUENCE or TRIGGER_MODE_SINGLE as needed
"ProfileIndex": 0,
"ProfileIncrement": 0
}
Expand All @@ -87,8 +98,38 @@ def main():
print("Failed to set trigger setting.")
continue

if interface.txdevice.start_trigger():
print("Trigger Running. Press Enter to STOP:")
if trigger_setting["TriggerMode"] == TRIGGER_MODE_SINGLE:
print("Trigger Mode set to SINGLE. Press Enter to START:")
if interface.txdevice.start_trigger():
print("Trigger started successfully.")
else:
print("Failed to start trigger.")

elif trigger_setting["TriggerMode"] == TRIGGER_MODE_SEQUENCE:
print("Trigger Mode set to SEQUENCE")
if interface.txdevice.start_trigger():
print("Trigger started successfully.")
else:
print("Failed to start trigger.")
while True:
trigger_status = interface.txdevice.get_trigger_json()
if trigger_status is None:
print("Failed to get trigger status! Fatal Error.")
break

if trigger_status["TriggerStatus"] == "STOPPED":
print("Run Complete.")
break

time.sleep(.5)
else:
print("Trigger Running Continuous Mode. Press Enter to STOP:")

if interface.txdevice.start_trigger():
print("Trigger started successfully.")
else:
print("Failed to start trigger.")

input() # Wait for the user to press Enter
if interface.txdevice.stop_trigger():
print("Trigger stopped successfully.")
Expand Down
2 changes: 1 addition & 1 deletion notebooks/test_updated_if.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
delays = sol_dict['delays'],
apodizations= sol_dict['apodizations'],
sequence= sol_dict['sequence'],
mode = "continuous",
trigger_mode = "continuous",
profile_index=profile_index,
profile_increment=profile_increment
)
Expand Down
Loading
Loading