LAVA Forums Buy cool LAVA gear Forums RSS Feed

Welcome Guest ( Log In | Register )

> Related links

Check out our XNodes Code Repository Files and visit our LabVIEW Wiki XNodes Portal


Tags
(This content has not been tagged yet)
 
Reply to this topic Start new topic
> GetValueByPointer XNode in LV 8.5, What does it do and how should it be safely used...
Tomi Maila
post Oct 29 2007, 07:34 PM
Post #1


Drawing Tool - LVOOP example application
*****

Premium Member
Posts: 1184
Joined: 29-January 06
From: Helsinki
Member No.: 4014
Using LabVIEW Since:2004
LV:8.5.1 ,8.2.1 ,7.1.1
Finland Nothing Selected Nothing Selected My Blog


Hi,

I noticed that LabVIEW 8.5 ships an interesting XNode called GetValueByPointer.xnode under folder <vi.lib>\Utility\importsl\GetValueByPointer. Has anyone experience what is this node, how does it work and how should it be safely used?

Cheers,

Tomi

--------------------
Tomi Maila



Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
Ad
post Oct 29 2007, 07:34 PM
Post #















Tags
(This content has not been tagged yet)
Go to the top of the page
Quote Post
hviewlabs
post Nov 21 2007, 12:30 AM
Post #2


Very Active
***

Member
Posts: 74
Joined: 2-December 04
From: Seattle
Member No.: 1166
Using LabVIEW Since:1999
LV:8.20 ,. ,.
United States Russia Nothing Selected


So, 8.5 can now handle (wrap) dll functions which
require as parameters, say, a pointer to a structure,
one of elements of which is a pointer to a variable
length data. Great! For this purpose the following
library is utilised by the DLL Import Wizard (that's
how I discovred it): \vi.lib\Utility\importsl

It has DSNewPtr.vi to create a pointer (and allocate
memory I would assume), DSDisposePtr.vi to (you
guessed!) dispose of the pointer (and deallocate
memory), InitStr.vi to write data to the memory to
which the pointer points and, the
GetValueByPointer.xnode (located in the
GetValueByPointer subfolder, can be dragged onto BD
from explorer, just like a VI, but you can't even open
its FP) to retreive the data from the memory location
the pointer points to.

No documentation though, even in the context help for
those top level VIs. So, Anybody has any idea what
PackType parameter of the GetValueByPointer.xnode is?

Well, what I said would be especially beneficial if on
its output wire GetValueByPointer.xnode really has the
reference to (address of) the data, not to a copy it
creates.


They apparently can be used to ensure that passing
of (large) data is done by reference (only the pointer
is passed around without moving/copying the data
itself) not only betweeen LabVIEW code and dll code but also
between any of your VI's as well.

Well, what I said would be especially beneficial if on
its output wire GetValueByPointer.xnode really has the
reference to (address of) the data, not to a copy it
creates.


Interesting: the default string for the InitStr.vi is
"Import Shared Library Tool in Jupiter." I wonder what
"Jupiter" is/was. My guess is it was the code name
for one of the LabVIEW versions.

This post has been edited by hviewlabs: Nov 21 2007, 12:44 AM


Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
Aristos Queue
post Nov 21 2007, 03:03 AM
Post #3


LV R&D Envoy
*****

NI
Posts: 1275
Joined: 15-August 06
From: Austin, TX
Member No.: 5877
Using LabVIEW Since:2000
LV:8.6 ,6.0 ,.
United States Nothing Selected Nothing Selected My Gallery


QUOTE (hviewlabs @ Nov 20 2007, 06:30 PM) *
I wonder what
"Jupiter" is/was. My guess is it was the code name
for one of the LabVIEW versions.
That would be LV8.5. LV8.5.1 -- if we decide that 8.5 warrants a bug fix release -- has been jokingly called LabVIEW Hale-Bopp... because it is a small adjustment to Jupiter.

--------------------
"A VI outside a class is a gun without a safety. Data outside a class is a target."
--- A message from LabVOOP R&D


Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
Tomi Maila
post Nov 21 2007, 08:28 AM
Post #4


Drawing Tool - LVOOP example application
*****

Premium Member
Posts: 1184
Joined: 29-January 06
From: Helsinki
Member No.: 4014
Using LabVIEW Since:2004
LV:8.5.1 ,8.2.1 ,7.1.1
Finland Nothing Selected Nothing Selected My Blog


QUOTE (hviewlabs @ Nov 21 2007, 02:30 AM) *
Interesting: the default string for the InitStr.vi is
"Import Shared Library Tool in Jupiter."

Also interestingly LAVA interprets initstr.vi as a web address for a domain at US Virgin Islands...

--------------------
Tomi Maila



Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
Michael_Aivaliot...
post Nov 21 2007, 10:30 AM
Post #5


Confucius say: Crowded elevator always smell different to midget
Group Icon
*****

