11-01-2018 03:45 AM
Use the following DLL file.
When you program as shown in the picture, other functions function normally and display the value.
However,
typedef struct {unsigned int channel;
unsigned short pbuf [128];
unsigned int len;
} lv_data_cb_params;
It does not work.
Programs and photos will be uploaded.
I do not know if pbuf seems to be a problem.
Solved! Go to Solution.
11-01-2018 05:26 AM - edited 11-01-2018 05:29 AM
I do not feel comfortable to run your .dll on my computer.
but... what does your .dll suppose to do?
I face some situation where the value in the structure need to be the same size... U16 all or U32 all.
Benoit
11-01-2018 06:31 AM - edited 11-01-2018 06:32 AM
You can NOT create a C data structure like that and hope that it will match the LabVIEW cluster! LabVIEW arrays are variable sized handles! Always!!
Your C data structure that you would need to pass to the LVPostUserEvent() function should be declared like this:
#include "lv_prolog.h" struct { int32 len; uint16_t elm[1]; } DataBufferRec, **DataBufferHandle; struct { uint32_t channel: DataBufferHandle buf; } EventRecord;
#include "lv_epilog.h"
Before passing the pointer to that struct to LVPostUserEvent() function you have to allocate the handle using one of the LabVIEW memory manager functions like DSNewHandle() or NumericArrayResize(). I would recommend to use the latter. Then fill in the data and make sure to set the len parameter inside it accordingly. After LVPostUserEvent() returns you retain ownership of that handle since LVPostUserEvent() made a copy of the entire data structure according to the data type of the event. You can either store the handle somewhere for reuse later (and should deallocate it using DSDisposeHandle() before your library unloads) or you can immediately deallocate it.
And since the length information for the number of elements in the array is maintained inside the handle you can remove the len integer in your cluster to make the cluster match the C data structure as shown above.
11-01-2018 07:04 AM
And in your VI the first call to lv_pkt_reg_data_cb_event_ref() is totally wrong. You pass in the data cluster itself, while later on you pass in the event refnum. That simply can't be right!
The second one likes to be what you want as you somehow have to pass in the user event refnum to the DLL, but then the first call simply MUST crash.
11-01-2018 09:57 AM
This white paper describes how LabVIEW is going to store data in memory and, as rolfk mentioned, LabVIEW and C are going to need to match.
https://zone.ni.com/reference/en-XX/help/371361H-01/lvconcepts/how_labview_stores_data_in_memory/
An alternative to what rolfk suggested is to just create a wrapper function which takes in the elements individually and packs them into a struct in C.
11-01-2018 10:35 AM
@Jacobson-ni wrote:
An alternative to what rolfk suggested is to just create a wrapper function which takes in the elements individually and packs them into a struct in C.
Except that for LVPostUserEvent() you need to create a fully LabVIEW compatible data structure whose type matches 100% the format of the event datatype, to pass to that function.
11-01-2018 01:07 PM
@rolfk wrote:
@Jacobson-ni wrote:
An alternative to what rolfk suggested is to just create a wrapper function which takes in the elements individually and packs them into a struct in C.
Except that for LVPostUserEvent() you need to create a fully LabVIEW compatible data structure whose type matches 100% the format of the event datatype, to pass to that function.
Sure, I wasn't even really thinking about the user event portion.
11-02-2018 12:46 AM
Thanks for answering.
So, can you change or add the DLL file to the structure that you gave it?
11-02-2018 05:35 AM
@blackshin wrote:
Thanks for answering.
So, can you change or add the DLL file to the structure that you gave it?
Sorry, but I'm not really understanding what you are asking here.
Can someone change the DLL to do it right? Absolutely!
Can you do it? Maybe!
Can I do it? Definitely, but it is your problem not mine.