diff --git a/DOA3.py b/DOA3.py new file mode 100644 index 0000000..125f687 --- /dev/null +++ b/DOA3.py @@ -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.") \ No newline at end of file diff --git a/tuning.py b/tuning.py index 0272329..f1dbf7b 100755 --- a/tuning.py +++ b/tuning.py @@ -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]