Admin
Posts: 2402
Joined: 13-October 02
From: Planet Earth
Member No.: 2
Using LabVIEW Since:1994
LV:8.5 ,8.2.1 ,7.1.1
Greece Canada United States My Blog My Gallery


QUOTE (Tomi Maila @ Nov 21 2007, 12:28 AM) *
Also interestingly LAVA interprets initstr.vi as a web address for a domain at US Virgin Islands...

Hey, it wasn't me! ninja.gif

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


Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
Jim Kring
post Nov 21 2007, 02:44 PM
Post #6


Changing the world, one VI at a time.
*****

JKI
Posts: 1717
Joined: 22-October 02
From: San Francisco, CA
Member No.: 17
Using LabVIEW Since:1995
LV:8.2.1 ,8.5 ,7.1.1
United States us_california Nothing Selected My Blog My Gallery


QUOTE (Tomi Maila @ Nov 21 2007, 12:28 AM) *
Also interestingly LAVA interprets initstr.vi as a web address for a domain at US Virgin Islands...


Actually, I think that it's gmail that does this. I'll bet that hviewlabs copied and pasted that text from his web browser.

--------------------
-----------------------------------------------------------------------------------------------------
| Book | OpenG | LAVA | Champion | VIPM | Builder | Blog | JKI |
-----------------------------------------------------------------------------------------------------


Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
cosmin
post Nov 21 2007, 03:13 PM
Post #7


More Active
**

Member
Posts: 25
Joined: 9-February 06
From: Romania
Member No.: 4089
Using LabVIEW Since:2001
LV:8.0 ,8.20 ,7.1.1
Romania Nothing Selected Nothing Selected


QUOTE (hviewlabs @ Nov 21 2007, 02:30 AM) *
No documentation though, even in the context help for
those top level VIs. So, Anybody has any idea what
PackType parameter of the GetValueByPointer.xnode is?



I guess the PackType parameter is refering to the member aligment (how the structures are packed into memory, 1byte, 2, 4, 8 or 16 bytes).


Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
hviewlabs
post Nov 21 2007, 05:19 PM
Post #8


Very Active
***

Member
Posts: 74
Joined: 2-December 04
From: Seattle
Member No.: 1166
Using LabVIEW Since:1999
LV:8.20 ,. ,.
United States Russia Nothing Selected


QUOTE (cosmin @ Nov 22 2007, 12:43 AM) *
I guess the PackType parameter is refering to the member aligment (how the structures are packed into memory, 1byte, 2, 4, 8 or 16 bytes).

And the correct value is determined by what? Say, if we dereference the pointer to a location to which a dll function has written something and we have the definition of the data structure for that pointer in the .h file, how exactly do we choose the PackType? Does it depend on OS, language/compiler used to make the dll, some options set in the compiler?


Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
lavezza
post Nov 21 2007, 07:29 PM
Post #9


More Active
**

Member
Posts: 49
Joined: 28-October 03
From: Phoenix, AZ
Member No.: 192
Using LabVIEW Since:1996
LV:7.1.1 ,8.2.1 ,8.5
United States us_arizona us_florida


QUOTE (hviewlabs @ Nov 21 2007, 12:19 PM) *
And the correct value is determined by what? Say, if we dereference the pointer to a location to which a dll function has written something and we have the definition of the data structure for that pointer in the .h file, how exactly do we choose the PackType? Does it depend on OS, language/compiler used to make the dll, some options set in the compiler?


The compiler. I think MS defaults their compilers to '#pragma pack 8' for 8-byte alignment. Although I'm not sure that all their internal data structures are done that way. We had this issue not too long ago. I was too lazy to write a wrapper DLL for a DLL written by another group in our company. There was one call that returned a structure. Reading it as a byte array and casting to a cluster wasn't working. It worked after adding some 'dummy' U8's into the cluster. When changes were made to the DLL we got them to compile with '#pragma pack 1', which is basically no byte alignment, so we didn't need the dummy controls. Eventually they just added a second call that returned the same data as separate values instead of a structure. Of course this isn't usually an option unless you have some sway with the DLL owner.

Pat


Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
Godpheray
post Nov 27 2007, 02:48 AM
Post #10


I want a LabVIEW icon under my name!


NI
Posts: 3
Joined: 8-September 06
Member No.: 6094
Using LabVIEW Since:2004
LV:8.20 ,7.1 ,8.0.1
China Nothing Selected Nothing Selected


QUOTE (Tomi Maila @ Oct 30 2007, 01:34 AM) *
Hi,

I noticed that LabVIEW 8.5 ships an interesting XNode called GetValueByPointer.xnode under folder <vi.lib>\Utility\importsl\GetValueByPointer. Has anyone experience what is this node, how does it work and how should it be safely used?

Cheers,

Tomi


