Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 29 additions & 0 deletions DOA3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from tuning import Tuning
import usb.core
import usb.util
import time

# Find the USB device by Vendor ID (VID) and Product ID (PID)
dev = usb.core.find(idVendor=0x2886, idProduct=0x0018)

if dev:
# Initialize the Tuning object
mic_tuning = Tuning(dev)

# Print the initial direction
print(f"Initial Direction: {mic_tuning.direction}")

# Main loop to continuously print the direction
while True:
try:
# Python 3 print function syntax
print(f"Current Direction: {mic_tuning.direction}")
time.sleep(1)

# Updated exception handling (Python 3 requires 'as e' for accessing the exception object)
except KeyboardInterrupt:
print("\nExiting loop...")
break

else:
print("Error: USB device (VID=0x2886, PID=0x0018) not found.")
4 changes: 3 additions & 1 deletion tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def read(self, name):
usb.util.CTRL_IN | usb.util.CTRL_TYPE_VENDOR | usb.util.CTRL_RECIPIENT_DEVICE,
0, cmd, id, length, self.TIMEOUT)

response = struct.unpack(b'ii', response.tostring())
# response = struct.unpack(b'ii', response.tostring())
# New Python 3 code
response = struct.unpack(b'ii', response.tobytes())

if data[2] == 'int':
result = response[0]
Expand Down