some adc improvements and testing stuff w pyplot
This commit is contained in:
+6
-1
@@ -44,7 +44,12 @@ class Client:
|
||||
|
||||
# fallback error listener
|
||||
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.unit_lu = {}
|
||||
|
||||
+5
-2
@@ -1,5 +1,7 @@
|
||||
import array
|
||||
|
||||
import time
|
||||
|
||||
import gex
|
||||
from gex import TF, TF_Msg
|
||||
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)
|
||||
|
||||
def stream_stop(self, confirm=True):
|
||||
def stream_stop(self, delay=0.1, confirm=True):
|
||||
""" Stop a stream """
|
||||
if not self._stream_running:
|
||||
raise Exception("Not streaming")
|
||||
|
||||
self._stream_listener = None
|
||||
self._send(cmd=CMD_STREAM_STOP, confirm=confirm)
|
||||
time.sleep(delay)
|
||||
self._stream_listener = None
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#!/bin/env python3
|
||||
import time
|
||||
|
||||
from matplotlib import pyplot as plt
|
||||
|
||||
import gex
|
||||
|
||||
transport = gex.TrxRawUSB(sn='0029002F-42365711-32353530')
|
||||
@@ -24,11 +27,46 @@ with gex.Client(transport) as client:
|
||||
if True:
|
||||
adc = gex.ADC(client, 'adc')
|
||||
|
||||
print(adc.set_sample_rate(40000))
|
||||
fs = adc.set_sample_rate(1000)
|
||||
|
||||
# adc.stream_start(lambda data: print(data))
|
||||
# time.sleep(5)
|
||||
data = None
|
||||
|
||||
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()
|
||||
# print("Done.")
|
||||
|
||||
|
||||
|
||||
|
||||
# time.sleep(.1)
|
||||
# print(adc.get_sample_rate())
|
||||
# time.sleep(.1)
|
||||
@@ -38,23 +76,23 @@ with gex.Client(transport) as client:
|
||||
|
||||
# print(adc.capture(200, 5))
|
||||
|
||||
adc.setup_trigger(channel=1,
|
||||
level=700,
|
||||
count=100,
|
||||
pretrigger=15,
|
||||
auto=True,
|
||||
edge="falling",
|
||||
holdoff=200,
|
||||
handler=lambda rpt: print("Report: %s" % rpt))
|
||||
|
||||
print("Armed")
|
||||
adc.arm()
|
||||
print("Sleep...")
|
||||
# adc.force()
|
||||
# adc.setup_trigger(channel=1,
|
||||
# level=700,
|
||||
# count=100,
|
||||
# pretrigger=15,
|
||||
# auto=True,
|
||||
# edge="falling",
|
||||
# holdoff=200,
|
||||
# handler=lambda rpt: print("Report: %s" % rpt))
|
||||
#
|
||||
# # adc.disarm()
|
||||
time.sleep(5)
|
||||
adc.disarm()
|
||||
# print("Armed")
|
||||
# adc.arm()
|
||||
# print("Sleep...")
|
||||
# # adc.force()
|
||||
# #
|
||||
# # # adc.disarm()
|
||||
# time.sleep(5)
|
||||
# adc.disarm()
|
||||
|
||||
# print(adc.capture(200, 50))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user