some adc improvements and testing stuff w pyplot

doublebuf
Ondřej Hruška 7 years ago
parent edf1853f6c
commit cfbb29c55e
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 7
      gex/Client.py
  2. 7
      gex/units/ADC.py
  3. 76
      main.py

@ -44,7 +44,12 @@ class Client:
# fallback error listener # fallback error listener
def fallback_lst(tf :TinyFrame, msg :TF_Msg): def fallback_lst(tf :TinyFrame, msg :TF_Msg):
raise Exception("UNHANDLED MESSAGE! %s" % msg.data.decode('utf-8')) try:
pld_as_s = msg.data.decode('utf-8')
except UnicodeDecodeError:
pld_as_s = str(msg.data)
raise Exception("UNHANDLED MESSAGE! %s" % pld_as_s)
self.tf.add_fallback_listener(fallback_lst) self.tf.add_fallback_listener(fallback_lst)
self.unit_lu = {} self.unit_lu = {}

@ -1,5 +1,7 @@
import array import array
import time
import gex import gex
from gex import TF, TF_Msg from gex import TF, TF_Msg
from gex.Client import EventReport from gex.Client import EventReport
@ -379,10 +381,11 @@ class ADC(gex.Unit):
self._query_async(cmd=CMD_STREAM_START, callback=self._on_stream_capt) self._query_async(cmd=CMD_STREAM_START, callback=self._on_stream_capt)
def stream_stop(self, confirm=True): def stream_stop(self, delay=0.1, confirm=True):
""" Stop a stream """ """ Stop a stream """
if not self._stream_running: if not self._stream_running:
raise Exception("Not streaming") raise Exception("Not streaming")
self._stream_listener = None
self._send(cmd=CMD_STREAM_STOP, confirm=confirm) self._send(cmd=CMD_STREAM_STOP, confirm=confirm)
time.sleep(delay)
self._stream_listener = None

@ -1,5 +1,8 @@
#!/bin/env python3 #!/bin/env python3
import time import time
from matplotlib import pyplot as plt
import gex import gex
transport = gex.TrxRawUSB(sn='0029002F-42365711-32353530') transport = gex.TrxRawUSB(sn='0029002F-42365711-32353530')
@ -24,11 +27,46 @@ with gex.Client(transport) as client:
if True: if True:
adc = gex.ADC(client, 'adc') adc = gex.ADC(client, 'adc')
print(adc.set_sample_rate(40000)) fs = adc.set_sample_rate(1000)
# adc.stream_start(lambda data: print(data)) data = None
# time.sleep(5)
def capture(rpt):
global data
print("trig'd, %s" % rpt)
data = rpt.data
# adc.setup_trigger(channel=1,
# level=500,
# count=100,
# pretrigger=100,
# auto=False,
# edge="rising",
# holdoff=200,
# handler=capture)
#
# adc.arm()
# time.sleep(2)
data = adc.capture(1000)
#plt.hist(data) #, 'r.', lw=1)
plt.magnitude_spectrum(data[:,0], Fs=fs, scale='dB', color='C1')
plt.show()
# def lst(data):
# if data is not None:
# print("Rx OK") #data
# else:
# print("Closed.")
# adc.stream_start(lst)
time.sleep(3)
# adc.stream_stop() # adc.stream_stop()
# print("Done.")
# time.sleep(.1) # time.sleep(.1)
# print(adc.get_sample_rate()) # print(adc.get_sample_rate())
# time.sleep(.1) # time.sleep(.1)
@ -38,23 +76,23 @@ with gex.Client(transport) as client:
# print(adc.capture(200, 5)) # print(adc.capture(200, 5))
adc.setup_trigger(channel=1, # adc.setup_trigger(channel=1,
level=700, # level=700,
count=100, # count=100,
pretrigger=15, # pretrigger=15,
auto=True, # auto=True,
edge="falling", # edge="falling",
holdoff=200, # holdoff=200,
handler=lambda rpt: print("Report: %s" % rpt)) # handler=lambda rpt: print("Report: %s" % rpt))
print("Armed")
adc.arm()
print("Sleep...")
# adc.force()
# #
# # adc.disarm() # print("Armed")
time.sleep(5) # adc.arm()
adc.disarm() # print("Sleep...")
# # adc.force()
# #
# # # adc.disarm()
# time.sleep(5)
# adc.disarm()
# print(adc.capture(200, 50)) # print(adc.capture(200, 50))

Loading…
Cancel
Save