Hello
I’ve created this Cpp programme where each time I press a button on my trigger device, an output log will be written, but I want to be able to create an event output as if this button is a key on a keyboard. I have created the function TriggerOccured but it’s not triggering for some reason. I’ll attach the code below:
MyActor.h
#pragma once
#include “CoreMinimal.h”
#include “ghc.h”
#include “GameFramework/Actor.h”
#include “MyActor.generated.h”
UCLASS()
class GHC_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor’s properties
AMyActor();
void PedalTrig();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UFUNCTION(BlueprintImplemenTableEvent)
void TriggerOccur();
};
MyActor.cpp
#include “MyActor.h”
#include “Logging/LogMacros.h”
TaskHandle taskHandle1 = 0;
int32 read1 = 0;
float64 data1[1000];
int totalRead1 = 0;
int32 CVICALLBACK EveryNCallback1(TaskHandle taskHandle_, int32 everyNsamplesEventType, uInt32 nSamples, void* callbackData);
int32 CVICALLBACK DoneCallback1(TaskHandle taskHandle_, int32 status, void* callbackData);
void PedalTrig();
// Sets default values
AMyActor::AMyActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;
}
void AMyActor::PedalTrig() {
TriggerOccur();
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
DAQmxCreateTask(“”, &taskHandle1);
(DAQmxCreateAIVoltageChan(taskHandle1, “Dev1/ai0”, “”, DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));
(DAQmxCfgSampClkTiming(taskHandle1, “”, 10000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 1000));
(DAQmxCfgDigEdgeStartTrig(taskHandle1, “/Dev1/PFI1”, DAQmx_Val_Rising));
(DAQmxRegisterEveryNSamplesEvent(taskHandle1, DAQmx_Val_Acquired_Into_Buffer, 1000, 0, EveryNCallback1, NULL));
(DAQmxRegisterDoneEvent(taskHandle1, 0, DoneCallback1, NULL));
(DAQmxStartTask(taskHandle1));
return;
}
// Called every frame
void AMyActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
int32 CVICALLBACK EveryNCallback1(TaskHandle taskHandle_, int32 everyNsamplesEventType, uInt32 nSamples, void* callbackData)
{
(DAQmxReadAnalogF64(taskHandle_, 1000, 10.0, DAQmx_Val_GroupByScanNumber, data1, 1000, &read1, NULL));
UE_LOG(LogTemp, Log, TEXT(“Value = %f”), 1);
void PedalTrig();
if (read1 > 0) {
/*if (Scrnsht1) {
if (Scrnsht2) {
if (Scrnsht3) {
UE_LOG(LogTemp, Log, TEXT("Commence Path Planning"), 1);
}
else {
Scrnsht3 = true;
}
}
else {
Scrnsht2 = true;
}
}
else {
Scrnsht1 = true;
}
UE_LOG(LogTemp, Warning, TEXT("Boolean 2 is %s"), Scrnsht2 ? TEXT("true") : TEXT("false"));*/
DAQmxStopTask(taskHandle_);
fflush(stdout);
(DAQmxStartTask(taskHandle_));
}
return 0;
}
int32 CVICALLBACK DoneCallback1(TaskHandle taskHandle_, int32 status, void* callbackData)
{
//Check to see if an error stopped the task.
DAQmxClearTask(taskHandle_);
return 0;
}
If you don’t understand the NI-DAQmx code thats fine. All you have to know is when i press the trigger button, the code goes to the EveryNCallback1 function where a UE_LOG occurs and the PedalTrig() function should be causing the event but it doesn’t.
Any help would be appreciated