Very nice, thank you for the example code. I’d like to see an audio driver (like getting the ASIO QA401 driver running for current hardware). This could be a start.
The commands are hard-coded, no definition file? Some must be missing. How is the sample rate set, how to use the front panel I2S, how to read power stats, etc? There are 6 endpoints?
So far, got the relays clicking in Python, with this piece of code:
#!/usr/bin/env python3
import time # just for test
import struct
import libusb_package # pip install this, if missing
class Registers:
def __init__(self, interface):
self.endpoint_read = interface.endpoints()[0]
self.endpoint_write = interface.endpoints()[1]
def read(self, reg):
self.write(0x80 | reg, 0)
data = self.endpoint_read.read(4)
(val,) = struct.unpack('>I', data)
return val
def write(self, reg, val):
buf = struct.pack('>BI', reg, val)
self.endpoint_write.write(buf)
class Levels:
def __init__(self, registers):
self.registers = registers
self.input2reg = {0: 0, 6: 1, 12: 2, 18: 3, 24: 4, 30: 5, 36: 6, 42: 7}
self.output2reg = {-12: 0, -2: 1, 8: 2, 18: 3}
def set_input(self, gain):
val = self.input2reg[gain]
self.registers.write(5, val)
def set_output(self, gain):
val = self.output2reg[gain]
self.registers.write(6, val)
def main():
device = libusb_package.find(idVendor=0x16c0, idProduct=0x4e37) # QA402
if device is None:
device = libusb_package.find(idVendor=0x16c0, idProduct=0x4e39) # QA403
if device is None:
raise SystemExit("no analyzer found")
device.set_configuration() # first one
interface = device[0].interfaces()[0]
registers = Registers(interface) # create register object
print(registers.read(0))
registers.write(0, 1234) # register test
print(registers.read(0))
levels = Levels(registers) # create level setting object
for level in range(0, 42+1, 6): # test all input levels
levels.set_input(level)
time.sleep(1)
for level in range(-12, 18+1, 10): # test all output levels
levels.set_output(level)
time.sleep(1)
if (__name__ == "__main__"):
main()
Now need to learn how to do asynchronous USB transfer in Python…
(Python was just for a quick start)