| libvkdaq VKINGING DAQ Library API Reference |

Loading...
Searching...
No Matches
Continuous output of any waveform
Temporary task flow chart

Note
  Steps:
  1.Create task. VkDaqCreateTask
  2.Create analog output channel VkDaqCreateAIAccelChan
  3.Set sampling clock VkDaqCfgSampClkTiming
  4.Start task VkDaqStartTask
  5.Continuously set task data for any waveform VkDaqSetTaskStreamData
  6.Stop task VkDaqStopTask
  7.Clear task VkDaqClearTask
  Note:
  1. When setting waveform data in a loop, the number of waveform points set should be consistent with the clock frequency. Please refer to the SAMPLING-FREQUEncy parameter in the C Language Reference below. When setting waveform data continuously in a loop, the return value should be ≥ 0. Otherwise, it needs to be re uploaded until ≥ 0

Example of Continuous output of any waveform Process Diagram

C language reference
#include <iostream>
#include <stdio.h>
#include <thread>
#include "libvkdaq.h"
#define CH_NAME "dev1/AOUT1"
#define PI 3.14159265358979323846
#define SAMPLING_FREQUENCY 10000 //1~99200
#define WAVE_AMPLITUDE 1 //0~9
#define WAVE_FREQUENCY 10
#define WAVE_PHASE 0 //0~360
#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";
// Sin Wave
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;
}
// VkDaq Configure Code
VkDaqErrChk(VkDaqCreateTask(taskHandle));
VkDaqErrChk(VkDaqCreateAOVoltageChan(taskHandle, CH_NAME, "", -9, 9, VkDaq_Val_Volts, ""));
VkDaqErrChk(VkDaqCfgSampClkTiming(taskHandle, VkDaq_Val_ClkSrc_OnBoardClk,SAMPLING_FREQUENCY, 0,VkDaq_Val_ContSamps, SAMPLING_FREQUENCY));
VkDaqErrChk(VkDaqStartTask(taskHandle));
printf("StartTask success.\n");
printf("Start continuous DAC output...\n");
while (true)
{
// VkDaq Write Code
ret = VkDaqSetTaskStreamData(taskHandle,data,SAMPLING_FREQUENCY,0,1,0,1);
// The return value of the function is less than 0, and the data needs to be uploaded again.
// Until there is space in the buffer, the upload is successful, and the function returns a value greater than 0
while (ret < 0) {
ret = VkDaqSetTaskStreamData(taskHandle, data, SAMPLING_FREQUENCY, 0, 1, 0, 1);
}
//change Sin Wave
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))
printf("VkDaq Error: %s\n", VkDaqGetLastErrorInfo());
if (taskHandle != 0) {
VkDaqStopTask(taskHandle);
VkDaqClearTask(taskHandle);
}
delete[] data;
printf("End of program, press Enter key to quit\n");
getchar();
return 0;
}
VkDaqClearTask
int32_t VkDaqClearTask(const char *task)
Clear task.
VkDaqCreateAOVoltageChan
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.
VkDaqCreateTask
int32_t VkDaqCreateTask(const char *task)
Create task.
VkDaqStartTask
int32_t VkDaqStartTask(const char *task)
Start task.
VkDaqStopTask
int32_t VkDaqStopTask(const char *task)
Stop task.
VkDaqSetTaskStreamData
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.
VkDaqGetLastErrorInfo
const char * VkDaqGetLastErrorInfo(void)
Get the error message of the last execution.
VkDaqCfgSampClkTiming
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...