LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using LabView dll to perform FFT for VB.NET 2005

I can create a LabView dll to perform FFT(calculation) used by VB.NET 2005. But I can only output single data values from dll function. When I try to output 1-d data array I always get memory related error. Does anybody know the trick?

I am using Vista, LabView8.6 and VB.NET 2005

0 Kudos
Message 1 of 9
(5,021 Views)

Hi,

I dont know about how the dll calls are made inVB.net.  But how is the array being passed to dll function in VB.NET.  You are passing as data or pointer to array or as a handle (pointer to pointer).  Each has its own way of manipulating the input.  The one way that should work without flaw is passing the pointers to the dll rather than other methods but still depends on certain other condition.  Kindly post which method you are adopting.

With regards,
JK
(Certified LabVIEW Developer)
Give Kudos for Good Answers, and Mark it a solution if your problem is solved.
0 Kudos
Message 2 of 9
(5,013 Views)

I guess my problem is can not output 1-D array from dll. 

 

In LabView 8.6 Application Builder. 

Using "C Calling Conventions" (I did try the "Standard Calling Conventions" and it seems same)

The function ("SimpleArray") has following I/O parameters:

1. 1-D Input Array (Int32) - type:input, Pass By:Array Data Pointer, Length Input: InLen(int32)

2. 1-D Output Array (double) - type:output, Pass By:Array Data Pointer, Length Input:InLen(In32), Length Output:Len2(int32)

 

 

In VB.NET 2005 I declare the fnction as

    Private Declare Sub SimpleArray Lib "MustangFIFOdsp.dll" (ByVal InputArray() As Int32, _
                                                              ByRef OutArray() As Double,  _
                                                              ByVal InLen As Int32, ByRef OutLen As Int32)

 

I don't have the problem to input the 1-D array and output single number values but the 1-D array even the OutLen reports correct output array size. I can get ride off the "memory" error by specify the output array size before calling the "SimpleArray' function in VB code. But the output array is "empty".

 

If I can get this work, LabView can provide nice DSP fucntions that is hard for VB.NET. Thanks!

 

0 Kudos
Message 3 of 9
(5,008 Views)

Hi there:

Can any one please help us with this issue.

Can't believe it's that hard for any NI guy to give us an exemple to hlp us deal with labview DLL's in VB2005.

all we have is a basic exemple with single I/O working with VB2003, when we run it on 2005, it's full of bugs, limitations, memory restriction... 

 

 thank's in advance for any assistance.

 

 

Labview 8.5

VB2005

XP 

0 Kudos
Message 4 of 9
(4,689 Views)

ACOH,

 

Have you seen this KB with links to other good resources?

 

Kristen H.

Message 5 of 9
(4,638 Views)

Hi Kristen:

 

Yes , i've seen thelink and the exemples , and they do not apply to VB 2005, but only to VB 2003.

 

I've been trying to perform the data transfert between  Labview and VB for at least a week, with no succes 😞

 

can any one help ?

 

Thank's

 

PS: Did you close the new thread i opened for this issue?

 

 

0 Kudos
Message 6 of 9
(4,629 Views)

I didn't look at this thread for a while till now I saw an email. I figured out how to pass data array from labView DLL to VB.NET 2005 or 2008. The Dll only only past the pointer of the data array. So you can Dim a data array then use first element to get the pointer.  

 

For example:

 

LabViewDLLFunction (Byval *OutputDataArray as int, ...)

 

in VB.NET

 

Dim dArray() as int

LabViewDLLFunction(dArray(0))

 

After run above lines, the dArray() should be filled with data if the LabView DLL works.

 

 

0 Kudos
Message 7 of 9
(4,593 Views)

If you use C datatypes the caller has to provide all the memory to a function call. This means in addition to the input arrays that are used for the calculation you also have to provide a large enough buffer for the output array. Just defining an unsized array pointer at passing it to the DLL function won't work.

 

It does work in Visual Basic itself maybe as VB has full control over its memory allocations as long as you stay in VB but there is no way for Visual Basic to know what size the array should have when passed to the DLL function. It certainly does work fully autmomatically in LabVIEW as long as you stay in the diagram but again LabVIEW would have no way to know what size the array has to be when passing it to an external C function.

 

And a C function has no way to resize a memory block properly if it doesn't know EXACTLY how that memory was allocated by the caller in the first place (and if the array pointer is passed by value, which is usually the case it couldn't even do so at all, since the reallocated pointer could not be passed back to the caller through the original function parameter).

 

How to allocate a properly sized array in Visual Basic I leave to the VB freaks. I only know from theory how VB works as I don't like it. 

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

ACOH wrote:

I didn't look at this thread for a while till now I saw an email. I figured out how to pass data array from labView DLL to VB.NET 2005 or 2008. The Dll only only past the pointer of the data array. So you can Dim a data array then use first element to get the pointer.  

 

For example:

 

LabViewDLLFunction (Byval *OutputDataArray as int, ...)

 

in VB.NET

 

Dim dArray() as int

LabViewDLLFunction(dArray(0))

 

After run above lines, the dArray() should be filled with data if the LabView DLL works.

 

 


How does the DIM command allocate a properly sized array? I would expect this to fail somehow since the DIM command only allocates an array pointer but not the memory for the entire array.

 

Shouldn't this be DIM dArray(100) as int or something like that, depending how large the array needs to be for the function?

Or maybe you could do LabViewDLLFunction(dArray(100)) but I'm not sure if this is the VB syntax to resize a variable sized array to a specific size. Just guessing here.

Message Edited by rolfk on 03-04-2010 09:25 AM
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 9 of 9
(4,582 Views)