2019-12-18 09:02:20 +00:00
|
|
|
#!/usr/bin/python3
|
2018-07-31 11:09:42 +00:00
|
|
|
import argparse
|
2020-09-18 06:52:56 +00:00
|
|
|
import sys
|
2019-12-18 09:02:20 +00:00
|
|
|
|
|
|
|
|
2018-07-31 11:09:42 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description='Acquire data and store a measurement file'
|
|
|
|
)
|
|
|
|
parser.add_argument('filename', type=str,
|
|
|
|
help='File name to record to.'
|
|
|
|
' Extension is automatically added.')
|
|
|
|
parser.add_argument('--duration', '-d', type=float,
|
|
|
|
help='The recording duration in [s]')
|
2018-09-13 11:56:05 +00:00
|
|
|
|
|
|
|
device_help = 'DAQ Device to record from'
|
2018-12-28 12:55:09 +00:00
|
|
|
parser.add_argument('--input-daq', '-i', help=device_help, type=str,
|
2019-12-18 09:02:20 +00:00
|
|
|
default='Default')
|
2018-09-13 11:56:05 +00:00
|
|
|
|
2018-07-31 11:09:42 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2019-10-27 13:19:26 +00:00
|
|
|
|
2019-12-22 14:00:50 +00:00
|
|
|
from lasp.lasp_avstream import AvStream, AvType
|
2019-12-18 09:02:20 +00:00
|
|
|
from lasp.lasp_record import Recording
|
2020-10-18 11:58:42 +00:00
|
|
|
from lasp.device import DaqConfiguration, Daq, DaqChannel
|
2020-09-18 06:52:56 +00:00
|
|
|
|
2020-10-18 11:58:42 +00:00
|
|
|
configs = DaqConfiguration.loadConfigs()
|
2020-09-18 06:52:56 +00:00
|
|
|
|
|
|
|
for i, (key, val) in enumerate(configs.items()):
|
|
|
|
print(f'{i:2} : {key}')
|
|
|
|
|
|
|
|
daqindex = input('Please enter required config: ')
|
|
|
|
try:
|
|
|
|
daqindex = int(daqindex)
|
|
|
|
except:
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
for i, (key, val) in enumerate(configs.items()):
|
|
|
|
if i == daqindex:
|
|
|
|
config = configs[key]
|
|
|
|
|
|
|
|
|
|
|
|
config = configs[key]
|
|
|
|
|
2019-10-27 13:19:26 +00:00
|
|
|
|
|
|
|
|
2019-12-18 09:02:20 +00:00
|
|
|
print(config)
|
2020-09-18 06:52:56 +00:00
|
|
|
# daq = RtAudio()
|
2020-10-18 11:58:42 +00:00
|
|
|
devices = Daq.getDeviceInfo()
|
2019-12-18 09:02:20 +00:00
|
|
|
|
|
|
|
input_devices = {}
|
|
|
|
for device in devices:
|
|
|
|
if device.inputchannels >= 0:
|
|
|
|
input_devices[device.name] = device
|
|
|
|
|
|
|
|
try:
|
|
|
|
input_device = input_devices[config.input_device_name]
|
|
|
|
except KeyError:
|
|
|
|
raise RuntimeError(f'Input device {config.input_device_name} not available')
|
2019-10-27 13:19:26 +00:00
|
|
|
|
2019-12-18 09:02:20 +00:00
|
|
|
print(input_device)
|
|
|
|
|
2019-12-22 14:00:50 +00:00
|
|
|
stream = AvStream(input_device,
|
|
|
|
AvType.audio_input,
|
2019-12-18 09:02:20 +00:00
|
|
|
config)
|
2018-09-13 11:56:05 +00:00
|
|
|
|
2020-09-18 06:52:56 +00:00
|
|
|
|
2018-07-31 11:09:42 +00:00
|
|
|
rec = Recording(args.filename, stream, args.duration)
|
2020-09-18 06:52:56 +00:00
|
|
|
stream.start()
|
2019-12-23 11:25:37 +00:00
|
|
|
with rec:
|
|
|
|
pass
|
2019-12-18 09:02:20 +00:00
|
|
|
|
|
|
|
print('Stopping stream...')
|
2018-07-31 11:09:42 +00:00
|
|
|
stream.stop()
|
2019-12-18 09:02:20 +00:00
|
|
|
|
|
|
|
print('Stream stopped')
|
|
|
|
print('Closing stream...')
|
|
|
|
print('Stream closed')
|