doublebuf .. bad

doublebuf
Ondřej Hruška 7 years ago
parent f3920743aa
commit bb8d3d29bf
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 3
      gex/Client.py
  2. 6
      gex/TinyFrame.py
  3. 3
      gex/transport.py
  4. 4
      test_adc.py
  5. 9
      test_core.py

@ -48,7 +48,8 @@ class Client:
pld_as_s = msg.data.decode('utf-8') pld_as_s = msg.data.decode('utf-8')
except UnicodeDecodeError: except UnicodeDecodeError:
pld_as_s = str(msg.data) 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) self.tf.add_fallback_listener(fallback_lst)

@ -142,6 +142,8 @@ class TinyFrame:
if listener is not None: if listener is not None:
self.add_id_listener(id, listener) 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) self.write(buf)
return id return id
@ -187,6 +189,9 @@ class TinyFrame:
""" """
Parse bytes received on the serial port 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: for b in bytes:
self.accept_byte(b) self.accept_byte(b)
@ -233,6 +238,7 @@ class TinyFrame:
if len(self.rbuf) == self.rlen: if len(self.rbuf) == self.rlen:
self.rf.len = self._unpack(self.rbuf) self.rf.len = self._unpack(self.rbuf)
print("Len=%d"%self.rf.len)
self.ps = 'TYPE' self.ps = 'TYPE'
self.rlen = self.TYPE_BYTES self.rlen = self.TYPE_BYTES

@ -150,6 +150,7 @@ class TrxRawUSB (BaseGexTransport):
detach_kernel_driver(dev, 2) # CDC data detach_kernel_driver(dev, 2) # CDC data
detach_kernel_driver(dev, 3) # CDC control detach_kernel_driver(dev, 3) # CDC control
detach_kernel_driver(dev, 4) # CDC data2
# Set default configuration # Set default configuration
# (this will fail if we don't have the right permissions) # (this will fail if we don't have the right permissions)
@ -188,7 +189,7 @@ class TrxRawUSB (BaseGexTransport):
def write(self, buffer): def write(self, buffer):
""" Send a buffer of bytes """ """ Send a buffer of bytes """
self._dev.write(0x02, buffer, 100) self._dev.write(0x04, buffer, 100)
def poll(self, timeout, testfunc=None): 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 # Using time.sleep() would block for too long. Instead we release the semaphore on each Rx chunk of data

@ -11,10 +11,10 @@ with gex.Client(gex.TrxRawUSB()) as client:
adc = gex.ADC(client, 'a') adc = gex.ADC(client, 'a')
adc.set_active_channels([3]) adc.set_active_channels([3])
rate=44000 rate=20000
fs = adc.set_sample_rate(rate) fs = adc.set_sample_rate(rate)
count = 44000*2 count = 1000
data = np.add(adc.capture(count) / 4096, -0.5) data = np.add(adc.capture(count) / 4096, -0.5)
if data is not None: if data is not None:

@ -0,0 +1,9 @@
#!/bin/env python3
import time
import gex
with gex.Client(gex.TrxRawUSB()) as client:
time.sleep(3)
print("End")
Loading…
Cancel
Save