Skip to content
Snippets Groups Projects
Commit fa02c19f authored by Sonia Minolli's avatar Sonia Minolli
Browse files

Add callback mode for BUFFERED acquisition (CPPAPIS-18)

parent e5e9f1c7
No related branches found
No related tags found
No related merge requests found
......@@ -36,8 +36,10 @@ namespace ni660Xsl
class NI660XSL_EXPORT BufferedAcquisition :public virtual CounterBasedOperation
{
public:
BufferedAcquisition(void);
virtual ~BufferedAcquisition(void);
/**
* Configure the sample clock (rate at which data is saved in the buffer)
* @param _sample_clk The pin of the sample clock.
......@@ -45,21 +47,25 @@ namespace ni660Xsl
* @param _max_rate The maximum expected rate of the clock in samples per seconds.
*/
virtual void set_sample_clock(std::string _sample_clk, ni::EdgeType _active_edge, double _max_rate);
/**
* Set the buffer depth.
* @param _nb_samples The buffer depth in samples per channel.
*/
virtual void set_buffer_depth(unsigned long _nb_samples);
/**
* Set the overrun strategy
* @param _strategy The strategy to apply.
*/
virtual void set_overrun_strategy(ni::StrategyType _strategy);
/**
* Set the timeout (time to for data wait when entering get_buffer )
* @param _timeout The time to wait in seconds.
*/
virtual void set_timeout(double _timeout);
/**
* Set the timing to be finite or continuous.
* If the chosen mode is finite, the acquisition will fill one buffer.
......@@ -67,28 +73,40 @@ namespace ni660Xsl
* @param _mode The mode to use.
*/
virtual void set_timing_mode(ni::ModeType _mode);
/**
* Specifies the point in the buffer at which to begin a read operation.
* @param _start_point The start point.
* @param _offset The offset to apply to _start_point.
*/
virtual void set_read_start_point(ni::StartPointType _start_point, unsigned long _offset);
/**
* Start the acquisition of a raw buffer.
* Set the callback mode for buffered acquisition (default = disabled).
* @param _enabled True if callback mechanism is to be enabled.
*/
virtual void set_callback_mode(bool _enabled);
/**
* Start the acquisition of a raw buffer (polling mecanism).
*/
virtual void get_raw_buffer(void) throw (ni660Xsl::DAQException);
/**
* Start the acquisition of a scaled buffer.
*/
virtual void get_scaled_buffer(void) throw (ni660Xsl::DAQException);
/**
* This function must be implemented by user. Will be called each time an overrun occurred.
*/
virtual void handle_data_lost(void) = 0;
/**
* This function must be implemented by user. Will be called each time a timeout occurred.
*/
virtual void handle_timeout(void) = 0;
/**
* This function must be implemented by user.
* Will be called each time a raw buffer has been received.
......@@ -97,6 +115,7 @@ namespace ni660Xsl
* @param _samples_read The actual number of samples read from each channel (returned value).
*/
virtual void handle_raw_buffer(ni660Xsl::InRawBuffer* buffer, long& _samples_read) = 0;
/**
* This function must be implemented by user.
* Will be called each time a raw buffer has been received.
......@@ -116,7 +135,7 @@ namespace ni660Xsl
unsigned long offset_;
double timeout_;
ni::ModeType mode_;
bool use_callback_;
};
}//namespace
......
......@@ -28,6 +28,7 @@
namespace ni660Xsl
{
// ============================================================================
//! Perform buffered event counting
// ============================================================================
......@@ -37,25 +38,32 @@ namespace ni660Xsl
//! The rate at which data is saved is determined by a sample clock.
//!
// ============================================================================
class NI660XSL_EXPORT BufferedEventCounting: public EventCounting, public BufferedAcquisition
class NI660XSL_EXPORT BufferedEventCounting: public EventCounting,
public BufferedAcquisition
{
public:
BufferedEventCounting(void);
virtual ~BufferedEventCounting(void);
BufferedEventCounting();
virtual ~BufferedEventCounting();
/**
* Configure the hardware with all preconfigured parameters.
*/
virtual void configure(void) throw (ni660Xsl::DAQException);
virtual void configure(void)
throw (ni660Xsl::DAQException);
/**
* This function must be implemented by user. Will be called each time a overrun occurred.
* This function must be implemented by user.
* Will be called each time a overrun occurred.
*/
virtual void handle_data_lost(void) = 0;
virtual void handle_data_lost() = 0;
/**
* This function must be implemented by user. Will be called each time a timeout occurred.
* This function must be implemented by user.
* Will be called each time a timeout occurred.
*/
virtual void handle_timeout(void) = 0;
virtual void handle_timeout() = 0;
/**
* This function must be implemented by user.
* Will be called each time a buffer has been received.
......
......@@ -34,23 +34,31 @@ namespace ni660Xsl
//! The rate at which data is saved is determined by a sample clock.
//!
// ============================================================================
class NI660XSL_EXPORT BufferedPositionMeasurement: public PositionMeasurement, public BufferedAcquisition
class NI660XSL_EXPORT BufferedPositionMeasurement: public PositionMeasurement,
public BufferedAcquisition
{
public:
BufferedPositionMeasurement(void);
virtual ~BufferedPositionMeasurement(void);
BufferedPositionMeasurement();
virtual ~BufferedPositionMeasurement();
/**
* Configure hardware with all predefined parameters
* Configure hardware with all predefined parameters.
*/
virtual void configure (void) throw (ni660Xsl::DAQException);
virtual void configure (void)
throw (ni660Xsl::DAQException);
/**
* This function must be implemented by user. Will be called each time a overrun occurred.
* This function must be implemented by user.
* Will be called each time a overrun occurred.
*/
virtual void handle_data_lost(void) = 0;
/**
* This function must be implemented by user. Will be called each time a timeout occurred.
* This function must be implemented by user.
* Will be called each time a timeout occurred.
*/
virtual void handle_timeout(void) = 0;
/**
* This function must be implemented by user.
* Will be called each time a raw buffer has been received.
......@@ -59,6 +67,7 @@ namespace ni660Xsl
* @param _samples_read The actual number of samples read from each channel(returned value).
*/
virtual void handle_raw_buffer(ni660Xsl::InRawBuffer* buffer, long& _samples_read) = 0;
/**
* This function must be implemented by user.
* Will be called each time a scaled buffer has been received.
......
......@@ -36,18 +36,22 @@ namespace ni660Xsl
class NI660XSL_EXPORT EventCounting: public InputOperation
{
public:
EventCounting(void);
virtual ~EventCounting(void);
/**
* Add an an input channel to an event counting operation. \n
* It is only possible to add one channel.
* @param _chan The channel to add.
*/
virtual void add_input_channel(ni660Xsl::EventCountChan _chan);
/**
* Configure the hardware
* Configure the hardware.
*/
virtual void configure(void) = 0;
protected:
std::string chan_name_;
ni::EdgeType edge_;
......@@ -55,9 +59,9 @@ protected:
ni::DirectionType count_direction_;
int added_channels;
std::string input_terminal_;
// Configure the input channel.
virtual void configure_channel(void) throw (ni660Xsl::DAQException);
};
}//namespace
......
......@@ -64,7 +64,7 @@ class NI660XSL_EXPORT InputOperation : public virtual CounterBasedOperation
virtual void set_min_pulse_width( double _min_pulse_width_seconds );
/**
* Configure hardware with all predefined parameters
* Configure hardware with all predefined parameters.
*/
virtual void configure (void) = 0;
......
......@@ -332,6 +332,21 @@ namespace ni{
toggle = DAQmx_Val_Toggle
}BehaviorType;
/**
* Event type for callback function.
*/
typedef enum
{
/**
* Acquisition event type.
*/
intoBuffer = DAQmx_Val_Acquired_Into_Buffer,
/**
* Generation event type.
*/
fromBuffer = DAQmx_Val_Transferred_From_Buffer
}CBEventType;
}//namespace ni
#endif // _NI_H_
......@@ -53,7 +53,7 @@ namespace ni660Xsl
*/
virtual void add_angular_encoder(ni660Xsl::AngularEncoderChan _chan) throw (ni660Xsl::DAQException);
/**
* Configure hardware with all predefined parameters
* Configure hardware with all predefined parameters.
*/
virtual void configure (void) = 0;
protected:
......
......@@ -33,7 +33,8 @@ strategy_(ni::abort),
start_point_(ni::current_read_position),
offset_(0),
timeout_(1.0),
mode_(ni::continuous)
mode_(ni::continuous),
use_callback_(false)
{
}
// ============================================================================
......@@ -96,6 +97,13 @@ void BufferedAcquisition::set_read_start_point(ni::StartPointType _start_point,
this->offset_ = _offset;
}
// ============================================================================
// BufferedAcquisition::set_callback_mode
// ============================================================================
void BufferedAcquisition::set_callback_mode(bool _enabled)
{
this->use_callback_ = _enabled;
}
// ============================================================================
// BufferedAcquisition::get_raw_buffer
// ============================================================================
void BufferedAcquisition::get_raw_buffer(void)
......@@ -159,7 +167,7 @@ throw (ni660Xsl::DAQException)
this->handle_timeout();
delete rb;
}
//----------handle others errors---------------------------------------
//----------handle other errors---------------------------------------
else if(err < 0)
{
delete rb;
......
......@@ -22,16 +22,27 @@
namespace ni660Xsl
{
/*int32 CVICALLBACK BufferedEventCountingCallback (TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
// ============================================================================
// raw_buffer_callback
//
// Callback function for buffered acquisition.
// @param _taskHandle NI task handler.
// @param _evt_type Event type associated to the callback function.
// @param _samples Number of samples of the buffer.
// @param _data Callback data pointer.
// ============================================================================
int32 CVICALLBACK raw_buffer_callback(ni::DAQTaskHandle _taskHandle,
int32 _evt_type,
uInt32 _samples,
void *_data)
{
//std::cout << "raw_buffer_callback() entering..." << std::endl;
std::cout <<"=-------------------------------------------------------------------" << std::endl;
std::cout << "Before get_raw_buffer from callback, for task handle: "<< taskHandle << std::endl;
reinterpret_cast<BufferedEventCounting*>(callbackData)->get_raw_buffer();
std::cout << "After get_raw_buffer from callback." << std::endl;
// call internal function to read data from board
reinterpret_cast<BufferedEventCounting*>(_data)->get_raw_buffer();
return 0;
}*/
}
// ============================================================================
// BufferedEventCounting::BufferedEventCounting
......@@ -40,8 +51,8 @@ BufferedEventCounting::BufferedEventCounting()
:EventCounting(),
BufferedAcquisition()
{
//std::cout<<<<"BufferedEventCounting::BufferedEventCounting"<<std::endl;
}
// ============================================================================
// BufferedEventCounting::~BufferedEventCounting
// ============================================================================
......@@ -49,13 +60,16 @@ BufferedEventCounting::~BufferedEventCounting()
{
//std::cout<<"BufferedEventCounting::~BufferedEventCounting"<<std::endl;
}
// ============================================================================
// BufferedEventCounting::configure
// ============================================================================
void BufferedEventCounting::configure(void) throw (ni660Xsl::DAQException)
void BufferedEventCounting::configure(void)
throw (ni660Xsl::DAQException)
{
//std::cout<<<<"BufferedEventCounting::configure<-"<<std::endl;
//-------------------------configure channel------------------------------------------
try
{
this->configure_channel();
......@@ -69,20 +83,57 @@ void BufferedEventCounting::configure(void) throw (ni660Xsl::DAQException)
throw DAQException();
}
//-------------------------configure timing------------------------------------------
const char* clk = this->sample_clk_.c_str();
int err = DAQmxCfgSampClkTiming(this->task_handle_, clk, this->max_rate_,
this->active_edge_, this->mode_, this->nb_samples_);
if (err < 0)
{
throw ni660Xsl::DAQException("Timing configuration failed!",
this->get_string_error(),
"BufferedEventCounting::configure()",
err);
}
else if (err > 0)
{
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
if (this->use_callback_)
{
//-------------------------Register callback event-------------------------------
//- Register a callback which will be called when the number of sample will be acquired
/*int err = DAQmxRegisterEveryNSamplesEvent (this->task_handle_, DAQmx_Val_Acquired_Into_Buffer , this->nb_samples_,
0, &BufferedEventCountingCallback, static_cast<void*> (this));*/
//- Register a callback which will be called when the number of samples will be acquired.
err = DAQmxRegisterEveryNSamplesEvent(this->task_handle_, ni::intoBuffer,
this->nb_samples_, 0, raw_buffer_callback,
static_cast<void*> (this));
if (err < 0)
{
throw ni660Xsl::DAQException("callback configuration failed!",
this->get_string_error(),
"BufferedEventCounting::configure()",
err);
}
else if (err > 0)
{
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
}
if (this->use_callback_)
{
//-------------------------reset acquisition buffer-------------------------------------------
err = DAQmxResetBufInputBufSize(this->task_handle_);
//-------------------------config timing------------------------------------------
const char* clk = this->sample_clk_.c_str();
int err = DAQmxCfgSampClkTiming(this->task_handle_, clk, this->max_rate_, this->active_edge_, this->mode_, this->nb_samples_);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Buffer reset failed!",
this->get_string_error(),
"BufferedEventCounting::configure",
"BufferedEventCounting::configure()",
err);
}
else if (err > 0)
......@@ -90,13 +141,16 @@ void BufferedEventCounting::configure(void) throw (ni660Xsl::DAQException)
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
//-------------------------config buffer-------------------------------------------
}
//-------------------------configure acquisition buffer-------------------------------------------
err = DAQmxCfgInputBuffer(this->task_handle_, this->nb_samples_);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Buffer configuration failed!",
this->get_string_error(),
"BufferedEventCounting::configure",
"BufferedEventCounting::configure()",
err);
}
else if (err > 0)
......@@ -104,13 +158,15 @@ void BufferedEventCounting::configure(void) throw (ni660Xsl::DAQException)
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
//---------------------config read start point-----------------------------------
//---------------------configure read start point-----------------------------------
err = DAQmxSetReadRelativeTo(this->task_handle_, this->start_point_);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Start point configuration failed!",
this->get_string_error(),
"BufferedEventCounting::configure",
"BufferedEventCounting::configure()",
err);
}
else if (err > 0)
......@@ -119,12 +175,14 @@ void BufferedEventCounting::configure(void) throw (ni660Xsl::DAQException)
this->warn_occured_ = true;
}
//-------------------------configure offset-------------------------------
err = DAQmxSetReadOffset(this->task_handle_, this->offset_);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Offset configuration failed!",
this->get_string_error(),
"BufferedEventCounting::configure",
"BufferedEventCounting::configure()",
err);
}
else if (err > 0)
......@@ -132,16 +190,18 @@ void BufferedEventCounting::configure(void) throw (ni660Xsl::DAQException)
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
//-------------------------config tc------------------------------------------
//-------------------------configure tc------------------------------------------
if( this->terminal_.size() != 0)
{
const char* term = this->terminal_.c_str();
err = DAQmxSetExportedCtrOutEventOutputTerm(this->task_handle_, term);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Output term configuration failed!",
this->get_string_error(),
"BufferedEventCounting::configure",
"BufferedEventCounting::configure()",
err);
}
else if (err > 0)
......@@ -149,12 +209,14 @@ void BufferedEventCounting::configure(void) throw (ni660Xsl::DAQException)
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
err = DAQmxSetExportedCtrOutEventOutputBehavior(this->task_handle_, this->behavior_);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Output behaviour configuration failed!",
this->get_string_error(),
"BufferedEventCounting::configure",
"BufferedEventCounting::configure()",
err);
}
else if (err > 0)
......@@ -164,17 +226,17 @@ void BufferedEventCounting::configure(void) throw (ni660Xsl::DAQException)
}
}
//-------------------------config trigger------------------------------------------
//-------------------------configure start trigger------------------------------------------
if (use_start_trig_)
{
//config trigger to be arm start trig
// configure trigger to be a "arm start trig"
int err = DAQmxSetArmStartTrigType(this->task_handle_, DAQmx_Val_DigEdge);
if(err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Start trigger configuration failed!",
this->get_string_error(),
"BufferedEventCounting::configure",
"BufferedEventCounting::configure()",
err);
}
else if(err > 0)
......@@ -183,14 +245,16 @@ void BufferedEventCounting::configure(void) throw (ni660Xsl::DAQException)
this->warn_occured_ = true;
}
//config trigger pin
// configure trigger pin
const char* s = this->start_trigger_source_.c_str();
err = DAQmxSetDigEdgeArmStartTrigSrc(this->task_handle_, s);
if(err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Start trigger src configuration failed!",
this->get_string_error(),
"BufferedEventCounting::configure",
"BufferedEventCounting::configure()",
err);
}
else if (err > 0)
......@@ -199,13 +263,14 @@ void BufferedEventCounting::configure(void) throw (ni660Xsl::DAQException)
this->warn_occured_ = true;
}
//config edge
// configure edge
err = DAQmxSetDigEdgeArmStartTrigEdge(this->task_handle_, this->trig_active_edge_);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Start trigger edge configuration failed!",
this->get_string_error(),
"BufferedEventCounting::configure",
"BufferedEventCounting::configure()",
err);
}
else if (err > 0)
......@@ -214,14 +279,16 @@ void BufferedEventCounting::configure(void) throw (ni660Xsl::DAQException)
this->warn_occured_ = true;
}
}
//---------------------config autostart------------------------------------------------
//---------------------configure autostart------------------------------------------------
//to call get_buffer() does not start the acquisition.
err = DAQmxSetReadAutoStart(this->task_handle_, FALSE);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Autostart configuration failed!",
this->get_string_error(),
"BufferedEventCounting::configure",
"BufferedEventCounting::configure()",
err);
}
else if (err > 0)
......@@ -229,13 +296,15 @@ void BufferedEventCounting::configure(void) throw (ni660Xsl::DAQException)
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
//---------------------config read mode-----------------------------------------------
//---------------------configure read mode-----------------------------------------------
err = DAQmxSetReadWaitMode(this->task_handle_, this->read_mode_);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("read mode configuration failed!",
this->get_string_error(),
"BufferedEventCounting::configure");
"BufferedEventCounting::configure()");
}
else if (err > 0)
{
......@@ -257,7 +326,6 @@ void BufferedEventCounting::configure(void) throw (ni660Xsl::DAQException)
throw DAQException();
}
//std::cout<<<<"BufferedEventCounting::configure->"<<std::endl;
}
......
......@@ -20,6 +20,29 @@
namespace ni660Xsl
{
// ============================================================================
// scaled_buffer_callback
//
// Callback function for buffered acquisition.
// @param _taskHandle NI task handler.
// @param _evt_type Event type associated to the callback function.
// @param _samples Number of samples of the buffer.
// @param _data Callback data pointer.
// ============================================================================
int32 CVICALLBACK scaled_buffer_callback(ni::DAQTaskHandle _taskHandle,
int32 _evt_type,
uInt32 _samples,
void *_data)
{
//std::cout << "scaled_buffer_callback() entering..." << std::endl;
// call internal function to read data from board
reinterpret_cast<BufferedPositionMeasurement*>(_data)->get_scaled_buffer();
return 0;
}
// ============================================================================
// BufferedPositionMeasurement::BufferedPositionMeasurement
// ============================================================================
......@@ -28,20 +51,23 @@ BufferedPositionMeasurement::BufferedPositionMeasurement()
BufferedAcquisition()
{
}
// ============================================================================
// BufferedPositionMeasurement::~BufferedPositionMeasurement
// ============================================================================
BufferedPositionMeasurement::~BufferedPositionMeasurement()
{
}
// ============================================================================
// BufferedPositionMeasurement::configure
// ============================================================================
void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException)
void BufferedPositionMeasurement::configure (void)
throw (ni660Xsl::DAQException)
{
//std::cout<<<<"BufferedPositionMeasurement::configure<-"<<std::endl;
//-------------------------configure channel------------------------------------------
try
{
this->configure_channel();
......@@ -54,15 +80,19 @@ void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException
{
throw DAQException();
}
//-------------------------config timing------------------------------------------
//-------------------------configure timing------------------------------------------
//std::cout<<<<"BufferedPositionMeasurement::config timing"<<std::endl;
const char* clk = this->sample_clk_.c_str();
int err = DAQmxCfgSampClkTiming(this->task_handle_, clk, this->max_rate_, this->active_edge_, this->mode_, this->nb_samples_);
int err = DAQmxCfgSampClkTiming(this->task_handle_, clk, this->max_rate_,
this->active_edge_, this->mode_, this->nb_samples_);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Timing configuration failed!",
this->get_string_error(),
"BufferedPositionMeasurement::configure",
"BufferedPositionMeasurement::configure()",
err);
}
else if (err > 0)
......@@ -70,14 +100,57 @@ void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
//-------------------------config buffer-------------------------------------------
if (this->use_callback_)
{
//-------------------------Register callback event-------------------------------
//- Register a callback which will be called when the number of samples will be acquired.
err = DAQmxRegisterEveryNSamplesEvent(this->task_handle_, ni::intoBuffer,
this->nb_samples_, 0, scaled_buffer_callback,
static_cast<void*> (this));
if (err < 0)
{
throw ni660Xsl::DAQException("callback configuration failed!",
this->get_string_error(),
"BufferedPositionMeasurement::configure()",
err);
}
else if (err > 0)
{
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
}
if (this->use_callback_)
{
//-------------------------reset acquisition buffer-------------------------------------------
err = DAQmxResetBufInputBufSize(this->task_handle_);
if (err < 0)
{
throw ni660Xsl::DAQException("Buffer reset failed!",
this->get_string_error(),
"BufferedPositionMeasurement::configure()",
err);
}
else if (err > 0)
{
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
}
//-------------------------configure buffer-------------------------------------------
//std::cout<<<<"BufferedPositionMeasurement::config buffer"<<std::endl;
err = DAQmxCfgInputBuffer(this->task_handle_, this->nb_samples_);
if(err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Buffer configuration failed",
this->get_string_error(),
"BufferedPositionMeasurement::configure",
"BufferedPositionMeasurement::configure()",
err);
}
else if (err > 0)
......@@ -85,16 +158,18 @@ void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
//-------------------------config trigger------------------------------------------
//-------------------------configure start trigger------------------------------------------
if (use_start_trig_)
{
//config trigger to be arm start trig
//config trigger to be a "arm start trig"
int err = DAQmxSetArmStartTrigType(this->task_handle_, DAQmx_Val_DigEdge);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Start trigger configuration failed!",
this->get_string_error(),
"BufferedPositionMeasurement::configure",
"BufferedPositionMeasurement::configure()",
err);
}
else if (err > 0)
......@@ -103,14 +178,14 @@ void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException
this->warn_occured_ = true;
}
//config trigger pin
// configure trigger pin
const char* s = this->start_trigger_source_.c_str();
err = DAQmxSetDigEdgeArmStartTrigSrc(this->task_handle_, s);
if(err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Start trigger src configuration failed!",
this->get_string_error(),
"BufferedPositionMeasurement::configure",
"BufferedPositionMeasurement::configure()",
err);
}
else if (err > 0)
......@@ -119,13 +194,14 @@ void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException
this->warn_occured_ = true;
}
//config edge
// configure edge
err = DAQmxSetDigEdgeArmStartTrigEdge(this->task_handle_, this->trig_active_edge_);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Start trigger edge configuration failed!",
this->get_string_error(),
"BufferedPositionMeasurement::configure",
"BufferedPositionMeasurement::configure()",
err);
}
else if (err > 0)
......@@ -134,13 +210,15 @@ void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException
this->warn_occured_ = true;
}
}
//---------------------config read start point-----------------------------------
//---------------------configure read start point-----------------------------------
err = DAQmxSetReadRelativeTo(this->task_handle_, this->start_point_);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Start point configuration failed!",
this->get_string_error(),
"BufferedPositionMeasurement::configure",
"BufferedPositionMeasurement::configure()",
err);
}
else if (err > 0)
......@@ -149,12 +227,14 @@ void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException
this->warn_occured_ = true;
}
//---------------------configure offset-----------------------------------
err = DAQmxSetReadOffset(this->task_handle_, this->offset_);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Offset configuration failed!",
this->get_string_error(),
"BufferedPositionMeasurement::configure",
"BufferedPositionMeasurement::configure()",
err);
}
else if (err > 0)
......@@ -162,16 +242,18 @@ void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
//-------------------------config tc------------------------------------------
//-------------------------configure tc------------------------------------------
if( this->terminal_.size() != 0)
{
const char* term = this->terminal_.c_str();
err = DAQmxSetExportedCtrOutEventOutputTerm(this->task_handle_, term);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Term configuration failed!",
this->get_string_error(),
"BufferedPositionMeasurement::configure",
"BufferedPositionMeasurement::configure()",
err);
}
else if (err > 0)
......@@ -179,10 +261,12 @@ void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
err = DAQmxSetExportedCtrOutEventOutputBehavior(this->task_handle_, this->behavior_);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("term behaviour configuration failed()",
this->get_string_error(),
"BufferedPositionMeasurement::configure",
err);
......@@ -207,15 +291,17 @@ void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException
}*/
}
//---------------------config autostart------------------------------------------
//---------------------configure autostart------------------------------------------
//to call get_buffer() does not start the acquisition.
err = DAQmxSetReadAutoStart(this->task_handle_, FALSE);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Autostart configuration failed!",
this->get_string_error(),
"BufferedPositionMeasurement::configure",
"BufferedPositionMeasurement::configure()",
err);
}
else if (err > 0)
......@@ -223,13 +309,15 @@ void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
//---------------------config read mode-----------------------------------------------
//---------------------configure read mode-----------------------------------------------
err = DAQmxSetReadWaitMode(this->task_handle_, this->read_mode_);
if (err < 0)
{
throw ni660Xsl::DAQException("configuration failed",
throw ni660Xsl::DAQException("Read mode configuration failed!",
this->get_string_error(),
"BufferedEventCounting::configure",
"BufferedEventCounting::configure()",
err);
}
else if (err > 0)
......@@ -237,6 +325,7 @@ void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException
this->warn_ = this->get_string_error();
this->warn_occured_ = true;
}
//---------------------get task ready to start------------------------------------------------
try
{
......@@ -252,7 +341,6 @@ void BufferedPositionMeasurement::configure (void) throw (ni660Xsl::DAQException
}
//std::cout<<<<"BufferedPositionMeasurement::configure->"<<std::endl;
}
}//namespace
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment