Per Erik Strandberg /cv /kurser /blog

This is the third instruction I write on how to use Labview in mixed environments. The other two both combine Labview and .NET: In Labview And Dot Net Combo Part 1 I show how you can import .NET code into Labview and in Labview And Dot Net Combo Part 2 I illustrate how virtual instruments can be used in C#. Here we will see how a native C dll's can be called from within Labview.

Step 1: Create the native dll

I write a very simple method in a very simple c-file. It multiplies two numbers and adds a third number times 1.01. In the function header I specify that it should be exported in the dll:

#include <stdio.h>
#include <string.h>

double __declspec(dllexport) __stdcall MyFunc(int a, int b, int c)
    return a * b + c * 1.01;

I also make my very first (on my home page any way) h-file. The h-file is needed in a later step when Labview will import the method.

#ifndef MY_LIB
#define MY_LIB
double __declspec(dllexport) __stdcall MyFunc(int a, int b, int c);

I compile using cl from the command line since that is the kind of guy I am: cl MyLib.c /LD /Zi. The source files can be downloaded from [1] and [2].

Step 2: Create a VI-wrapper

Now you can create a new VI and in the block diagram select Tools - Import - Shared Library (.dll)... If you follow this wizard (politely give the header file to Labview) you will end up with a VI named something like My in the project view.

Step 3: Use the C dll

The VI we created in step 2 can now be dragged and dropped in a new VI and we can use it just like any other node. I made three slides and a tank to illustrate the inputs and the output:

See also Labview And Dot Net Combo Part 1
See also Labview And Dot Net Combo Part 2
This page belongs in Kategori Programmering