Hello
I have created C++ code in visual studio for the purpose of implementing it into my UE5 programme but have been running into errors when I have tried to implement it into my actor class. I have been told to create a plugin and execute the code that way but I am pretty new to C++ coding in unreal so I wanted to ask the best way to go about this issue.
The code I made is here:
#include
#include <stdio.h>
#include <NIDAQmx.h>
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void* callbackData);
int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void* callbackData);
int main(void)
{
int32 error = 0;
TaskHandle taskHandle = 0;
char errBuff[2048] = { ‘\0’ };
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk(DAQmxCreateTask("", &taskHandle));
DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai0", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));
DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle, "", 10000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 1000));
DAQmxErrChk(DAQmxCfgDigEdgeStartTrig(taskHandle, "/Dev1/PFI1", DAQmx_Val_Rising));
DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(taskHandle, DAQmx_Val_Acquired_Into_Buffer, 1000, 0, EveryNCallback, NULL));
DAQmxErrChk(DAQmxRegisterDoneEvent(taskHandle, 0, DoneCallback, NULL));
/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk(DAQmxStartTask(taskHandle));
printf("Acquiring samples continuously. Press Enter to interrupt\n");
getchar();
Error:
if (DAQmxFailed(error))
DAQmxGetExtendedErrorInfo(errBuff, 2048);
if (taskHandle != 0) {
//
// DAQmx Stop Code
//
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}
if (DAQmxFailed(error))
printf(“DAQmx Error: %s\n”, errBuff);
printf(“End of program, press Enter key to quit\n”);
getchar();
return 0;
}
int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void* callbackData)
{
int32 error = 0;
char errBuff[2048] = { ‘\0’ };
static int totalRead = 0;
int32 read = 0;
float64 data[1000];
/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk(DAQmxReadAnalogF64(taskHandle, 1000, 10.0, DAQmx_Val_GroupByScanNumber, data, 1000, &read, NULL));
if (read > 0) {
printf("Acquired %d samples. Total %d\r", (int)read, (int)(totalRead += read));
DAQmxStopTask(taskHandle);
fflush(stdout);
DAQmxErrChk(DAQmxStartTask(taskHandle));
}
Error:
if (DAQmxFailed(error)) {
DAQmxGetExtendedErrorInfo(errBuff, 2048);
//
// DAQmx Stop Code
//
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
printf(“DAQmx Error: %s\n”, errBuff);
}
return 0;
}
int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void* callbackData)
{
int32 error = 0;
char errBuff[2048] = { ‘\0’ };
// Check to see if an error stopped the task.
DAQmxErrChk(status);
Error:
if (DAQmxFailed(error)) {
DAQmxGetExtendedErrorInfo(errBuff, 2048);
DAQmxClearTask(taskHandle);
printf(“DAQmx Error: %s\n”, errBuff);
}
return 0;
}
Once I go into the lab I will discuss the errors but I am posting this question now just to be directed in a certain direction before working on it so I know I’m going on the right track.
Any advice would be appreciated.