LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Receive and read DVR Using DLL

HI ,

I am working on a LabVIEW project that involves calling a custom C++ DLL function to process an array in place.so I made a sample program for my project and the goal is to pass an EDVR, process the data within the DLL, and then return the modified array back to LabVIEW for further use within an In Place Element structure. I am encountering issues and receiving Error 1097 in LabVIEW.

#include "extcode.h"
#include <stdint.h>

#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif

extern "C" {

// LabVIEW array handle definition for unsigned 8-bit integers
typedef struct {
int32_t cnt;
uint8_t bytes[1];
} LVArray_U8;

typedef LVArray_U8** LVArrayHandle_U8;

DLLEXPORT int32_t processArray(LVArrayHandle_U8* handle) {
if (handle == NULL || *handle == NULL) {
return -1; // Error: NULL pointer received
}

// Get the pointer to the actual data
LVArrayHandle_U8 actualHandle = *handle;
if (actualHandle == NULL || *actualHandle == NULL) {
return -2; // Error: NULL data in handle
}

uint8_t* data = (*actualHandle)->bytes;
int32_t dataLen = (*actualHandle)->cnt;

// Process the data: add 10 to each element
for (int32_t i = 0; i < dataLen; ++i) {
data[i] += 10;
}

// Return success code
return 0;
}

}

MA60010_0-1716975521281.png

 

I am receiving Error 1097 when calling the DLL function from LabVIEW. I suspect the issue might be related to the configuration of the Call Library Function Node or the handling of the DVR in LabVIEW.

Could you please provide guidance or an example on how to correctly configure the Call Library Function Node and handle the DVR to ensure the data is processed correctly within the DLL and returned to LabVIEW?

Thank you for your assistance!

0 Kudos
Message 1 of 3
(354 Views)

You are treating the DVR like an array, but it is something completely different. You can find this out by choosing "adapt to type" in the call library node, then right click on it and select "create c code". The created file shows you what data type will be passed to the function.

 

A DVR is passed as an LVRefNum and there is little documentation on how to use that. There is some documenation about using EDVRs in the GPU toolkit, but to my knowledge no one published a working example. This thread is the closest I know of https://forums.ni.com/t5/LabVIEW/Creating-EXTERNAL-data-value-references/m-p/3873039.

 

If you wire the array to the call library node, you have to set the parameter to "adapt to type" and data format to "pointers to handles". You could also change your function definition to `int32_t processArray(LVArrayHandle_U8 handle)` and use "handles by value".

 

If you want to take a deep dive, look here 😉 https://forums.ni.com/t5/LabVIEW/Creating-a-DLL-to-work-on-2D-Arrays/td-p/4373163

 

Message 2 of 3
(294 Views)

Hi ,

Thank you for your prompt and helpful response. I appreciate the guidance on handling the array directly with the DLL and it worked successfully.

#include "extcode.h"
#include <stdint.h>

#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif

extern "C" {

// LabVIEW array handle definition for unsigned 8-bit integers
typedef struct {
int32_t cnt;
uint8_t bytes[1];
} LVArray_U8;

typedef LVArray_U8** LVArrayHandle_U8;

DLLEXPORT int32_t processArray(LVArrayHandle_U8 handle) {
if (handle == NULL || *handle == NULL) {
return -1; // Error: NULL pointer received
}

uint8_t* data = (*handle)->bytes;
int32_t dataLen = (*handle)->cnt;

for (int32_t i = 0; i < dataLen; ++i) {
data[i] += 10;
}

return 0;
}

}

MA60010_0-1717062313269.png


The sample program was a simplified version of my actual project. In the actual project, I need to handle a large amount of data—specifically, 24MB of data every 33ms. This high-frequency data processing is causing performance issues, and I suspect that passing around such a large array is contributing to the problem. My goal was to use Data Value References (DVRs) to efficiently manage and process this large data set by passing a reference instead of the entire array, hoping to reduce execution time.

Given this context, I was trying to pass the array as a DVR to the DLL for in-place processing to avoid the overhead of copying large amounts of data. If there are alternative strategies or best practices for efficiently handling and processing such large data sets in LabVIEW with DLLs, I would greatly appreciate any further advice or examples you might have.

Thank you again for your assistance and for pointing me to useful resources.

Best regards,
Maharaja Abishek A

 

0 Kudos
Message 3 of 3
(267 Views)