GetValueByPointer takes the C style pointer and the corresponding data type, which are generated by Import Shared Library Tool, as inputs and copies the value which the pointer points in shared library(dll/so/framework) to LabVIEW.

Input terminals:
Input Type: Input type is the LabVIEW data type to which you want to pass into LabVIEW. Input type can be Numeric, string, Array, Cluster . This VI returns an error if LabVIEW cannot convert the data wired to Pointer to the data type you wire to this input. If the data is integer, you can coerce the data to another numeric representation, such as an extended-precision, floating-point number.
Pointer: Pointer is a memory address represented by a 32-bit unsigned integer in LabVIEW.
Pack Type: Byte alignment information of the Input Type.

Output terminals:
Value:Value is the data copied from the memory which is pointed by Pointer and changed to the data type specified by Input type.


Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
rolfk
post Nov 28 2007, 04:10 PM
Post #11


<customize this text>
*****

Premium Member
Posts: 1060
Joined: 9-April 04
From: Rotterdam
Member No.: 349
Using LabVIEW Since:1992
LV:8.5.1 ,8.2.1 ,7.1.1
Netherlands Switzerland Nothing Selected


QUOTE (hviewlabs @ Nov 21 2007, 12:19 PM) *
And the correct value is determined by what? Say, if we dereference the pointer to a location to which a dll function has written something and we have the definition of the data structure for that pointer in the .h file, how exactly do we choose the PackType? Does it depend on OS, language/compiler used to make the dll, some options set in the compiler?

That node has an input that accepts just about any LabVIEW type including a cluster. For non-cluster types the packtype has no meaning. But for cluster types the node will align the individual elements to that packing alignment. This is also where the node is actually a bit complicated I'm sure. The extraction of linear arrays or skalars is a no brainer really. The fact that an xnode apperently can have an input parameter that can truely adapt to just about any LabVIEW datatype would be the most interesting aspect of that node, but according to NI there is no such thing like an Xnode and therefore no self adapting datatype input.

QUOTE (Godpheray @ Nov 26 2007, 09:48 PM) *
GetValueByPointer takes the C style pointer and the corresponding data type, which are generated by Import Shared Library Tool, as inputs and copies the value which the pointer points in shared library(dll/so/framework) to LabVIEW.Input terminals:Input Type: Input type is the LabVIEW data type to which you want to pass into LabVIEW. Input type can be Numeric, string, Array, Cluster . This VI returns an error if LabVIEW cannot convert the data wired to Pointer to the data type you wire to this input. If the data is integer, you can coerce the data to another numeric representation, such as an extended-precision, floating-point number.Pointer: Pointer is a memory address represented by a 32-bit unsigned integer in LabVIEW. Pack Type: Byte alignment information of the Input Type. Output terminals:Value:Value is the data copied from the memory which is pointed by Pointer and changed to the data type specified by Input type.

One interesting aspect of that node seems to be the fact that one can convert a pointer into a string or array. I can see that converting into a string should be possible when simply looking for the NULL termination character, but turning it in an array would suggest to me that the input pointer can not just be any possible pointer but must be one prepared by DSNewPtr.vi. Otherwise that node has no way of knowing how big the memory area the pointer is pointing too could possibly be. There is not even a documented DSPtrSize function, so I guess DSNewPtr.vi must do some internal magic to the pointer so that GetValueByPointer.xnode can make sure to never overrun the end of the allocated memory area.

Rolf Kalbermatter


Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
hviewlabs
post Nov 28 2007, 08:10 PM
Post #12


Very Active
***

Member
Posts: 74
Joined: 2-December 04
From: Seattle
Member No.: 1166
Using LabVIEW Since:1999
LV:8.20 ,. ,.
United States Russia Nothing Selected


The node apparently uses GetValueByPointer function from the LabVIEW 8.5\resource\lvimptsl.dll. There other 2 functions there: SetLVRTModule and SetStrDefaultValue.


Tags
(This content has not been tagged yet)
Go to the top of the page
+Quote Post
Tomi Maila
post Nov 28 2007, 09:23 PM
Post #13


Drawing Tool - LVOOP example application
*****

Premium Member
Posts: 1184
Joined: 29-January 06
From: Helsinki
Member No.: 4014
Using LabVIEW Since:2004
LV:8.5.1 ,8.2.1 ,7.1.1
Finland Nothing Selected Nothing Selected My Blog


QUOTE (hviewlabs @ Nov 28 2007, 10:10 PM) *
The node apparently uses GetValueByPointer function from the LabVIEW 8.5\resource\lvimptsl.dll. There other 2 functions there: SetLVRTModule and SetStrDefaultValue.

Surely you can check it out. Add XNodeWizardMode=True into your LabVIEW.ini file, then right click on the XNode on a block diagram and select Generated Code from the what ever menu there is for debugging XNodes. Then simply check out the call specs... biggrin.gif

Tomi

--------------------
Tomi Maila



Tags
(This content has not been tagged yet)