From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing parameters to DLL: ok in Excel/VB, not in Labview?

Hello:

I am trying to embed a dll in a Labview 7.1 application. The following code works for Excel/Vba but I was not able to reproduce it in Labview. The reason for the problem probably lies in the third argument of the call of the ReadDevice16 that must be the first element of the array that will be filled with the 10 elements requested (the 4th argument). I do not understand how to code that in Labview, I tried the code attached as suggested in a similar thread by Ralph K. but I am getting an error message, maybe it is not really a pointer that comes out of the first DLL.

I am sorry for my ignorance, the lack of proper vocab used but I am totally new to DLL embedding in Labview. All I can say is that I was able to encapsulate in Excel (see below) in less than 10 min and spent several hours trying to do the same with no success in Labview 7.1.

Thanks for your precious suggestions,

Christophe

------------------------------

Dim STATUS_READ As Long

Global TABLE_READ(1 To 100) As Integer

Global TABLE_WRITTEN(1 To 10) As Integer

 

Sub READ()

STATUS_READ = ReadDevice16("__AGP1.#INTERNAL", "WS01_Hour", TABLE_READ(1), 10)

Cells(1, 1) = STATUS_READ

 

For line = 1 To 10

    Cells(line + 1, 1) = TABLE_READ(line)

Next

End Sub

0 Kudos
Message 1 of 12
(3,280 Views)
Hi Cristophe,

have you got the .dll function declaration? or better .h file (I have 8.2 and can try to automatically build the setup).
Maybe you need some other string declaration?
I am not that familiar with VB, but are you sure Integer = U32? and it looks like you swapped the third and fourth elements

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 2 of 12
(3,256 Views)

Hello Ton:

Thanks for your feedback. I attach the .h file where you will find this line:

INT WINAPI ReadDevice16(LPCSTR sNodeName,LPCSTR sDeviceName,WORD* owData,WORD wCount);

No, I do not think that I swapped the third and fourth argument, the 3d is the first element of the array and the fourth is the requested length. What I do not understand is how I can send the first element of an array to this 3d element AND so that the DLL will fill the entire array in question as it exits.

I have to mention that the second DLL call in my labview code (it is the MoveBlock DLL) is what Rolf K. referred to in a previous message. I have added this call after the exit of the first DLL call thinking it would convert the array pointer that exits first DLL (?) to an array that is refered by the pointer but apparently it is not working.

Thanks,

Christophe

0 Kudos
Message 3 of 12
(3,248 Views)

Hello again;

Does someone out there have an input to try to mimic in Labview what is succesfully done in Excel using the:

STATUS_READ = ReadDevice16("__AGP1.#INTERNAL", "WS01_Hour", TABLE_READ(1), 10)

This supplies the first element of TABLE_READ array to the ReadDevice16 function and in return gets the all TABLE_READ array filled.

The two first parameters that I send to the DLL are correct because I can get good results if I request one parameter at a time. It is only to get the all array at once that fails.
Thanks again for all your precious advises,

Christophe

0 Kudos
Message 4 of 12
(3,195 Views)
Hi Christophe,
the wCount parameter is an input to the function, this means that allocating memory for the array is up to you (like in the VB example). I think you need to create an U16 (i.e. WORD) array with Initialise Array and pass the array to the function as an Array Data Pointer; the output array should contain the required values. Hope this helps.

Message Edited by pincpanter on 12-11-2006 09:35 AM

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 5 of 12
(3,186 Views)


@Chris_From_Brussels wrote:

Hello again;

Does someone out there have an input to try to mimic in Labview what is succesfully done in Excel using the:

STATUS_READ = ReadDevice16("__AGP1.#INTERNAL", "WS01_Hour", TABLE_READ(1), 10)

This supplies the first element of TABLE_READ array to the ReadDevice16 function and in return gets the all TABLE_READ array filled.

The two first parameters that I send to the DLL are correct because I can get good results if I request one parameter at a time. It is only to get the all array at once that fails.
Thanks again for all your precious advises,

Christophe



Try pincpanters suggestion. He is certainly rigth with his explanation. The MoveBlock example you saw only works for pointers returned by the function itself or for those rare functions that would allocate the buffer themselves and pass it to the caller. Normally if a function takes a buffer as parameter, the caller always has to take care to allocate it and the function just writes into it. This is also your case.

The DIM statement in VB allocates the buffer. Do the same with the InitializeArray function in LabVIEW.

Rolf Kalbermatter

Message Edited by rolfk on 12-11-2006 12:16 PM

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 12
(3,176 Views)

Paolo, Rolf:

Thanks it works perfectly ! The 'initialize array' function must be explicitely wired, wiring a constant or control array does not work.
Thanks again,
Christophe

0 Kudos
Message 7 of 12
(3,160 Views)


@Chris_From_Brussels wrote:

Paolo, Rolf:

Thanks it works perfectly ! The 'initialize array' function must be explicitely wired, wiring a constant or control array does not work.
Thanks again,
Christophe



It will work but you need to make sure that it is not an empty array. An empty array has storage for 0 bytes and will crash of course. But of course making sure the constant is filled with the right amount of elements is more cumbersome than using Initialize Array.

Rolf Kalbermatter

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 12
(3,155 Views)

Rolf:

When i said that a constant array would not work I meant wiring an array with a dimension >1 but instead of defining the array in an initialize array function (works) wiring a constant array to the same input of the DLL does not work. It is the initialize function that I was missing at the beginning of my post,

Thanks,

Chr

0 Kudos
Message 9 of 12
(3,147 Views)


@Chris_From_Brussels wrote:

Rolf:

When i said that a constant array would not work I meant wiring an array with a dimension >1 but instead of defining the array in an initialize array function (works) wiring a constant array to the same input of the DLL does not work. It is the initialize function that I was missing at the beginning of my post,


Are you sure you made the array constant contain as much elements than what you now allocate with Initialize Array? While LabVIEW does certain optimizations for constants, this should not make any difference in this case since LabVIEW can not know what the DLL will do with the buffer and should allocate it anyhow, disregarding any of its usual optimizations.

The only thing I could think of is that you branched of the wire before going to the DLL node to be used later. While this might work with Initialize Array sometimes, it will fail with a constant in more recent LabVIEW versions. You should always wire the input to the left side of the DLL node and any output from the DLL you want to use further on the right side.

Rolf Kalbermatter

Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 12
(3,131 Views)