LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VIs using DLL

Hi !,

I have a DLL which export the C API of my hardware device in the kernel space
I'm planning to build a Wrapper VI for each entrypoints ( functions ) of my DLL
using Call Library Function Nodes. This will allow me to import the entire API
of my DLL into LabView in user space.

Then, the function wrappers VIs will be saved in a llb, a LabVIEW Library and
used by a LabView application.

Now, I have few questions regarding the way the function calls, data access
are performed between the kernel and user spaces.
I'm still a beginner in this area.

Questions:

1) Functions Calls

About the Call Library Function Nodes within the VIs, they are used to call functions
within the kernel space from LabView in a user space.

Is there any address conversion somewhere to perform or it is handled automatically ?

2) Read/Write data buffers in kernel space from LabView in user space.

I have several large buffers allocated within the kernel space that need to be
access in read/write modes from LabView in user space.

What is the fastest way to access these buffers ?
Using a pointer in LabView to access the data into the buffer is probably the best way to go ?

Again, Is there any address conversion somewhere to perform or it is handled automatically ?

3) Shared Memory Region

What about using a virtual memory region which is map on a physical memory region to access
the buffers data in read/write ?

Is it something that can be implemented in windows ?

thanks in advance!
0 Kudos
Message 1 of 5
(2,775 Views)
I can't say that I completely understand many of your questions, but it sounds like you would simply like to port some DLL functions to LabVIEW using a Call Library Function Node, and I've attached a great document that explains all about it. Basically, all that is required is that you configure the function parameters and the rest is taken care of automatically. One specific parameter that you mentioned was a data buffer, and the best way to implement that is to pass the DLL function a pointer to an array in LabVIEW (and there is a whole section in the attached document that goes over arrays).

Best of luck to you!
E. Sulzer
Applications Engineer
National Instruments
0 Kudos
Message 2 of 5
(2,733 Views)
Accessing kernel space is not a trivial thing from the OS APIs. You must first map the kernel address space into user space via kernel APIs and then you can access it. Depending on what kernel space you are trying to access, VISA might help you out there (such as if you are trying to access a PCI card). Check out http://zone.ni.com/devzone/conceptd.nsf/webmain/ADF3152837E2B4A486256B5600642AC7 for more information.

To answer your questions

1. LabVIEW can only invoke APIs in user space - thus any Win32 user mode API is available as well as any DLL you create with a C interface. Of course, some APIs map easier than others. Any kernel APIs can only be invoked from kernel space. The kernel driver may be exposed via Read/Write or an ioctl...depends how it is set up.

2. See my first section. I guess one question I have from you - do you have a kernel driver or is it simply that you need to access your hardware (PCI or what)?

3. Not sure I understand this one.
0 Kudos
Message 3 of 5
(2,716 Views)
Thanks for the information, I will read the documents you have referred to me.


2. See my first section. I guess one question I have from you - do you have a kernel
driver or is it simply that you need to access your hardware (PCI or what)?

I have a kernel driver( DLL ) for an OHCI IEEE1394 PCI card.
I'm planning to export the API of my kernel driver into LabView using VIs.
These wrapper VIs will be saved within an LLB ( LabView library )

Then, I will build a LabView application using the services of this LLB library.
At first, I didn't know how and where I can allocate the buffers I need for transmit and receive.

But now, I understand that I need to allocate them within LabView and pass pointers on them
to my kernel driver using the wrapper VIs.

I have also concerns about processing time, I want my LabView application to be Zero-Copy.
Meaning there are no copy of buffers from the kernel space into the user space.
Only pointers on buffers are used to access the received and transmit data.


3. Not sure I understand this one.

Forget this question, I have a background of programming with the Integrity RTOS, and
we are allowed to map a virtual memory region into a kernel memory region.
I was just wondering if we can do that using LabView with a DLL.


Thanks for your help
0 Kudos
Message 4 of 5
(2,709 Views)
I think we need to break this into two parts for Windows and LabVIEW.

In the first part, we need to have a user level API (C based) for your kernel driver. The only way to access a kernel driver is via the OS layer of Read/Write/DeviceIoControl - any API methods you have in the kernel driver cannot be accessed directly from user space. As far as avoiding copies, you need to look at the options for the memory buffers used in these APIs. If you can lock the memory in the kernel then the user mode code can write directly into it.

For simplicity of testing I would recommend creating this initial user-mode API in straight C, rather than trying to either (a) get LV to call the OS methods directly or (b) use the CINs to call them.

Second part - Once you have that API, you can use either the Call Library Node or CINs to invoke them from LV.

BTW - the document link I sent you was regarding creating a driver for your PCI card without having to write a kernel driver. If you already have the kernel driver, it isn't going to help that much.
0 Kudos
Message 5 of 5
(2,676 Views)