Relacs DAQ Library
0.9.8
|
#include <analoginput.h>
Public Member Functions | |
AnalogInput (void) | |
AnalogInput (int aitype) | |
AnalogInput (const string &deviceclass, int aitype=0) | |
virtual | ~AnalogInput (void) |
virtual int | open (const string &device) override |
virtual int | open (Device &device) override |
virtual bool | isOpen (void) const =0 |
virtual void | close (void)=0 |
virtual int | channels (void) const =0 |
virtual int | bits (void) const =0 |
virtual double | maxRate (void) const =0 |
virtual int | maxRanges (void) const =0 |
virtual double | unipolarRange (int index) const =0 |
virtual double | bipolarRange (int index) const =0 |
int | minGainIndex (bool unipolar) const |
int | maxGainIndex (bool unipolar) const |
int | gainIndex (bool unipolar, double maxvoltage) const |
virtual int | testRead (InList &traces) |
virtual int | prepareRead (InList &traces)=0 |
virtual int | startRead (QSemaphore *sp=0, QReadWriteLock *datamutex=0, QWaitCondition *datawait=0, QSemaphore *aosp=0)=0 |
virtual int | readData (void)=0 |
virtual int | convertData (void)=0 |
virtual void | model (InList &data, const vector< int > &aochannels, vector< float > &aovalues) |
virtual int | stop (void)=0 |
virtual int | reset (void)=0 |
virtual bool | running (void) const |
virtual void | take (const vector< AnalogInput * > &ais, const vector< AnalogOutput * > &aos, vector< int > &aiinx, vector< int > &aoinx, vector< bool > &airate, vector< bool > &aorate) |
virtual void | addTraces (vector< TraceSpec > &traces, int deviceid) const |
virtual int | matchTraces (InList &traces) const |
int | analogInputType (void) const |
Public Member Functions inherited from Device | |
Device (int type=MiscellaneousType) | |
Device (const string &deviceclass, int type=MiscellaneousType) | |
virtual | ~Device (void) |
virtual const Options & | info (void) const |
virtual const Options & | settings (void) const |
int | deviceType (void) const |
string | deviceTypeStr (void) const |
string | deviceClass (void) const |
string | deviceFile (void) const |
string | deviceName (void) const |
string | deviceVendor (void) const |
string | deviceIdent (void) const |
virtual void | setDeviceIdent (const string &ident) |
virtual void | clearError (void) |
virtual string | errorStr (void) const |
void | setErrorStr (const string &strg) |
void | addErrorStr (const string &strg) |
void | setErrorStr (int errnum) |
void | addErrorStr (int errnum) |
virtual bool | success (void) const |
virtual bool | failed (void) const |
Protected Member Functions | |
virtual int | testReadData (InList &traces) |
virtual int | testReadDevice (InList &traces)=0 |
void | setAnalogInputType (int aitype) |
void | setReadSleep (unsigned long ms) |
void | setInfo (void) |
void | setSettings (const InList &traces, int readbuffer=0, int updatebuffer=0) |
virtual void | startThread (QSemaphore *sp=0, QReadWriteLock *datamutex=0, QWaitCondition *datawait=0, bool error=false) |
virtual void | run (void) |
virtual void | stopRead (void) |
Protected Member Functions inherited from Device | |
void | setDeviceType (int type) |
void | setDeviceClass (const string &deviceclass) |
void | setDeviceFile (const string &devicefile) |
void | setDeviceName (const string &devicename) |
void | setDeviceVendor (const string &devicevendor) |
void | addInfo (void) |
void | lock (void) const |
void | unlock (void) const |
QMutex * | mutex (void) const |
virtual void | initOptions (void) |
Additional Inherited Members | |
Public Types inherited from Device | |
enum | DeviceTypes { MiscellaneousType = 0, AnalogInputType = 1, AnalogOutputType = 2, DigitalIOType = 3, TriggerType = 4, AttenuatorType = 5, AttenuateType = 6, ManipulatorType = 7, TemperatureType = 8, CameraType = 9 } |
Static Public Member Functions inherited from Device | |
static int | deviceTypes (void) |
static string | deviceTypeStr (int type) |
static string | getErrorStr (int ern) |
Static Public Attributes inherited from Device | |
static const int | NotOpen = -1 |
static const int | InvalidDevice = -2 |
static const int | ReadError = -3 |
static const int | WriteError = -4 |
static const int | InvalidParam = -5 |
Protected Attributes inherited from Device | |
Options | Info |
Options | Settings |
Interface for accessing analog input of a data-aquisition board.
add probe function that returns a string of possible supported devices.
add directread function for single point acquisition
add a flag for indicating whether device is capable of streaming input
In case you want to use a analog input device within RELACS, your AnalogInput implementation needs to provide a void default constructor (i.e. with no parameters) that does not open the device. Also, include the header file <relacs/relacsplugin.h>
and make the AnalogInput device known to RELACS with the addAnalogInput
( ClassNameOfYourAnalogInputImplementation, PluginSetName ) macro.
AnalogInput | ( | void | ) |
Create a new AnalogInput without opening a device. Reimplement this constructor.
AnalogInput | ( | int | aitype | ) |
Constructs an AnalogInput with type id aitype.
AnalogInput | ( | const string & | deviceclass, |
int | aitype = 0 |
||
) |
Constructs an AnalogInput with device class deviceclass and type id aitype.
|
virtual |
Stop analog input and close the daq driver.
|
overridevirtual |
Open the analog input device specified by device. Returns zero on success, or InvalidDevice (or any other negative number indicating the error).
Reimplemented from Device.
References Device::Info, Device::InvalidDevice, Device::setDeviceFile(), and Device::Settings.
|
overridevirtual |
Open the analog input device specified by device. Returns zero on success, or InvalidDevice (or any other negative number indicating the error).
Reimplemented from Device.
References Device::deviceIdent(), Device::Info, Device::InvalidDevice, Device::setDeviceFile(), and Device::Settings.
|
pure virtual |
Returns true if the device is open.
Implements Device.
Referenced by Acquire::addInput(), AnalogInput::gainIndex(), AnalogInput::maxGainIndex(), AnalogInput::minGainIndex(), AnalogInput::setInfo(), and AnalogInput::testReadData().
|
pure virtual |
|
pure virtual |
Number of analog input channels.
Referenced by AnalogInput::setInfo(), and AnalogInput::testReadData().
|
pure virtual |
Resolution in bits of analog input.
Referenced by AnalogInput::setInfo().
|
pure virtual |
Maximum sampling rate in Hz of analog input.
Referenced by AnalogInput::setInfo(), and AnalogInput::testReadData().
|
pure virtual |
Maximum number of analog input ranges.
Referenced by Acquire::adjustGain(), AnalogInput::gainIndex(), AnalogInput::maxGainIndex(), Acquire::maxValues(), Acquire::maxVoltages(), AnalogInput::minGainIndex(), and AnalogInput::testReadData().
|
pure virtual |
Voltage range index in Volt for unipolar mode. If -1 is returned this range is not supported.
Referenced by Acquire::adjustGain(), AnalogInput::gainIndex(), AnalogInput::maxGainIndex(), Acquire::maxValues(), Acquire::maxVoltages(), AnalogInput::minGainIndex(), Acquire::setGain(), and AnalogInput::testReadData().
|
pure virtual |
Voltage range index in Volt for bipolar mode. If -1 is returned this range is not supported.
Referenced by Acquire::adjustGain(), AnalogInput::gainIndex(), AnalogInput::maxGainIndex(), Acquire::maxValues(), Acquire::maxVoltages(), AnalogInput::minGainIndex(), Acquire::setGain(), and AnalogInput::testReadData().
int minGainIndex | ( | bool | unipolar | ) | const |
References AnalogInput::bipolarRange(), AnalogInput::isOpen(), AnalogInput::maxRanges(), and AnalogInput::unipolarRange().
Referenced by Acquire::adjustGain().
int maxGainIndex | ( | bool | unipolar | ) | const |
References AnalogInput::bipolarRange(), AnalogInput::isOpen(), AnalogInput::maxRanges(), and AnalogInput::unipolarRange().
int gainIndex | ( | bool | unipolar, |
double | maxvoltage | ||
) | const |
References AnalogInput::bipolarRange(), AnalogInput::isOpen(), AnalogInput::maxRanges(), and AnalogInput::unipolarRange().
Referenced by Acquire::adjustGain(), AnalogInput::setSettings(), and AnalogInput::testReadData().
|
virtual |
Test settings for analog input on the device for each input channel in traces. First, all error flags in traces are cleared (DaqError::clearError()). If an error ocurred in any trace, the corresponding errorflags in the InData are set and a negative value is returned. The channels in traces are not sorted. Simply calls testReadData() and testReadDevice(). This function can be called any time independently of prepareRead() and startRead() with different traces.
References InList::clearError(), AnalogInput::testReadData(), and AnalogInput::testReadDevice().
|
pure virtual |
Prepare analog input of the input traces traces on the device as much as possible. If an error ocurred in any channel, the corresponding errorflags in the InData structure are filled and a negative value is returned. In addition, according to the InData::gainIndex() of each trace the gain and the minimum and maximum possible output voltages for each of the traces should be set (see InData::setGain(), InData::setMaxVoltage(), InData::setMinVoltage() ). This function assumes that traces successfully passed testRead(). The channels in traces are not sorted.
|
pure virtual |
Start non-blocking analog input for the input traces that were passed to the previous call of prepareRead(). If an error ocurred in any channel, the corresponding errorflags in the InData structure are filled and a negative value is returned. Also start possible pending acquisition on other devices that are known from take().
[in] | sp | if not null, a thread is started reading out the running analog input. When the thread and analog input is finished, releases the semaphore by one. On error, the semaphore is released by 1000 so that the process waiting on the semaphore is waking up immediately. |
[in] | datamutex | the mutex for locking the input traces that were passed to the previous call of prepareRead(). |
[in] | datawait | a waitcondition that is waken up whnever the thread put new data into the input traces. |
[in] | aosp | is the semaphore that guards analog outputs. if null , then do not start analog outputs. |
|
pure virtual |
Read data from a running data acquisition and store them in an internal buffer. Returns the total number of read data values. If an error ocurred in any channel, the corresponding errorflags in the InData structure are filled and a -2 is returned. If no acquisition is running and therefore no more data are to be expected, -1 is returned. This function is called periodically after reading has been successfully started by startRead(). This function does not modify the traces passed to prepareRead()!
Referenced by AnalogInput::run().
|
pure virtual |
Convert the acquired data from the internal buffer to numbers in the secondary unit and store the data in the traces that were passed to the previous call of prepareRead(). Returns the number of data values that were added to the traces (sum over all traces). If an error ocurred in any channel, the corresponding errorflags in the InData structure are filled and a negative value is returned. This function is called periodically after one or several calls to readData().
Referenced by AnalogInput::run().
|
virtual |
Compute a dynamic clamp model. An implementation is only needed for an analog input simulation.
|
pure virtual |
Stop any running ananlog input activity, but preserve all so far read in data. The next call to readData() will return the data. Should call stopRead() to stop the thread. Returns zero on success, otherwise one of the flags NotOpen, InvalidDevice, ReadError.
|
pure virtual |
|
virtual |
|
virtual |
Check for every analog input and analog output device in ais and aos, respectively, whether it can be simultaneously started by startRead() from this device. Add the indices of those devices to aiinx and aoinx, respectively. The corresponding entries in airate and aorate should be set to true
if these devices should use the same sampling rate as this.
|
virtual |
If the analog input device supports inputs that are not physical input lines but rather readable internal variables, like model outputs of a dynamic clamp modul, then reimplement this function. Add for each such variable a TraceSpec to traces. deviceid is the id of this analog input device that you should pass as the device to TraceSpec.
|
virtual |
May match trace names with driver internal trace names, for example trace names of a dynamic clamp model.
int analogInputType | ( | void | ) | const |
The id of the analog input implementation.
|
protectedvirtual |
Test each input channel in traces for valid settings. If an error ocurred in any trace, the corresponding errorflags in the InData are set and a negative value is returned. The following error conditions are checked: DeviceNotOpen, NoData (InData::capacity() <= 0), MultipleDevices, MultipleStartSources, MultipleDelays, MultipleSampleRates, MultipleContinuous, MultipleBuffersizes (InData::capacity()), MultipleBufferTimes, MultipleUpdateTimes, InvalidStartSource (InData::startSource() < 0), InvalidDelay (InData::delay() < 0), InvalidSampleRate (InData::sampleRate() > maxRate() or < 1.0), InvalidChannel (InData::channel() >= channels() or < 0), MultipleChannels, InvalidReference (InData::reference() != InData::Differential, InData::Referenced, InData::NonReferenced), InvalidGain (InData::gainIndex() not valid, i.e. < 0 or >= maxRanges() or the corresponding range in unipolarRange() or bipolarRange does not exist). This function is called by testRead().
References InList::addError(), AnalogInput::bipolarRange(), AnalogInput::channels(), DaqError::DeviceNotOpen, InList::failed(), AnalogInput::gainIndex(), DaqError::InvalidChannel, DaqError::InvalidDelay, DaqError::InvalidGain, DaqError::InvalidReference, DaqError::InvalidSampleRate, DaqError::InvalidStartSource, AnalogInput::isOpen(), AnalogInput::maxRanges(), AnalogInput::maxRate(), DaqError::MultipleBuffersizes, DaqError::MultipleBufferTimes, DaqError::MultipleChannels, DaqError::MultipleContinuous, DaqError::MultipleDelays, DaqError::MultipleDevices, DaqError::MultipleSampleRates, DaqError::MultipleStartSources, DaqError::MultipleUpdateTimes, DaqError::NoData, InData::ParamChannel, InData::RefCommon, InData::RefDifferential, InData::RefGround, InData::RefOther, InList::setContinuous(), InList::setDelay(), InList::setDevice(), InList::setReadTime(), InList::setReference(), InList::setSampleRate(), InList::setStartSource(), InList::setUpdateTime(), InList::size(), and AnalogInput::unipolarRange().
Referenced by AnalogInput::testRead().
|
protectedpure virtual |
Device driver specific tests on the settings in traces for each input channel. Before this function is called, the validity of the settings in traces was already tested by testReadData(). testWriteDevice() is called even if an error was detected by testWriteData(). This function should test whether the settings are really supported by the hardware. If an error ocurred in any trace, the corresponding errorflags in the InData are set and a negative value is returned. In addition, according to the gainIndex() of each trace the gain and the minimum and maximum possible output voltages for each of the traces should be set (see InData::setGain(), InData::setMaxVoltage(), InData::setMinVoltage() ). The channels in traces are not sorted. This function is called by testRead().
Referenced by AnalogInput::testRead().
|
protected |
Set id of the analog input implementation to aitype. This function should be called in the constructor of an implementation of AnalogInput.
|
protected |
Set the time for sleeping between calls of readData() to ms milliseconds.
|
protected |
Set the device info(). Call this function from open().
References Device::addInfo(), AnalogInput::bits(), AnalogInput::channels(), Device::Info, AnalogInput::isOpen(), and AnalogInput::maxRate().
|
protected |
Set the settings() for traces. Call this function from within a successful prepareRead().
[in] | traces | the input traces for which the settings string should be constructed. |
[in] | readbuffer | is the size of the driver's buffer in bytes. |
[in] | updatebuffer | is the size of the internal buffer in bytes. |
References AnalogInput::gainIndex(), Device::Settings, and InList::size().
|
protectedvirtual |
Start the thread if sp is not null. If error do not start the thread and release the semaphore sp.
|
protectedvirtual |
The thread reading data from a running analog input.
References Device::addErrorStr(), AnalogInput::convertData(), Device::getErrorStr(), Device::lock(), AnalogInput::readData(), AnalogInput::reset(), and Device::unlock().
|
protectedvirtual |
Stop the running thread.
References Device::lock(), and Device::unlock().