Use of C/C++ Codes in LabVIEW

How to use C/C++ compiled program in LAbVIEW?

There are two methods, depending on what the C/C++ application looks like:
DLL: Use the Call Library Function Node to call a single function from the DLL. You will need the information about the prototype of the function you are calling since you will have "to rebuild it".
EXE: Use the System Exec.vi. Please note that you can only pass data to the EXE if it has an approriate parameterset and you cannot get any data back using parameters. The only value available from EXE is the returnvalue which is normaly the errorcode.
hope this helps,
Norbert
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.

Similar Messages

  • Can I use C code in labview?

    Hello, I've got a fairly complicated program I've written in C that
    requires two doubles to be passed to it and it spits out two integers
    as a result of a very detailed calculation. Is there a way to have
    labview call this C function? I've tried searching the NI.com website
    but all I could find were examples where labview was being compared to
    C in an attempt to show how they are equal. Any advice/links to
    relevant information or tutorials would be greatly appreciated.

    You have two possibilities:
    Compile your C code into a DLL and call it with "Call Library Function Node".
    Use the "Code Interface Node".
    The LabVIEW Bookshelf (under help) contains a PDF document name "Using external code in LabVIEW". It will probably answer all your questions. Good luck
    LabVIEW Champion . Do more with less code and in less time .

  • Using Matlab code in LabVIEW

    Hi,
    I have never used LabVIEW and I am wondering if there is a way to run Matlab code in LabVIEW. If so, how would I do it and are there any special instructions or tips I should know about?

    What is your LabVIEW version?
    Do you have matlab installed on your computer?
    In older LabVIEW versions, you can only use the matlab script node, which requires that you have a copy of matlab installed.
    In newer versions, you have two more alternatives that don't require the purchase of Matlab:
    Use a mathscript node.
    Use a scilab script node.
    Information on mathscript: http://zone.ni.com/devzone/cda/tut/p/id/3502
    Information on scilab: http://zone.ni.com/devzone/cda/epd/p/id/657
    There is even a mathscript forum here: http://forums.ni.com/ni/board?board.id=MathScript
    LabVIEW Champion . Do more with less code and in less time .

  • How we can import and run the matlab codes in labview using xmath script.

    hello,
    i have some GUI code in MATLAB and i want to process that codes in labview . tell me about the procedure how we can done this task.
    thanks in advance
    rachana
    Er. (Instrumentation)

    Hello,
    The title of your post asks about using Xmath script.  Is this what you intended?  You can use the Xmath script node in LabVIEW if you have MATRIXx 7.x or earlier installed.  However, the syntax is slightly different from the syntax of The MathWorks, Inc. MATLAB® software.
    In LabVIEW 8.0, we introduced LabVIEW MathScript.  The LabVIEW MathScript syntax is similar to the MATLAB language syntax.  In LabVIEW MathScript, you generally can execute scripts written in the MATLAB language syntax.  However, the MathScript engine executes the scripts, and the MathScript engine does not support some functions that the MATLAB software supports.  In order to reuse code that you have written, open the MathScript Window by going to Tools >> MathScript Window.  You can also use the MathScript node as part of a VI you are writing.  You can find the node on the Programming >> Structures palette.  You can import an existing script by right-clicking the node and selecting "Import..."  You can create inputs and outputs for the script by right-clicking on the node and selecting the appropriate option.  If you wish to call any functions you have written, put them in the MathScript search path.  By default, this is your "My Documents\LabVIEW Data" folder.  In LabVIEW 8.5, you can change the default search path for the main application instance by going to Tools >> Options.
    LabVIEW MathScript does not contain very many GUI functions at this time.  You can use the VI's front panel as your GUI, though, and interact with your program that way.  Let me know if you have other questions about moving your code or about specific functions.
    MATLAB® is a registered trademark of The MathWorks, Inc.
    Grant M.
    Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments

  • How to use matlab code in Labview without having MATLAB software. I tried to convert .m files into .dll files. But i could not do. Please help me out..

    Please help me out...
    Solved!
    Go to Solution.

    bombay wrote:
    Yes. It can be done. But Math script can not evaluate all functions in .m files (There are some exceptions).
    And those can perhaps easily be ported to LabVIEW/MathScript?
    It is not sufficient to disregard running your Matlab code in LabVIEW based on a few exceptions without first thoroughly evaluating the impact they have.
    If you want to stick with Matlab in your implementation, then there are other avenues than hypotethizing about the limited portability issues of using MathScript in your project?
    Br,
    /Roger

  • How to we use CNC G-CODES in LabVIEW?

    I can't find any G-CODES interpretor for labiew.Anyone can help me? Here is my email for the conversation.
    [email protected]
    Thanks.

    Hi eniscelik,
    About integrating existing G-code into LabVIEW, unfortunately, LabVIEW does not currently have any way to do this, as there are no toolkits or modules designed for this type of application, but  NI has  Alliance Partners who specializes in this type of work.Design & Assembly Concepts, Inc. specializes in motion control and does support these types of applications.
    Otherwise you can keep trying to comunicate with Gharb (link below):
    http://forums.ni.com/t5/Motion-Control-and-Motor-Drives/G-code-interpreter-using-LabVIEW-done/td-p/2...  
    If our developers know our customers are asking for it, they will be able to appropriately prioritize their development time, so I would suggest you to go to our NI idea Exchange (find link below) to provide feedback on G-code support.
    http://forums.ni.com/t5/LabVIEW-Idea-Exchange/idb-p/labviewideas
    Regards.

  • What is the best way to add external C++ code to LabView 6.1?

    I have various C++ class-based DLL's written with Visual Studio 6.0 and wish
    to create instances of these C++ classes and call their methods in LabView
    6.1. What is the best way to do this?
    It seems based on the little reading I have done that there are two choices:
    1. Wrap the C++ class as a simple COM control and use LabView's COM based
    VIs to create a COM object and access the methods of various interfaces.
    2. Wrap the C++ class methods as C functions and a "constructor" and
    "destructor" C function to create and destroy an instance of the class. Then
    use LabView's DLL call support.
    Which is best? What direction is LabView going to take that better supports
    the notion of C++ class libraries?
    Thanks,
    Te
    rry

    You could also try using a CIN. This is a tool that LabVIEW provides for interfacing with external code.
    The CINTools libraries of LabVIEW allow you to embed compiled C code into a particular Virtual Instrument (VI) using a CIN.
    In order for LabVIEW to be capable of calling compiled functions of C from a running VI, the code must be loaded and unloaded into memory at the same time as the VI code itself. LabVIEW uses object code in the form of a .lsb file which is generated by the C compiler from the C source code using the ntlvsbm.mak file. This ntlvsbm.mak file is included in the CINtools directory in the LabVIEW folder. You also must create another .mak file which includes parameter definitions for the ntlvsbm.mak file and also includes a call to the LabVIEW .mak file.
    The generic documentation for CINs only explains how to use them to call C compiled code from a LabVIEW VI. It shows several development environments such as Visual C++, but in essence it only allows the user to create .lsb files out of plain C source code ( .c ) through C compilers on those environments.
    The question now is how can I create .lsb files from C++ native source code using a C++ compiler. Furthermore, how can I create a .lsb file from several C++ source code files (.cpp) and make calls to C++ functions from a VI using CINs? The following explains how to do this:
    1) Drop a Code Interface Node (from the Advanced Subpalette of the Functions Palette) into the LabVIEW VI. Make sure to wire the inputs.
    2) Right-click on the CIN and choose "Create.c File...", then in the file dialog box specify a "name.cpp" file name. (very important: use .cpp extension)
    3) Then create a name.mak makefile (text file) and add the following lines :
    name=name_of_cpp_file_without_the_extension
    type=CIN
    cinlibraries=Kernel32.lib
    CINTOOLSDIR=path_to_cintools_directory
    !include <$(CINTOOLSDIR)\ntlvsb.mak>
    4) Go into Visual C++ and File>Open and open the .mak file. You can even Add the name.cpp file to the project to make it easier to edit. Select that name.cpp or open it as a text file in NotePad or and edit the prototypes of the CIN MgErr functions as shown below, adding extern "C" at the beginning of the line. extern "C" CIN MgErr CINRun(float64 *INPUT);3) Select Build.exe to create the "name.lsb" file. To import the .lsb into LabVIEW, right-click on the CIN and choose "Load Code Resource...". Then, choose the name.lsb file and it is ready to run!
    If you want to use several C++ source code files with .cpp extensions, then compile them in Visual C++ and link them to name.cpp and create a .lsb by modifying the name.mak as follows:
    name=name_of_cpp_file_without_the_extension
    otherobj=other_cpp_files_BUT_USING_.obj_extension
    type=CIN
    cinlibraries=Kernel32.lib
    CINTOOLSDIR=path_to_cintools_directory
    !include <$(CINTOOLSDIR)\ntlvsbm.mak>
    It's worth a try? I have also heard of using clusters to represent classes, so you could check that out.
    J.R. Allen

  • Extra bytes in data transfer when using VISA and C++ instead of LABVIEW

    Hello,
    I've a problem when I try to download the capture buffer from a spectrum analyzer with C++Builder and VISA.
    If I do that with LABVIEW (with VISA read and write) everything is fine. Instead, with C I get extra bytes in
    the stream. In particular whenever there is a '0A' in the stream I get also a '0D' before it. I'm using a GPIB-USB-B card from National. I know I could easily get rid of those extra bytes in my code, but I'd like a cleaner solution.
    Does anybody know the difference between the following code and LABVIEW VISA read and write routines?
    Is there some attributes I have to set in C which is automatically set in LABVIEW?
    Thanks a lot in advance!!
    Simone
    ViSession defaultRM, vi;
    viOpenDefaultRM (&defaultRM);
    viOpen (defaultRM, "GPIB0::10::INSTR", VI_NULL,VI_NULL, &vi);
    ViStatus err = viSetAttribute(vi, VI_ATTR_IO_PROT, VI_NORMAL);
    ViUInt32 retCount;
    err = viWrite(vi, "CGET?0,0\n", strlen("CGET?0,0\n"), &retCount);
    ViByte* buffer = new ViByte[100000];
    err = viRead(vi, (ViByte*)buffer, 100000, &retCount);
    FILE *fp;
    fp = fopen("data", "w");
    fwrite (buffer, retCount, sizeof(ViByte), fp);
    fclose(fp);
    viClose(defaultRM);
    viClose(vi);
    delete []buffer;

    Simone,
    this has to do with LabVIEW running on multiple platforms with different End-of-line signals.
    With Windows this is usually 0x0d0a, which is the ASCII control code for . Other platforms use typically just one of those characters; I believe with MacOS there used to be just a 0x0a and with Unix this might have been 0x0d.
    In order to avoid hazzles, the LabVIEW develloper decided to convert the platform-specific End-of-line signals into a LabVIEW-internal character (which is 0x0a) when reading strings and back when sending strings out of LabVIEW.
    So, your device sends out 0xd0a and LabVIEW removes the 0x0d. Everything is OK.
    Greetings from Germany!
    Uwe

  • Using pixelink software development kit with labview

    hi,
    i am currently using the pixelink camera pl b741 f, however i am facing a problem when i use the "get frame dll" in labview.
    my program works when in highlight execution mode, however when i run it in normal mode i get the following message:
    Labview: an exception occurred within the external code called by a library node function node. This might have corrupted labview's memory. Save any work to a new location and restart labview. VI "amol_getimage.vi" was stopped at node "" at a call to "MEPU- acquisition-getframe .vi"
    can you please help me!
    thanks
    amol

    amolchoudhary wrote:
    hi,
    i am currently using the pixelink camera pl b741 f, however i am facing a problem when i use the "get frame dll" in labview.
    my program works when in highlight execution mode, however when i run it in normal mode i get the following message:
    Labview: an exception occurred within the external code called by a library node function node. This might have corrupted labview's memory. Save any work to a new location and restart labview. VI "amol_getimage.vi" was stopped at node "" at a call to "MEPU- acquisition-getframe .vi"
    can you please help me!
    It's simple! You made an error in the configuration of your Call Library Node. It could be a number of reasons but the two most likely ones are that you get a variable wrong to be passed by Value while it should be by Reference or vice versa, or that you call the function which expects a buffer it can write in the results (the image frame is a likely candiate) and didn't create a large enough buffer in LabVIEW to be passed to the function.
    I actually think this last one is by far the most likely reason here and in fact the number 1 error done by most people that try to interface to a DLL through the Call Library Node. DLLs come from the C world and want to be called like that and one important rule there is that memory buffers to be filled, must always be created by the caller. This is different in LabVIEW itself since LabVIEW manages all the memory for you and allocates it whenver necessary but this can't work for calling DLLs as LabVIEW has ABSOLUTELY no way to know what a DLL function might need as memory buffer.
    You can create such a buffer by either executing the Initialize Array function with the correct parameters or in LabVIEW 8.2 you can directly configure array and string parameters in the Call Library Node configuration to create the necessary buffer. I prefer the Initialize Array variant since the other one is a LabVIEW 8.2 only feature and creates a fixed size buffer while for your frame buffer you will likely have to allocate a memory buffer whose minimum size depends on the bitmap format and bitmap size the function is going to return.
    Rolf Kalbermatter
    Message Edited by rolfk on 06-29-2007 07:27 PM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How to implement this code in labview?

    How do implement this pseudo code in labview? Please keep in mind "a" and "c" in the code below ARE VARIABLES
    for i =0 to i=maxvalue
           if i <= a 
               output = output2
           else if i > a AND i<=c
               output = output2
           else if i < c 
               output = output3
           else i = d
               output = output4
    I understance i can use a case structures and modify the label, but i do not know how to make the label dependent on a variable value. 
    Thanks 

    Try an array of boudaries and use threshold array. See this old example:
    Now just iterate over an array of values using a FOR loop.
    LabVIEW Champion . Do more with less code and in less time .

  • Best way to implement this code in labview

    Hi
    What is the best way to implement this code in labview programming.
    I have an analogue input which triggers a boolean light when it reaches a certain voltage. but at the same time i would like it to enable two other outputs one for a set period of time and the other stay on until another statement becomes true.
    For example
    case 1:
    Set output high
    Delay(2000ms)
    Set output low
    Case 2:
    Set output high
    If statement 2 is true
    then set out put low
    if not then repeat until statement is true
    Thanks for your help

    Hi David,
    The code you posted will work, although note that the front panel becomes 'unresponsive' - as changes in the controls are only read once per iteration.  The wait function is an example of an execution timing VI, however if we want to do software timing (like a 2 hour wait) - we should use software timing VIs.
    Check out the following example (note we can stop execution during run-time):
    Regards,
    Peter D
    Attachments:
    SoftwareTiming.vi ‏26 KB

  • How i can generat VHDL or Verilog code from labview code

    how i can generat VHDL or Verilog code from labview code ( i have a labview code and i want to convert it to VHDL or Verilog code how i can do that )

    Mouath,
    There is no feature in LabVIEW to export your VIs as VHDL files. You are able to include your own HDL in your LabVIEW VI (using the HDL node). I encourage you to provide your feedback related to this issue at ni.com/contact. The product suggestion submitted are taken seriously and reviewed by National Instruments.
    Cheers,
    Jonah
    Applications Engineer
    National Instruments
    Jonah Paul
    Marketing Manager, Embedded Software
    Evaluate the LabVIEW RIO Platform! - ni.com/rioeval

  • How can I use a non-NI card in LabVIEW RT environment

    We built up a LabVIEW RT environment with LabVIEW 7.1 and relating drivers. There is a problem that we use some non-NI cards in this system and we did not know how to install the dll driver.
    Could you give me some ideals?
    Thanks a lot!!
    Regards,
    Yang Xin

    As it states in the LV RT User Manual - Appendix A (7.0) you might get more info on ni.com/info with info code RTDRVS.
    What kind of instrument/io-/bus-cards are you using?
    As I thought the VI calling the DLL would download the dll to the RT target automatically when run the VI. However, there are probably some restrictions (e.g. Call Library Nodes that access an operating system API other than Pharlap).
    In the 7.0 release notes it is mentioned: When building a start-up application that uses shared libraries (DLLs) with the LabVIEW Application Builder, LabVIEW opens the DLLs Used by Application dialog box and lists the DLLs used by the application. Some DLLs might report the following error:
    Target OS fails to load this DLL
    Ignore the warning and click th
    e OK button if you already transferred the DLL to the RT target. If you have not transferred the DLLs to the target, FTP the DLLs to the /ni-rt/system directory of the RT target.
    Note as well: Why Does My DLL Call Cause My LabVIEW Real-Time VI to Fail to Download?
    Let us know.
    Roland
    PS: These are links to start with.
    Developing a LabVIEW Real-Time Driver for a PXI or Compact PCI Device
    Configuring LabVIEW Real-Time and NI-VISA to Recognize a Third Party Device
    Using VISA to Write Drivers Supported in LabVIEW Real-Time for Thi
    rd Party PXI Cards.
    Programming for the LabVIEW Real-Time Module Using LabWindows/CVI

  • How to generate and use Matlab(R2007) .dll's in Labview

    Is there a step-by-step example on how to generate and use Matlab(R2007)  .dll's in Labview.
    Our experimenal hardware is LabView-controlled and we want to pass
    images/2d intensity arrays to a more complex matlab program that will
    return an array of extracted data which we want to use in LabView again.
    Thank you
    Carsten

    I recommend having a wrapper created around the matlab dll that converts the datatypes for you. There is a lot of fooling around with pointers involved which is very difficult in LabVIEW. btw, this got much more complicated after Matlab 7. Essentially, you need to convert your inputs into mxArrays, and then add those mxArrays to an mxArray list that you pass by pointer into the matlab dll. You also need to create a mxArray list for the outputs from the dll which you will need to extract your data out of before converting it back into a LabVIEW supported datatype. It's a big hassle. We do this pretty often, but we have created a c library that handles all the conversions, so it is feasible for us. Unfortunately, I can't share the library, but hopefully this information will help you get where you want to be.
    Like I said, it would be easier if you can just get a c developer to write a wrapper for you to keep it simple in LabVIEW. Alternatively, you might try getting your m-code to work in Mathscript.
    Chris

  • Converting HP-BASIC code into Labview or Labwindows

    I need some insight on as to whether I can use all my HP-Basic code in labview or labwindows and how? Can I create dlls and call them into labview or use the code itselg in LabWindows?
    Any information will be appreciated.

    A very long time ago, there was a BASIC version of LabWindows.  You could not convert a Rocky Mountain BASIC program directly, but it was a fairly simple fit.  You could then translate that into C code automatically through LabWindows.  That was one of its selling points; you didn't have to lose all of that old BASIC code.  About 10 years ago, they decided to go with only a C version of LabWindows and renamed it LabWindows/CVI.  This change was made because most people who were converting from BASIC to C already had and supporting two languages and a translator was very expensive (cost, memory, processing power, complexity, - expensive in every way). 
    If someone has an old version, you might have an upgrade path with your old code (no, I don't have any that old).  Otherwise, you could build DLLs and call them with either LabVIEW or LabWindows/CVI.  You could also recreate the code with the newer language.
    Hope that this helps,
    Bob Young
    Bob Young - Test Engineer - Lapsed Certified LabVIEW Developer
    DISTek Integration, Inc. - NI Alliance Member
    mailto:[email protected]

Maybe you are looking for