diff --git a/gex/Client.py b/gex/Client.py index 85d12fe..cedaafd 100644 --- a/gex/Client.py +++ b/gex/Client.py @@ -48,7 +48,8 @@ class Client: pld_as_s = msg.data.decode('utf-8') except UnicodeDecodeError: pld_as_s = str(msg.data) - raise Exception("UNHANDLED MESSAGE! %s" % pld_as_s) + # raise Exception("UNHANDLED MESSAGE! %s, type %d, id %04x" % (' '.join([("%02x"%b) for b in msg.data]), msg.type, msg.id)) + print("UNHANDLED MESSAGE! %s, type %d, id %04x" % (' '.join([("%02x" % b) for b in msg.data]), msg.type, msg.id)) self.tf.add_fallback_listener(fallback_lst) diff --git a/gex/TinyFrame.py b/gex/TinyFrame.py index f7c31e7..9939424 100644 --- a/gex/TinyFrame.py +++ b/gex/TinyFrame.py @@ -142,6 +142,8 @@ class TinyFrame: if listener is not None: self.add_id_listener(id, listener) + print("Tx: " + ' '.join(["%02x"%b for b in buf])) + print(" " + ''.join(["%c"% (b if b>=32 and b<127 else ord('.')) for b in buf])) self.write(buf) return id @@ -187,6 +189,9 @@ class TinyFrame: """ Parse bytes received on the serial port """ + print("Rx: " + ' '.join(["%02x"%b for b in bytes])) + print(" " + ''.join(["%c"% (b if b>=32 and b<127 else ord('.')) for b in bytes])) + for b in bytes: self.accept_byte(b) @@ -233,6 +238,7 @@ class TinyFrame: if len(self.rbuf) == self.rlen: self.rf.len = self._unpack(self.rbuf) + print("Len=%d"%self.rf.len) self.ps = 'TYPE' self.rlen = self.TYPE_BYTES diff --git a/gex/transport.py b/gex/transport.py index d40d893..c4c09a6 100644 --- a/gex/transport.py +++ b/gex/transport.py @@ -150,6 +150,7 @@ class TrxRawUSB (BaseGexTransport): detach_kernel_driver(dev, 2) # CDC data detach_kernel_driver(dev, 3) # CDC control + detach_kernel_driver(dev, 4) # CDC data2 # Set default configuration # (this will fail if we don't have the right permissions) @@ -188,7 +189,7 @@ class TrxRawUSB (BaseGexTransport): def write(self, buffer): """ Send a buffer of bytes """ - self._dev.write(0x02, buffer, 100) + self._dev.write(0x04, buffer, 100) def poll(self, timeout, testfunc=None): # Using time.sleep() would block for too long. Instead we release the semaphore on each Rx chunk of data diff --git a/test_adc.py b/test_adc.py index f5dcf6d..c09d050 100644 --- a/test_adc.py +++ b/test_adc.py @@ -11,10 +11,10 @@ with gex.Client(gex.TrxRawUSB()) as client: adc = gex.ADC(client, 'a') adc.set_active_channels([3]) - rate=44000 + rate=20000 fs = adc.set_sample_rate(rate) - count = 44000*2 + count = 1000 data = np.add(adc.capture(count) / 4096, -0.5) if data is not None: diff --git a/test_core.py b/test_core.py new file mode 100644 index 0000000..7b0520a --- /dev/null +++ b/test_core.py @@ -0,0 +1,9 @@ +#!/bin/env python3 +import time + +import gex + +with gex.Client(gex.TrxRawUSB()) as client: + time.sleep(3) + print("End") +