Relacs DAQ Library  0.9.8
Public Types | Public Member Functions | Protected Member Functions | List of all members
AnalogOutput Class Referenceabstract

#include <analogoutput.h>

Inheritance diagram for AnalogOutput:
Inheritance graph
[legend]
Collaboration diagram for AnalogOutput:
Collaboration graph
[legend]

Public Types

enum  Status { Idle =0, Running =1, Underrun =2, UnknownError =3 }
 
- 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
}
 

Public Member Functions

 AnalogOutput (void)
 
 AnalogOutput (int aotype)
 
 AnalogOutput (const string &deviceclass, int aotype=0)
 
virtual ~AnalogOutput (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
 
double delay (int channel) const
 
void setDelays (const vector< double > &delays)
 
void setDelay (double delay)
 
double externalReference (void) const
 
void setExternalReference (double extr)
 
virtual int directWrite (OutList &sigs)=0
 
virtual int testWrite (OutList &sigs)
 
virtual int prepareWrite (OutList &sigs)=0
 
virtual int startWrite (QSemaphore *sp=0)=0
 
virtual int writeData (void)=0
 
virtual int stop (void)=0
 
virtual int reset (void)=0
 
virtual Status status (void) const =0
 
bool running (void) const
 
virtual long index (void) const
 
virtual int getAISyncDevice (const vector< AnalogInput * > &ais) const
 
virtual bool useAIRate (void) const
 
virtual void take (const vector< AnalogOutput * > &aos, vector< int > &aoinx, vector< bool > &aorate)
 
virtual void addTraces (vector< TraceSpec > &traces, int deviceid) const
 
virtual int matchTraces (vector< TraceSpec > &traces) const
 
int analogOutputType (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 testWriteData (OutList &sigs)
 
virtual int testWriteDevice (OutList &sigs)=0
 
void setAnalogOutputType (int aotype)
 
void setWriteSleep (unsigned long ms)
 
void setErrorStr (const string &strg)
 
void addErrorStr (const string &strg)
 
void setErrorStr (int errnum)
 
void addErrorStr (int errnum)
 
void setErrorStr (const OutList &sigs)
 
void addErrorStr (const OutList &sigs)
 
void setInfo (void)
 
void setSettings (const OutList &sigs, int writebuffer=0)
 
virtual void startThread (QSemaphore *sp=0, bool error=false)
 
virtual void run (void)
 
virtual void stopWrite (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

- 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
 

Detailed Description

Interface for accessing analog output of a data-aquisition board.

Author
Marco Hackenberg
Jan Benda
Todo:

add probe function that returns a string of possible supported devices.

add a flag for indicating whether device is capable of streaming output

In case you want to use a analog output device within RELACS, your AnalogOutput 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 AnalogOutput device known to RELACS with the addAnalogOutput( ClassNameOfYourAnalogInputImplementation, PluginSetName ) macro.

Member Enumeration Documentation

enum Status

Return values for analog output status().

Enumerator
Idle 

Not running and no error.

Running 

Anaolog output is still in progress.

Underrun 

Buffer underrun error.

UnknownError 

Any other error.

Constructor & Destructor Documentation

AnalogOutput ( void  )

Create a new AnalogOutput without opening a device. Reimplement this constructor.

AnalogOutput ( int  aotype)

Constructs an AnalogOutput with type id aotype.

See Also
setAnalogOutputType()
AnalogOutput ( const string &  deviceclass,
int  aotype = 0 
)

Constructs an AnalogOutput with device class deviceclass and type id aotype.

See Also
setDeviceClass(), setAnalogOutputType()
~AnalogOutput ( void  )
virtual

Stop analog output and close the daq driver.

Member Function Documentation

int open ( const string &  device)
overridevirtual

Open the analog output device specified by device. Returns zero on success, or InvalidDevice (or any other negative number indicating the error). A reimplementation of this function should extract the following options from opts if provided:

Reimplemented from Device.

References Device::Info, Device::InvalidDevice, Device::setDeviceFile(), and Device::Settings.

int open ( Device device)
overridevirtual

Open the analog input device specified by device. Returns zero on success, or InvalidDevice (or any other negative number indicating the error).

See Also
isOpen(), close(), reset()

Reimplemented from Device.

References Device::deviceIdent(), Device::Info, Device::InvalidDevice, Device::setDeviceFile(), and Device::Settings.

virtual bool isOpen ( void  ) const
pure virtual

Returns true if the device is open.

See Also
open(), close(), reset()

Implements Device.

Referenced by Acquire::addOutput(), AnalogOutput::setInfo(), and AnalogOutput::testWriteData().

virtual void close ( void  )
pure virtual

Stop all activity and close the device.

See Also
open(), isOpen(), reset()

Implements Device.

virtual int channels ( void  ) const
pure virtual

Number of analog output channels.

Referenced by AnalogOutput::delay(), AnalogOutput::setInfo(), and AnalogOutput::testWriteData().

virtual int bits ( void  ) const
pure virtual

Resolution in bits of analog output.

Referenced by AnalogOutput::setInfo().

virtual double maxRate ( void  ) const
pure virtual

Maximum sampling rate in Hz of analog output.

Referenced by AnalogOutput::setInfo(), and AnalogOutput::testWriteData().

double delay ( int  channel) const

Delay in seconds from calling startWrite() to the actual signal start of channel channel.

References AnalogOutput::channels().

Referenced by AnalogOutput::setInfo(), AnalogOutput::setSettings(), and AnalogOutput::testWriteData().

void setDelays ( const vector< double > &  delays)

Set for each channel the delay in seconds it takes from calling startWrite() to the actual signal start. If there are such delays, this function should be called in the implementation of the open() function to set them.

See Also
setDelay()

References AnalogOutput::setInfo().

void setDelay ( double  delay)

Set the delay in seconds it takes from calling startWrite() to the actual signal start for all channels to delay. If there are such delays, this function should be called in the implementation of the open() function to set them.

See Also
setDelays()

References AnalogOutput::setInfo().

double externalReference ( void  ) const

The voltage of an external reference for scaling the analog output. A negative number indicates that an external reference is not connected to the daq board. Zero is returned, if the external reference is a non-constant voltage.

void setExternalReference ( double  extr)

Set the voltage of an external reference for scaling the analog output to extr. A negative extr indicates that an external reference is not connected to the daq board. Set extr to zero if the external reference is a non-constant voltage.

virtual int directWrite ( OutList sigs)
pure virtual

Directly writes from each signal in sigs the first data value to the data acquisition board.

int testWrite ( OutList sigs)
virtual

Test settings for analog output on the device for each output signal in sigs. First, all error flags in sigs are cleared (DaqError::clearError()). If an error ocurred in any signal, the corresponding errorflags in OutData are set and a negative value is returned. The channels in sigs are not sorted. Simply calls testWriteData() and testWriteDevice(). This function can be called any time independently of prepareWrite() and startWrite() with different sigs.

References OutList::clearError(), AnalogOutput::testWriteData(), and AnalogOutput::testWriteDevice().

virtual int prepareWrite ( OutList sigs)
pure virtual

Prepare analog output of the output signals sigs on the device. If an error ocurred in any signal, the corresponding errorflags in OutData are set and a negative value is returned. In addition, according to OutData::requestedMin() and OutData::requestedMax(), the gain, the polarity, the reference, and the minimum and maximum possible output voltages for each of the traces in sigs should be set (see OutData::setGain(), OutData::setGainIndex(), OutData::setMaxData(), OutData::setMinData() ). This function assumes that sigs successfully passed testWrite(). The channels in sigs are not sorted.

virtual int startWrite ( QSemaphore *  sp = 0)
pure virtual

Start non-blocking analog output of the output signals that were passed to the previous call of prepareWrite(). If an error ocurred in any signal, the corresponding errorflags in OutData are set and a negative value is returned. If no further calls of writeData() are required, 0 is returned, otherwise 1 is returned. Also start possible pending acquisition on other devices that are known from take(). This function is always called after a successfull prepareRead(). An implementation of startWrite() should call startThread() to start the thread.

Parameters
[in]spif not null, a thread is started feeding the running analog output. When the thread and analog output 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.
virtual int writeData ( void  )
pure virtual

Write data of the output signals that were passed to the previous call of prepareWrite() to the analog output device. Returns the number of transferred data elements. Returns zero if all data are transferred and no more calls to writeData() are necessary. If an error ocurred in any channel, the corresponding errorflags in the OutData structure are filled, the error string is set, and a negative value is returned. This function is called periodically after writing has been successfully started by startWrite().

See Also
setErrorStr()

Referenced by AnalogOutput::run().

virtual int stop ( void  )
pure virtual

Stop any running ananlog output activity. Assumes that analog output is open. Should call stopWrite() to stop the thread. Returns zero on success.

See Also
reset(), startWrite()
int reset ( void  )
pure virtual

Clear any internal data buffers and reset the device. Assumes that analog output is open and already stopped. Returns zero on success. An implementation should NOT clear the error string!

See Also
stop(), close(), open(), isOpen()

Reimplemented from Device.

References Device::Settings.

Referenced by AnalogOutput::run().

virtual Status status ( void  ) const
pure virtual
Returns
the status of the analog output. If an error is detected, this function could also set the appropriate error code in the signals.

Referenced by AnalogOutput::run().

bool running ( void  ) const
Returns
true if the analog input thread is running.
long index ( void  ) const
virtual

Index of signal start. The default implemetation returns -1, indicating that no index is available. If the analog output driver can return an index into the data stream of a running analog input where the last analog output started, then this function should return the this index. You also need to reimplement getAISyncDevice() to let the user know about this property.

int getAISyncDevice ( const vector< AnalogInput * > &  ais) const
virtual

In case the analog output driver can return an index (via the index() function) into the data stream of a running analog input where the last analog output started, then this function should return the index of the corresponding analog input device in ais. This function is called once after opening the device and before any IO operation. The default implementation simply returns -1.

bool useAIRate ( void  ) const
virtual

Return true if the analog output is required to have the same sampling rate as the analog input returned by getAISyncDevice(). The default implementation returns false.

void take ( const vector< AnalogOutput * > &  aos,
vector< int > &  aoinx,
vector< bool > &  aorate 
)
virtual

Check for every analog output device in aos whether it can be simultaneously started by startWrite() from this device. Add the indices of those devices to aoinx. The corresponding entries in aorate should be set to true if these devices should use the same sampling rate as this.

void addTraces ( vector< TraceSpec > &  traces,
int  deviceid 
) const
virtual

If the analog output device supports outputs that are not physical output lines but rather writeable parameter, like model parameter for a dynamic clamp modul, then reimplement this function. Add for each such parameter a TraceSpec to traces. deviceid is the id of the analog output device that you should pass as the device to TraceSpec.

int matchTraces ( vector< TraceSpec > &  traces) const
virtual

May match trace names with driver internal trace names, for example trace names of a dynamic clamp model.

Returns
0: no traces needed to be matched.
n: n traces have been successfully matched.
-1: Failed to match a trace.
int analogOutputType ( void  ) const

The id of the analog output implementation.

See Also
setAnalogOutputType(), deviceType(), deviceName(), ident()
int testWriteData ( OutList sigs)
protectedvirtual

Test each output signal in sigs for valid settings. If an error ocurred in any signal, the corresponding errorflags in the OutData are set and a negative value is returned. The following error conditions are checked: DeviceNotOpen, NoData (OutData::size() <= 0), MultipleDevices, MultipleStartSources, MultipleDelays, MultipleSampleRates, MultipleContinuous, MultipleRestart, MultipleBuffersizes (OutData::size()), MultipleBufferTimes, InvalidStartSource (OutData::startSource() < 0), InvalidDelay (OutData::delay() < 0), InvalidSampleRate (OutData::sampleRate() > maxRate() or < 1.0), InvalidChannel (OutData::channel() >= channels() or < 0), MultipleChannels. This function is called by testWrite().

References OutList::addError(), AnalogOutput::channels(), AnalogOutput::delay(), DaqError::DeviceNotOpen, OutList::failed(), DaqError::InvalidChannel, DaqError::InvalidDelay, DaqError::InvalidSampleRate, DaqError::InvalidStartSource, AnalogOutput::isOpen(), AnalogOutput::maxRate(), DaqError::MultipleBuffersizes, DaqError::MultipleChannels, DaqError::MultipleContinuous, DaqError::MultipleDelays, DaqError::MultipleDevices, DaqError::MultipleRestart, DaqError::MultipleSampleRates, DaqError::MultipleStartSources, DaqError::NoData, OutList::setContinuous(), OutList::setDelay(), OutList::setDevice(), OutList::setRestart(), OutList::setSampleRate(), OutList::setStartSource(), and OutList::size().

Referenced by AnalogOutput::testWrite().

virtual int testWriteDevice ( OutList sigs)
protectedpure virtual

Device driver specific tests on the settings in sigs for each output signal. Before this function is called, the validity of the settings in sigs 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 OutData are set and a negative value is returned. In addition, according to OutData::requestedMin() and OutData::requestedMax(), the gain, the polarity, the reference, and the minimum and maximum possible output voltages for each of the traces in sigs should be set (see OutData::setGain(), OutData::setGainIndex(), OutData::setMaxData(), OutData::setMinData() ). The channels in sigs are not sorted. This function is called by testWrite().

Referenced by AnalogOutput::testWrite().

void setAnalogOutputType ( int  aotype)
protected

Set id of the analog output implementation to aotype. This function should be called in the constructor of an implementation of AnalogOutput.

See Also
analogOutputType(), setDeviceType(), setDeviceName(), setIdent()
void setWriteSleep ( unsigned long  ms)
protected

Set the time for sleeping between calls of writeData() to ms milliseconds.

void setErrorStr ( const string &  strg)
protected

Set error string to strg.

See Also
addErrorStr(), errorStr()

References Device::setErrorStr().

void addErrorStr ( const string &  strg)
protected

Add strg to the error string.

See Also
setErrorStr(), errorStr()

References Device::addErrorStr().

Referenced by AnalogOutput::run().

void setErrorStr ( int  errnum)
protected

Set error string to the string describing the standard C error code errnum (from errno).

See Also
addErrorStr(), errorStr()

References Device::setErrorStr().

void addErrorStr ( int  errnum)
protected

Add the string describing the standard C error code errnum (from errno) to the error string.

See Also
setErrorStr(), errorStr()

References Device::addErrorStr().

void setErrorStr ( const OutList sigs)
protected

If sigs.failed(), set error string to the error set in sigs otherwise clear the error string.

See Also
addErrorStr()

References Device::clearError(), OutList::errorText(), OutList::failed(), and Device::setErrorStr().

void addErrorStr ( const OutList sigs)
protected

If sigs.failed(), add error string to the error set in sigs.

See Also
setErrorStr()

References Device::addErrorStr(), OutList::errorText(), and OutList::failed().

void setInfo ( void  )
protected
void setSettings ( const OutList sigs,
int  writebuffer = 0 
)
protected

Set the settings() for sigs. Call this function from within a successful prepareWrite().

Parameters
[in]sigsthe output data fro which the settings string should be constructed.
[in]writebufferis the size of the driver's buffer in bytes.
See Also
settings()

References AnalogOutput::delay(), Device::Settings, and OutList::size().

void startThread ( QSemaphore *  sp = 0,
bool  error = false 
)
protectedvirtual

Start the thread if sp is not null. If error do not start the thread and release the semaphore sp.

void run ( void  )
protectedvirtual
void stopWrite ( void  )
protectedvirtual

Stop the running thread.

References Device::lock(), and Device::unlock().


The documentation for this class was generated from the following files: