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.
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.
11-23-2006 02:45 PM
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
STATUS_READ = ReadDevice16("__AGP1.#INTERNAL", "WS01_Hour", TABLE_READ(1), 10)
Cells(1, 1) = STATUS_READ
Cells(line + 1, 1) = TABLE_READ(line)
Next
End Sub
11-24-2006 12:54 AM
11-24-2006 02:23 AM
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
12-11-2006 02:10 AM
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
12-11-2006 02:35 AM - edited 12-11-2006 02:35 AM
Message Edited by pincpanter on 12-11-2006 09:35 AM
12-11-2006 05:16 AM - edited 12-11-2006 05:16 AM
@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
12-11-2006 07:16 AM
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
12-11-2006 10:52 AM
@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
12-11-2006 03:39 PM
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
12-12-2006 12:46 AM
@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