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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview C functions

Hello , my teacher told me to post on this forum if i need help with my project. I need to do a C code D L L for Lab view in which i will have many functions implemented and i ran into some problems regarding 2 of those functions.I'm using the Call Library Function Node to call those functions into Lab view.

The first function is like this : i have to input an array (double type) and "n"(int type) as the number of elements into the array. My functions has to output 2 things : 1. the medium value of the elements in the array and 2.the array sorted. I did the first thing with the medium value , but i can't seem to do the sort of the array , probably it's a coding thing , i don't know. I tried a basic bubble sort , still not working. I can also split this into 2 functions , one for the medium value and one for the sort , but the sort one still won't work properly.

The second function should be even easier than the first one . My inputs are again a "double array" , an "int n" and this time a "char c". The function has to output one thing : if the character given is found among the elements of the array. Now i know i can't have a Boolean output from the Call Library Function Node, that's why i was thinking "return 1 if it's true , else return 0" . My code should work , but in Lab view it isn't ...

I attached the 2 codes that i tried .

I'm using Lab view 2018.

Download All
0 Kudos
Message 1 of 4
(2,159 Views)

Give us a break!  Suppose one of us wants to run your code -- how do you expect us to do this?

  1. View code, hopefully on a single screen.
  2. Do a Print Screen.  Oops, I'm working on my laptop, don't have a printer, so I'll wait until I'm at work.
  3. Fire up C and type it in, hoping I don't make any mistakes.
  4. Say "Why am I bothering to help this user, who won't help me by attaching the code in a file format (e.g. a .c file) that I can just use?"

Note that usually when I go on these rants, it's because someone has attached a picture (and, like you, they used .jpg, a lossy image format, so the image might be blurry or pixelated) instead of the code (a .vi file, in the case of LabVIEW).  But the same principle applies.

 

Bob Schor

0 Kudos
Message 2 of 4
(2,132 Views)

Sorry , it's my first time posting something on a forum . I'll post the code from the screenshots here:

Boolean:

#include <stdio.h>

extern "C" __declspec(dllexport)int searchchar(char c,double sir[],int n);

int searchchar(char c,double sir[],int n)
{
   int i;
   for(i=0;i<n;i++)
       if((double)c==sir[i])
            return 1;
return 0;
}

 

Sort:

#include <stdio.h>

extern "C" __declspec(dllexport) double ValMed(double sir[],int n);

double ValMed(double sir[], int n)
{
   int i;
   double sum=0;
   for (i = 0; i < n; i++)
    sum=sum+sir[i];
   return sum/n;
}
extern "C" __declspec(dllexport) double sortare(double sir[],int n);
double sortare (double sir[],int n)
{
    double aux;
    for(int i =0;i<n;i++){
    if(sir[i] < sir[i+1])
        aux = sir[i];
        sir[i]=sir[i+1];
        sir[i+1]=aux;
}

return sir[10];
}

 

 

0 Kudos
Message 3 of 4
(2,128 Views)

We'll need some LabVIEW code to see what is wrong with the LabVIEW code...

 

My guess: change the calling convention...

 

Not sure why you'd do this in a dll. Is this LabVIEW class or C class homework?

0 Kudos
Message 4 of 4
(2,097 Views)