LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

pointer to array

Hello,

I'm trying to find out how to define an array, and send a pointer to it.
In other words: I've imported a DLL (written in C++), and one of its functions needs a pointer to an array as an input.
Let's say I have the array I need... Do I have to allocate a memory for it, and pass the pointer to that memory location to the dll?
I've read somewhere on this site, that the only way to work with pointers in LabVIEW is by using the "call library function". Is there any way to create an array and a pointer to it in labview without going through the call library functions?

Even if that were the only way, can anybody help me to get started?


In the attached VI, using "Invoke Node" I call a function named "Set Data". The function has
2 input variables:

1. pbyData - This is the pointer (type U8) to a buffer that contains the array;
2. wDataLength - The length of the array.

What should I connect to these 2 inputs?


Thank you in advance,
Ivan
0 Kudos
Message 1 of 11
(9,640 Views)
ivan_div wrote:

> Hello,
>
> I'm trying to find out how to define an array, and send a pointer to
> it.
> In other words: I've imported a DLL (written in C++), and one of its
> functions needs a pointer to an array as an input.
> Let's say I have the array I need... Do I have to allocate a memory
> for it, and pass the pointer to that memory location to the dll?
> I've read somewhere on this site, that the only way to work with
> pointers in LabVIEW is by using the "call library function". Is there
> any way to create an array and a pointer to it in labview without
> going through the call library functions?

Well you will have to use the Call Library function to call your DLL
function won't you? 😉 Ohh I see you created an Active X interface
for the DLL, ohh my God!
If you would call the DLL fucntion through Call Library Node instead,
LabVIEW would do all the work for you. Or have the ActiveX method take
a string or variant value instead.

> Even if that were the only way, can anybody help me to get started?
>
> In the attached VI, using "Invoke Node" I call a function named "Set
> Data". The function has 2 input variables:
>
> 1. pbyData - This is the pointer (type U8) to a buffer that contains
> the array;
> 2. wDataLength - The length of the array.
>
> What should I connect to these 2 inputs?

Create an Array of U8 integers with the Initialize Array function. Wire
that array to a Call Library Node (CLN) setup as following:

Library Name: LabVIEW
Function Name: MoveBlock
Calling convention: C decl
return value: void
1. param: source, array of U8 pass as LabVIEW array handle
2. param: target, uInt32, passed by reference
3. param: length = 4

The final array pointer (param2 output) incremented by 4 is now what you
want to pass to your ActiveX method together with the intial length of
the array.

NOTE!!: Make sure the array you intialized stays valid until after the
ActiveX method returns. This means for instance wiring the right side of
the first parameter of the CLN to a sequence frame which also somehow
depends on the ActiveX node having been executed (error cluster output
to the same frame wired) and don't branch the array wire before you
arrive in that (sequence) frame.

Rolf Kalbermatter

>
> Thank you in advance,
> Ivan
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 2 of 11
(9,645 Views)
Ok, let's do this the easy way... You said: "If you would call the DLL fucntion through Call Library Node instead,LabVIEW would do all the work for you."

How?

I'm calling the function from the DLL but it still expects a pointer as an input parameter (pbyData). How can I feed in a simple array of U8 ?

thanks for the help,
Ivan
0 Kudos
Message 3 of 11
(9,643 Views)
ivan_div wrote:

> Ok, let's do this the easy way... You said: "If you would call the DLL
> fucntion through Call Library Node instead,LabVIEW would do all the
> work for you."
>
> How?
>
> I'm calling the function from the DLL but it still expects a pointer
> as an input parameter (pbyData). How can I feed in a simple array of
> U8 ?

You simpy create an array of U8 with Initialize Array of the right size
and pass it to the Call Library Node parameter, which has been
configured to use Array of uInt8, 1 dimension, pass as C array pointer.
LabVIEW will take care to pass the pointer to the data part of the
LabVIEW array to the DLL and make sure that pointer stays valid as long
as the Call Library Node needs to execute.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 4 of 11
(9,643 Views)
I really have problems understanding you... How can I pass an array of U8 to the Call Library Node parameter that expects U8 number and not an array. I'd get a broken wire... Please be more specific or please send me an example code.

