Bugfixes of Python/C++ interaction layer, first tests for DaqConfiguration code

This commit is contained in:
Anne de Jong 2020-10-18 13:58:42 +02:00
parent 6b8abb878a
commit fa32e9eac3
8 changed files with 62 additions and 42 deletions

View File

@ -3,4 +3,5 @@ from .lasp_device_common import *
from .lasp_daq import * from .lasp_daq import *
from .lasp_deviceinfo import * from .lasp_deviceinfo import *
from .lasp_daqconfig import * from .lasp_daqconfig import *
from .lasp_daq import *

View File

@ -117,7 +117,8 @@ cdef extern from "lasp_cppdaq.h" nogil:
usvec inputRangeIndices usvec inputRangeIndices
DaqConfiguration() cppDaqConfiguration()
cppDaqConfiguration(cppDeviceInfo& devinfo)
int getHighestInChannel() int getHighestInChannel()
int getHighestOutChannel() int getHighestOutChannel()

View File

@ -277,7 +277,7 @@ int mycallback(
if(inputBuffer) { if(inputBuffer) {
us j=0; // OUR buffer channel counter us j=0; // OUR buffer channel counter
us i=0; // RtAudio channel counter us i=0; // RtAudio channel counter
for(us ch=daq->getLowestInChannel();ch<=daq->getHighestInChannel();ch++) { for(int ch=daq->getLowestInChannel();ch<=daq->getHighestInChannel();ch++) {
if(eninchannels[ch]) { if(eninchannels[ch]) {
memcpy( memcpy(
&(inbuffercpy[monitorOffset+j*bytesperchan]), &(inbuffercpy[monitorOffset+j*bytesperchan]),

View File

@ -1,4 +1,5 @@
include "lasp_common_decls.pxd" include "lasp_common_decls.pxd"
from .lasp_deviceinfo cimport DeviceInfo
cdef class DaqConfiguration: cdef class DaqConfiguration:
cdef: cdef:

View File

@ -8,43 +8,31 @@ Description:
Data Acquistiion (DAQ) device descriptors, and the DAQ devices themselves Data Acquistiion (DAQ) device descriptors, and the DAQ devices themselves
""" """
from dataclasses import dataclass, field __all__ = ['DaqChannel', 'DaqConfiguration']
from typing import List
from dataclasses_json import dataclass_json
from ..lasp_common import lasp_shelve, SIQtys, Qty from ..lasp_common import lasp_shelve, SIQtys, Qty
from .lasp_device_common import DaqChannel
import json import json
class CouplingMode:
ac = 'AC'
dc = 'DC'
undefined = 'Undefined'
class Range:
oneV = '+/- 1 V'
tenV = '+/- 10 V'
undefined = 'Undefined'
@dataclass_json
@dataclass
class DaqChannel:
channel_enabled: bool
channel_name: str = 'Unnamed channel'
sensitivity: float = 1.0
range_index: int = 0
ACCoupling_enabled: bool = False
IEPE_enabled: bool = False
cdef class DaqConfiguration: cdef class DaqConfiguration:
""" """
Initialize a device descriptor Initialize a device descriptor
""" """
def __init__(self):
pass
@staticmethod @staticmethod
def from_json(self, jsonstring): def fromDeviceInfo(DeviceInfo devinfo):
cdef:
cppDaqConfiguration cconfig
d = DaqConfiguration()
cconfig = cppDaqConfiguration(devinfo.devinfo)
d.config = cconfig
return d
@staticmethod
def from_json(jsonstring):
config_dict = json.loads(jsonstring) config_dict = json.loads(jsonstring)
return DaqConfiguration.from_dict(config_dict) return DaqConfiguration.from_dict(config_dict)
@ -58,8 +46,13 @@ cdef class DaqConfiguration:
config.device_name = pydict['device_name'].encode('utf-8') config.device_name = pydict['device_name'].encode('utf-8')
config.eninchannels = pydict['eninchannels'] config.eninchannels = pydict['eninchannels']
config.enoutchannels = pydict['enoutchannels'] config.enoutchannels = pydict['enoutchannels']
config.inchannel_names = pydict['inchannel_names']
config.outchannel_names = pydict['outchannel_names'] config.inchannel_names = [inchname.encode('utf-8') for inchname in
pydict['inchannel_names']]
config.outchannel_names = [outchname.encode('utf-8') for outchname in
pydict['outchannel_names']]
config.sampleRateIndex = pydict['sampleRateIndex'] config.sampleRateIndex = pydict['sampleRateIndex']
config.framesPerBlockIndex = pydict['framesPerBlockIndex'] config.framesPerBlockIndex = pydict['framesPerBlockIndex']
config.dataTypeIndex = pydict['dataTypeIndex'] config.dataTypeIndex = pydict['dataTypeIndex']
@ -75,7 +68,7 @@ cdef class DaqConfiguration:
def to_json(self): def to_json(self):
return json.dumps(dict( return json.dumps(dict(
apicode = self.api.apicode, apicode = self.config.api.apicode,
device_name = self.config.device_name.decode('utf-8'), device_name = self.config.device_name.decode('utf-8'),
eninchannels = self.eninchannels(), eninchannels = self.eninchannels(),
@ -87,7 +80,7 @@ cdef class DaqConfiguration:
self.config.outchannel_names], self.config.outchannel_names],
sampleRateIndex = self.config.sampleRateIndex, sampleRateIndex = self.config.sampleRateIndex,
dataTypeIndex = self.config.dataTypeIndex, dataTypeIndex = self.config.dataTypeIndex,
nFramesPerBlockIndex = self.config.framesPerBlockIndex, framesPerBlockIndex = self.config.framesPerBlockIndex,
monitorOutput = self.config.monitorOutput, monitorOutput = self.config.monitorOutput,
inputIEPEEnabled = self.config.inputIEPEEnabled, inputIEPEEnabled = self.config.inputIEPEEnabled,
@ -111,7 +104,7 @@ cdef class DaqConfiguration:
) )
def setInChannel(self, i:int, daqchannel: DaqChannel): def setInChannel(self, i:int, daqchannel: DaqChannel):
self.config.eninchannels[i] = daqchannel.channel_enabled self.config.eninchannels[i] = daqchannel.channel_enabled
self.config.inchannel_names[i] = daqchannel.channel_name self.config.inchannel_names[i] = daqchannel.channel_name.encode('utf-8')
self.config.inchannel_sensitivities[i] = daqchannel.sensitivity self.config.inchannel_sensitivities[i] = daqchannel.sensitivity
self.config.inputRangeIndices[i] = daqchannel.range_index self.config.inputRangeIndices[i] = daqchannel.range_index
self.config.inputACCouplingMode[i] = daqchannel.ACCoupling_enabled self.config.inputACCouplingMode[i] = daqchannel.ACCoupling_enabled

View File

@ -1,5 +1,7 @@
__all__ = ['AvType', 'DaqChannel']
__all__ = ['AvType'] from dataclasses import dataclass, field
from dataclasses_json import dataclass_json
from typing import List
class AvType: class AvType:
"""Specificying the type of data, for adding and removing callbacks from """Specificying the type of data, for adding and removing callbacks from
@ -7,3 +9,26 @@ class AvType:
audio_input = 1 audio_input = 1
audio_output = 2 audio_output = 2
video = 4 video = 4
@dataclass_json
@dataclass
class DaqChannel:
channel_enabled: bool
channel_name: str = 'Unnamed channel'
sensitivity: float = 1.0
range_index: int = 0
ACCoupling_enabled: bool = False
IEPE_enabled: bool = False
class CouplingMode:
ac = 'AC'
dc = 'DC'
undefined = 'Undefined'
class Range:
oneV = '+/- 1 V'
tenV = '+/- 10 V'
undefined = 'Undefined'

View File

@ -21,9 +21,9 @@ args = parser.parse_args()
from lasp.lasp_avstream import AvStream, AvType from lasp.lasp_avstream import AvStream, AvType
from lasp.lasp_record import Recording from lasp.lasp_record import Recording
from lasp.device import DAQConfiguration, RtAudio, UlDaq from lasp.device import DaqConfiguration, Daq, DaqChannel
configs = DAQConfiguration.loadConfigs() configs = DaqConfiguration.loadConfigs()
for i, (key, val) in enumerate(configs.items()): for i, (key, val) in enumerate(configs.items()):
print(f'{i:2} : {key}') print(f'{i:2} : {key}')
@ -45,8 +45,7 @@ config = configs[key]
print(config) print(config)
# daq = RtAudio() # daq = RtAudio()
daq = UlDaq() devices = Daq.getDeviceInfo()
devices = daq.getDeviceInfo()
input_devices = {} input_devices = {}
for device in devices: for device in devices:

View File

@ -40,7 +40,7 @@ int main() {
cout << "Inchannnels size: " << config.eninchannels.size() << endl; cout << "Inchannnels size: " << config.eninchannels.size() << endl;
Daq* daq = Daq::createDevice(config, devinfos); Daq* daq = Daq::createDaq(devinfo, config);
SafeQueue<void*> inqueue; SafeQueue<void*> inqueue;
SafeQueue<void*> outqueue; SafeQueue<void*> outqueue;