#include <iostream>
#include <stdio.h>
#include <thread>
#include "libvkdaq.h"
#define CH_NAME "dev1/AOUT1"
#define PI 3.14159265358979323846
#define SAMPLING_FREQUENCY 10000
#define WAVE_AMPLITUDE 1
#define WAVE_FREQUENCY 10
#define WAVE_PHASE 0
#define WAVE_OFFSET 0
#define DAQmxFailed(error) ((error)<0)
#define VkDaqErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
int main(int argc, char* argv[])
{
int i = 0;
int ret = 0;
int32_t error = 0;
const char* taskHandle = "VkDaqTaskHandledac";
double* data = new double[SAMPLING_FREQUENCY];
double phase_rad = WAVE_PHASE * PI / 180.0;
double step = 2.0 * PI * WAVE_FREQUENCY / SAMPLING_FREQUENCY;
int value = WAVE_AMPLITUDE;
for (int i = 0; i < SAMPLING_FREQUENCY; ++i)
{
double theta = step * i + phase_rad;
double sin_v = WAVE_AMPLITUDE * sin(theta) + WAVE_OFFSET;
data[i] = sin_v;
}
VkDaqErrChk(
VkDaqCfgSampClkTiming(taskHandle, VkDaq_Val_ClkSrc_OnBoardClk,SAMPLING_FREQUENCY, 0,VkDaq_Val_ContSamps, SAMPLING_FREQUENCY));
printf("StartTask success.\n");
printf("Start continuous DAC output...\n");
while (true)
{
while (ret < 0) {
}
value++;
if (value == 4) {
value = 1;
}
for (int i = 0; i < SAMPLING_FREQUENCY; ++i)
{
double theta = step * i + phase_rad;
double sin_v = value * sin(theta) + WAVE_OFFSET;
data[i] = sin_v;
}
}
printf("Generate success\n");
Error:
if (DAQmxFailed(error))
if (taskHandle != 0) {
}
delete[] data;
printf("End of program, press Enter key to quit\n");
getchar();
return 0;
}
int32_t VkDaqClearTask(const char *task)
Clear task.
int32_t VkDaqCreateAOVoltageChan(const char *task, const char *chans, const char *reserved1, double minVal, double maxVal, int32_t units, const char *reserved2)
Create DAC channel.
int32_t VkDaqCreateTask(const char *task)
Create task.
int32_t VkDaqStartTask(const char *task)
Start task.
int32_t VkDaqStopTask(const char *task)
Stop task.
int32_t VkDaqSetTaskStreamData(const char *task, const double dat[], int32_t sampsPerChan, int32_t fillmode, int32_t autoStart, int32_t stopAt, double timeout)
Set task data.
const char * VkDaqGetLastErrorInfo(void)
Get the error message of the last execution.
int32_t VkDaqCfgSampClkTiming(const char *task, int32_t source, double samplingFrequency, int32_t reserved, int32_t sampleMode, int32_t sampsPerChanToAcquire)
Set the source of the sampling clock, the rate of the sampling clock, and the number of samples to be...