Thanks,
Ivan
0 Kudos
Message 5 of 11
(9,643 Views)
ivan_div wrote:
> I really have problems understanding you... How can I pass an array of
> U8 to the Call Library Node parameter that expects U8 number and not
> an array. I'd get a broken wire... Please be more specific or please
> send me an example code.

Hmm, I said configure the parameter as:
- Array of U8
- 1 dimension
- pass as C array pointer

I can't see where you could possibly see that I said to configure it as
an U8 integer.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 6 of 11
(9,643 Views)
> I really have problems understanding you... How can I pass an array of
> U8 to the Call Library Node parameter that expects U8 number and not
> an array. I'd get a broken wire... Please be more specific or please
> send me an example code.

You might try searching for

Writing Win32 Dynamic Link Libraries (DLLs) and Calling Them from LabVIEW

on zone.ni.com. This tutorial goes over lots of DLL related issues and
has an example of passing a numeric array in and out of a DLL.

Greg McKaskle
0 Kudos
Message 7 of 11
(9,643 Views)
ivan_div wrote:

> I really have problems understanding you... How can I pass an array of
> U8 to the Call Library Node parameter that expects U8 number and not
> an array. I'd get a broken wire... Please be more specific or please
> send me an example code.

This is a screen shot of the relevant settings in the configuration dialog.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 8 of 11
(9,643 Views)


@rolfk wrote:
@ivan_div wrote:

> Hello,
>
> I'm trying to find out how to define an array, and send a pointer to
> it.
> In other words: I've imported a DLL (written in C++), and one of its
> functions needs a pointer to an array as an input.
> Let's say I have the array I need... Do I have to allocate a memory
> for it, and pass the pointer to that memory location to the dll?
> I've read somewhere on this site, that the only way to work with
> pointers in LabVIEW is by using the "call library function". Is there
> any way to create an array and a pointer to it in labview without
> going through the call library functions?

Well you will have to use the Call Library function to call your DLL
function won't you? 😉 Ohh I see you created an Active X interface
for the DLL, ohh my God!
If you would call the DLL fucntion through Call Library Node instead,
LabVIEW would do all the work for you. Or have the ActiveX method take
a string or variant value instead.

> Even if that were the only way, can anybody help me to get started?
>
> In the attached VI, using "Invoke Node" I call a function named "Set
> Data". The function has 2 input variables:
>
> 1. pbyData - This is the pointer (type U8) to a buffer that contains
> the array;
> 2. wDataLength - The length of the array.
>
> What should I connect to these 2 inputs?

Create an Array of U8 integers with the Initialize Array function. Wire
that array to a Call Library Node (CLN) setup as following:

Library Name: LabVIEW
Function Name: MoveBlock
Calling convention: C decl
return value: void
1. param: source, array of U8 pass as LabVIEW array handle
2. param: target, uInt32, passed by reference
3. param: length = 4

The final array pointer (param2 output) incremented by 4 is now what you
want to pass to your ActiveX method together with the intial length of
the array.

NOTE!!: Make sure the array you intialized stays valid until after the
ActiveX method returns. This means for instance wiring the right side of
the first parameter of the CLN to a sequence frame which also somehow
depends on the ActiveX node having been executed (error cluster output
to the same frame wired) and don't branch the array wire before you
arrive in that (sequence) frame.

Rolf Kalbermatter

>
> Thank you in advance,
> Ivan



Dear Masters,
I have fined this discussion - pointer to array - because I have a similar problem with using ActiveX to read data from some Data Acquisition program.
The answer of rolfk - Proven Active Veteran - looks wonderful.
Could you, please, explain, why this method should work, what for, in addition, can be useful calling LabVIEW(dll ?), and is this problem - passing buffer array from LabVIEW to ActiveX - resolved, say, in LabVIEW 8.2 ?
0 Kudos
Message 9 of 11
(9,077 Views)
I don't understand what "problem" you're referring to.

The only problem I see in this thread is that ivan_div didn't do exactly what RolfK told him.

The function call works fine.

As such I don't see how any changes to LV 8.2 should "fix" anything......

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 10 of 11
(9,054 Views)