LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

algorithm in c-code

I would like to implement an algorithm in c-code in my LabVIEW programm.
This code has to run for 64 channels at the same time in real time.

Is that possible at all?
Should I use CIN or DLL?


Thanks
Christoph
0 Kudos
Message 1 of 12
(2,988 Views)
It is possible.

The answer to your second question depends on the complexity of your algorithm (and its data-structure requirements).

(I would still recommend a DLL)

If the algorithm is very complex, I would develop an out-of process DLL or executable (for a number of reasons)

Anyhow, search NI's website for tutorials regarding DLL development (there are several).

Here's one:  http://decibel.ni.com/content/docs/DOC-1690



0 Kudos
Message 2 of 12
(2,974 Views)

Thanks for your quick reply!
I will check out the tutorials in the near future.

Now I am honestly not sure, where to build the DLL in my existing project, which I did not develop myself.
I attached a worddoc with a screen shot. At the beginning of the programm 60 electrodes send signals at the same time (according to sample rate 1kHz-25kHz).
All this information is queued so no information is lost. I guess this is queued in a 2D-array with 60 collumns and x rows. Is that right?

Now I have to run the DLL on the data I receive - is it possible to run the algorithms with the queued data or do I have to unqueue it before and then run the algorithm?

Since my data is stored in an array, I have to use an array in my c-code as well, right?!

Thanks again

0 Kudos
Message 3 of 12
(2,944 Views)
I haven't used traditional-DAQ in years.  If I remember correctly, a buffered-read call does returns a 2D array - containing all of the data acquired since the last call to buffered-read.

Anyhow, to answer your question:  you may handle the entire 2D array in your DLL.  Or, you may iterate through the 2D array in order to let your DLL process each row separately.

(and, yes - your DLL should use arrays in your C code; otherwise, you'd have to index each element and pass them into the DLL)

Considering the sampling-rate, you may have to launch a separate thread that calls this DLL (if the DLL call takes a relative long time to execute).  If you don't, your data-acquisition buffer will be overrun (and, data-loss will occur).

Fun Fun

Good Luck!

P.S., Have you considered implementing your algorithm in LabVIEW?


0 Kudos
Message 4 of 12
(2,920 Views)
By now I found, that I can´t use an array in c, but have to use a pointer instead. Is that correct?

Well I thought of writing the whole algorithm in labview, but the c-programm is about 700 lines.
I will see..
0 Kudos
Message 5 of 12
(2,878 Views)
In C array variables are pointers.
0 Kudos
Message 6 of 12
(2,868 Views)
So I have to use pointers...

I now suceeded in the tutorial (see above) but what would a Labview and C-code look like with pointers/arrays?

Lets say I want to call a DLL, which multiplies every element of an array by two and sends the new array back to labview??
How can I do that?


0 Kudos
Message 7 of 12
(2,826 Views)
I really don't want to confuse you anymore (that is, if you are indeed confused)

Anyhow, arrays [in C] and arrays [in LabVIEW] are the same.

In C, however, the name of the array can be used as a pointer to the 1st element of the array.  This pointer can be used to index other elements.

And, that's that.

...

Anyways, assuming that your algorithm is already coded in C - then all that you have to do is:  develope a DLL wrapper around the functions that you already have (which should be part of your algorithm - unless your algorithm consists of one function - e.g., "void main()").

I'd have to know more specific details - about your C code - in order to provide you with more accurate advice.

Good Luck.


0 Kudos
Message 8 of 12
(2,812 Views)

@s21694 wrote:
So I have to use pointers...

I now suceeded in the tutorial (see above) but what would a Labview and C-code look like with pointers/arrays?

Lets say I want to call a DLL, which multiplies every element of an array by two and sends the new array back to labview??
How can I do that?

Open the Example Finder (Help -> Find Examples) and do a search for "dll". Open the example called "Call DLL". You will find lots of examples of calling DLL functions with a wide variety of datatypes.
0 Kudos
Message 9 of 12
(2,799 Views)


@s21694 wrote:
By now I found, that I can´t use an array in c, but have to use a pointer instead. Is that correct?

Well I thought of writing the whole algorithm in labview, but the c-programm is about 700 lines.
I will see..


Unless your C program does lots of bit shuffling and bit level operations 700 lines of C code isn't so much to translate into LabVIEW.

However since you already seem to have the C code you simply would need to turn that into a DLL. Probably no need to write much C code if any at all. Then configure the Call Library Node correctly and you should be set. But considering your troubles to understand basic C concepts this might be a real challenge.

On the other hand if you do know what the algorithme does and how it does it, rewriting everything in LabVIEW might be in fact less troublesome (no crashes) and not really more time consuming and at the some educative in LabVIEW programming. I guess it is your call.

Rolf Kalbermatter


Message Edited by rolfk on 05-26-2008 09:27 AM
Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 12
(2,742 Views)