Calling labVIEW vi from matlab

i want to pass data (modulated sine wave) from matlab into labview,
transmit it (through the NI-DAQ card) into a channel, receive it back
on the input port of the card and pass the data back from labVIEW into
matlab. i built the vi and compiled the corresponding mex function.
when called, the function runs without error but the problem is that i
get back only noisy values and i have also verified with the help of a
CRO that no actual wave is transmitted. i.e., it seems that the labVIEW
vi doesn't actually run (though the LabVIEW window does open). this
after i have selected the "load front panel" option in the vi
properties. i might add that when i created a vi that uses the
"simulate sine signal" tool of labVIEW itself to transmit a sine wave
over the channel (As against using data from matlab, as in the former
case) but receive the data into matlab only (as in the former case),
the VI runs when called from matlab, the CRO shows sine waves being
transmitted and received and the data i receive into matlab is an
attenuated sine wave as expected. any MIT pro who can help me out?
Thanks.

It sounds like the problem is not that the VI isn't running, but rather that the data it is "receiving" from MATLAB is getting messedu up. This conclusion is drawn, of course, from the fact that simulated data can successfully be written and read in LabVIEW and passed to MATLAB using the same methods. The only way to get to the bottom of this dilemma is going to be to do some good, old-fashioned troubleshooting.
Since we believe that the problem lies in MATLAB passing data to LabVIEW, the first thing you can try is putting a pause at the beginning of your LabVIEW code and creating a graph on the VI's front panel to show the data before it is written. If it is jumbled there, then you'll next want to check the data inside of MATLAB before it is passed. If that data is okay, then you've narrowed it down to the actual transfer, and you should then start making sure that you are matching the proper datatypes and formats. Hope this points you in the right direction!
Kind Regards,
E. Sulzer
Applications Engineer
National Instruments

Similar Messages

  • Call LabVIEW VIs from MATLAB

    Does anybody know of a simple way to call LabVIEW VIs from within a MATLAB m-file?  I would like to be able to write VIs in LabVIEW and then script them (for stochastic analysis, etc.), and think MATLAB would be an awfully convenient way to do this (also useful for data analysis, etc.).  I have looked at LuaVIEW, but it appears to have been largely abandoned.
    Thanks!

    Hello Erik,
    Building it into a DLL as Altenback said is a solid way to do this, and here's a Knowledge Base article that also explains how to transfer data in binary or ASCII format, How do I Transfer Data Between The MathWorks, Inc. MATLAB® Software Development Environment and LabV... 
    Thank you,
    Deborah Y.
    LabVIEW Real-Time Product Marketing Manager
    Certified LabVIEW Architect
    National Instruments

  • How to call labview DLL from C#, passing char, char[], float[], long, short

    Hi,
    I'm having trouble calling labview dll from C# to perform certain function.
    The function supposed to return the values in the float Analysis[] array. However, when I execute it it only returns zero values.
    It seems that some parameters are not properly passed to the dll.
    Below is the function in the header file:
    void __stdcall Optical_Center(char FileDirectory[], long ImagePtr,
        short int Height, short int Width, char ReadFromFile, float Analysis[],
        long lenAnalysis);
    and my corresponding dll import in c#:
    [DllImport(@"SMIA.dll", CharSet = CharSet.Ansi)]
            public static extern void Optical_Center([MarshalAs(UnmanagedType.LPStr)]string FileDirectory, long ImagePtr,
                short Height, short Width,char  ReadFromFile, IntPtr Analysis,
                long lenAnalysis);
    string str = @"C:\SMIA.raw";
    int len = 3;
    long m_lenAnalysis = 3;
    long m_ImagePtr = 0;
    short m_Height = 2464;
    short m_Width = 3280;
    IntPtr m_PtrArray = Marshal.AllocHGlobal(len * Marshal.SizeOf(typeof(float)));
    char m_ReadFromFile = '1';
    Optical_Center(str,m_ImagePtr,m_Height,m_Width,m_ReadFromFile,m_PtrArray,m_lenAnalysis);
    float[] m_Analysis = new float[len];
    Marshal.Copy(m_PtrArray, floatArray,0,len);
    Marshal.FreeHGlobal(m_PtrArray);
    string printstr = "";
    for (int i=0; i<len; i++)
        printstr = printstr + floatArray[i].ToString() + "\n";       
    MessageBox.Show(printstr);
    Appreciate if anyone can help, thanks.
    KL

    I was just about to post the header file of the DLL, when
    I noticed that there's a function called LVDLLStatus.
    This little thingie turned out to be a rather handy tool.
    With that function I found that in the DLL I had a problem
    with another function that prevented the DLL to be correctly
    loaded.
    This other function in the DLL is for generating digital output
    and it worked as it should, when tested from LV.
    Anyway if someone is interested, I got it working by using
    the LoadLibrary and GetProcAddress function, as in the
    source code thatI posted earlier.
    I will investigate what is wrong with that digital output, and
    post into a another thread if I have problems with that.

  • How to call LabVIEW dll from ATL COM dll

    I have tried to call simple LabVIEW 8.6 Dll from win32 test application, class Library.
    I have include LabVIEW generated SharedLib.h file and SharedLib.lib file in the test application which I created as simple win32 console project and also from win32 class Library. I was sucessfully able to call my LabVIEW dll funtion. 
    But when I create ATL COM project and try to add SharedLib.h file and SharedLib.lib file I used to get following erors
    Error 1 error C2733: second C linkage of overloaded function 'StrCatW' not allowed d:\program files\national instruments\labview 8.6\cintools\extcode.h 463 
    Error 2 error C2733: second C linkage of overloaded function 'StrCpyW' not allowed d:\program files\national instruments\labview 8.6\cintools\extcode.h 464 
    Error 3 error C2733: second C linkage of overloaded function 'StrCpyNW' not allowed d:\program files\national instruments\labview 8.6\cintools\extcode.h 465 
    Error 4 error C2733: second C linkage of overloaded function 'StrCmpW' not allowed d:\program files\national instruments\labview 8.6\cintools\extcode.h 466 
    Error 5 error C2733: second C linkage of overloaded function 'StrCmpNW' not allowed d:\program files\national instruments\labview 8.6\cintools\extcode.h 467 
    these many errors.
    Will some one explain me how to call LabVIEW dll from ATL COM dll.
    Thanks & Regards,
    Jay

    I also had this problem.  My application is unicode-aware, but I was attempting to link it to a library with primitive C-string arguments.  You could dynamically load the DLL as suggested (more work), modify the header files (really not recommended), or if you are feeling lucky you could try fooling the compiler, as I was successfully able to do in Visual Studio 2010, by steering the preprocessor around those functions (assuming you're not using them, of course -- otherwise this probably wouldn't work):
    // prepare for NI extcode.h inclusion. avoid linker errors for this project.
    #define StrCatW(a,b)     IgnoreLinkError_StrCatW(a,b);
    #define StrCpyW(a,b)     IgnoreLinkError_StrCpyW(a,b);
    #define StrCpyNW(a,b,c)  IgnoreLinkError_StrCpyNW(a,b,c);
    #define StrCmpW(a,b)     IgnoreLinkError_StrCmpW(a,b);
    #define StrCmpNW(a,b,c)  IgnoreLinkError_StrCmpNW(a,b,c);
    // header file for my LabView-built DLL (ASCII single-byte character arguments)
    #include <MyLibraryHeader.h>
    // clean up afterwards, put things back to 'normal'
    #undef StrCatW
    #undef StrCpyW
    #undef StrCpyNW
    #undef StrCmpW
    #undef StrCmpNW

  • Calling labview VIs from python in Linux

    Hello.
    I've spent some time searching for this but I haven't found exactly what I was hoping for.
    I'm involved in a project that we're starting now and it involves creating a complex software architecture in order to control a robot. This software will need to perform multiple tasks such as interfacing with hardware (which LabView is perfect for) as well as planning and high performance image processing (which LabView isn't as great for).
    I was hoping to be able to use a scripting language like python to manage high level stuff (planning, behavior, etc) by calling "subroutines" in other languages such as C++ for the high performance stuff and LabView VIs for the hardware interfacing. I would also like this to run on Linux.
    I've found a lot of suggestions on how to call Python scripts from within LabView but this is not what I want. I want exactly the opposite, invoke VIs from Python. I found some information on how to do this on Windows (http://zone.ni.com/devzone/cda/tut/p/id/5719) but this article seems to assume that Windows is being used.
    Does anybody have an idea on how to do this? 

    Unfortunately that's not an option. This is an interdisciplinary school project involving students from engineering (mechanical, electrical and more), computer science and more fields. Some of these students have gotten used to using Labview and this is the main reason I'm trying to accomplish this. I want to have the higher level architecture done in a scripting language such as python which will enable us to create modules in various different environments such as C++ for tasks requiring high performance (image processing for example), Labview for tasks that the people used to using that and even something running on the GPU if there's use for that. Python would make it easy to glue all these components together while maintaining an environment that would make it very easy to configure the whole software system in different ways.
    I'd also prefer that this all run on Linux.
    The more I look for this the more hopeless I get I'll find anything which is very frustrating. It's a bit hard to believe that Labview doesn't have "python bindings" for running the VIs from within python :-(

  • How to call Labview DLL from VB2005

    Dear all expert,
    I'm a student and very new in Labview programming.
    Currently i have build a simple vi and need to convert it to dll so that i can call it from my VB.net. But the problem is how to call the labview dll from my VB.net?
    I know we must declare function something like this,
    Auto function Bodeplot Lib"..\\Bodeplot.dll" (Byval Val1 as double, Byval Val2 as double,...) as double
    but how to determine Val1, Val2 (and so on) is input for which data?  if my vi have 10 input (frequency, Kc,Fcz,Fcp,Wzrhp,Wp,k,Wz,Beta and Operation) ? and how to select the output (my application have 3 possible output : magnitup loop,phase loop, and degree loop)
    In addition, since I'm using Labview 8.0 , and as i know apllication  builder for this version cannot convert vi to dll which contain Mathscript (but unfortunely, my vi all use Mathscript), so really hope someone can help me to convert my vi to dll using Labview 8.2 (which remove this limitation).
    here I'm attach my Vi and really hope someone willing to help.
    Thank you.
    Attachments:
    bodeplot.vi ‏1049 KB

    On Sep 17, 6:40 am, cckoh <[email protected]> wrote:
    > Dear all expert,
    > I'm a student and very new in Labview programming.
    > Currently i have build a simple vi and need to convert it to dll so that i can call it from my VB.net. But the problem is how to call the labview dll from my VB.net?
    > &nbsp;
    > I know we must declare function something like this,
    > &nbsp;
    > Auto function Bodeplot Lib"..\\Bodeplot.dll" (Byval Val1 as double, Byval Val2 as double,...) as double
    > &nbsp;
    > but how&nbsp;to determine Val1, Val2 (and so on) is input for which data?&nbsp; if my&nbsp;vi have&nbsp;10 input (frequency, Kc,Fcz,Fcp,Wzrhp,Wp,k,Wz,Beta and Operation)&nbsp;? and how to&nbsp;select the output (my application have 3 possible output : magnitup loop,phase loop, and degree loop)
    > &nbsp;
    > In addition, since I'm using Labview 8.0 , and as i know apllication&nbsp; builder for this version cannot convert vi to dll which contain Mathscript (but unfortunely, my vi all use Mathscript), so really hope someone can help me to convert my vi to dll using Labview 8.2 (which&nbsp;remove this limitation).
    > &nbsp;
    > here I'm attach my Vi and really hope someone willing to help.
    > &nbsp;
    > Thank you.
    > &nbsp;
    >
    > bodeplot.vi:http://forums.ni.com/attachments/ni/170/272124/1/bodeplot.vi
    If you insist on using Labview with your project then you should
    consider using ActveX in place of using a dynamic link library to
    interface to your VB.net code. You don't need "Application Builder"
    if you use ActiveX. The Student, Basic and Full development versions
    of Labview for Windows come with ActiveX capability. For more
    information on ActiveX look up the subject ActiveX in Labview's Help
    File.
    Howard

  • Call a function from matlab labview

    hi,
    I would like to know how can I do to write a string on the front panel of Labview and write simultaneously in the Matlab command window.
    Thank you

    You can pass the string to a MATLAB script node and use eval() to execute it in a MATLAB environment.

  • Calling LabView DLLs from C/C++

    Hi!
    Is it possible to call functions in the LabView DLLs directly from
    C/C++?
    Functions like InvChiSquare in lvanlys.dll has "Adapt to Type" void *
    parameters. How do I specify those parameters from C/C++?
    I have tried to use the "Build Shared Library" function in LabView to
    make a wrapper dll of the "Inv Chi Square Distrubution" vi, but when I
    call this function in the dll from C/C++ the function never returns.
    Other functions in the same dll that does not use functions in the
    lvanalys.dll are working ok.
    Regards
    Hans Forssell

    There are 2 great places to get infomraiton on passing data to dlls, and the data types used. First would be this manual. Using External Code in LabVIEW
    The second is the dll examples that ship with LabVIEW 7.0. Go to LabVIEW 7.0\examples\dll\data passing\Call Native Code.vi

  • Calling labview executable from teststand

    I have a labview VI that I build into an exe, and I'd like to call it from my teststand sequence in the setup - other test steps need to use its capabilities in the remainder of the sequence (main).  If it were just a VI, then no problem, the inputs would be visible to me, and I could pass them in.  Since it's an executable, though, my step is of type "Call Executable", but I don't see anywhere that it allows me to pass in the inputs it needs.  Thoughts?
    Solved!
    Go to Solution.

    What version of TestStand are you using?  With TestStand 4.0 for the 'Call Executable' step there is a line called
    Argument Expression:
    Enter your parameters to pass into your LabVIEW executable.  You will have to know which ones to pass in and in what order. I believe you can seperate the arguments by spaces.  In my attachment, I pass in one parameter to a LabVIEW executable.
    Remember, though you have to set the Build properties in LabVIEW to allow it to Pass command parameters to the application.
    Thanks,
    PH
    Attachments:
    Call Executable.JPG ‏48 KB

  • Segmentation fault when calling gpctr function from matlab mex file

    I am trying to write a simple mex file for square wave generation using counter1 of PCI-6035E. I am using matlab's native compiler to compile and link with the nidaq32 library, ver.6.9.3, with no errors. When the mex function is called from a matlab script, however, the program crashes at the first call, to reset the counter. (I can generate a square wave with the test panel.)

    Sorry for the delay in responding. I got caught up in other stuff. I am attaching my little program as requested. As you can see, I have just wrapped a mexFunction call round the example code for square wave generation. After I posted this, I tracked down a copy of BorlandC++, installed it on my computer and recompiled using that compiler and *b.* libraries. And would you know it, the program works. The question remains, though, why it doesn't work with Matlab's native lcc compiler. Plus, I have limited disk space, so if I can do without BorlandC, I can use the extra room. The runtime error was a Segmentation fault that I traced to the first call to GPCTR_Control.
    Attachments:
    pulsegen.c ‏4 KB

  • Calling LabVIEW DLL from C with 2d array strings

    I am trying to write a DLL in C that calls a LabVIEW DLL that has a
    number of functions that each return a 2D array of strings which are the formatted
    measurements, with column 1 being the measurement name and column 2
    being the measurement. I wanted to use the 2D array of strings since
    this would give a uniform interface for returning measurements. Ive
    cobbled together bits and pieces of messages and example code I've
    found here into something that almost works, and was hoping someone
    with a little more experience in interfacing C with LabVIEW DLLs would
    be able to help me.
    Here's a little
    snippet from the header file generated when building the LabVIEW DLL:
    typedef struct {
    long dimSizes[2];
    LStrHandle String[1];
    } TD1;
    typedef TD1 **TD1Hdl;
    long __cdecl TestVI(char serialNumber[],  TD1Hdl *formattedMeasurements, char ErrorDescription[], long len);
    The "TestVI" VI generates a 2D array of strings. The cell contents and number of rows are random to
    simulate different measurement names and measurements.
    Here's a snippet for the wrapper class:
    class CArgoTestsLabVIEW 
    public:
    CArgoTestsLabVIEW();
    virtual ~CArgoTestsLabVIEW();
    // test modules called from parent DLL
    BOOL GetResult_LV(CString resultName, double *result);
    long TestVI_LV(CString serialNumber);
    private:
    TD1Hdl m_LVStringArray;
    CMapStringToString m_resultMap;
    InitMeasurementsArray();
    PopulateResultMap();
    The "m_LVStringArray" is intended to hold the 2D array of strings that
    the test modules spit out. The "m_resultMap" is just for accessing the
    measurements from the parent DLL via the "GetResult_LV" function.
    The implementation of TestVI_LV is:
    long CArgoTestsLabVIEW::TestVI_LV(CString serialNumber)
    long rc = 0;
    char errStr[BUFFERLEN];
    strcpy(errStr,"");
    rc = InitMeasurementsArray();
    if (rc == 0) {
    rc = TestVI(serialNumber.GetBuffer(serialNumber.GetLength()), &m_LVStringArray, errStr, BUFFERLEN);
    PopulateResultMap();
    return rc;
    The accessor functions InitMeasurementsArray and PopulateResultMap are:
    long CArgoTestsLabVIEW::InitMeasurementsArray()
    MgErr err;
    if (m_LVStringArray)
    DSDisposeHandle(m_LVStringArray);
    m_LVStringArray = (TD1Hdl)DSNewHandle(sizeof(TD1));
    // code to check for NULL
    // Set number of strings in array to 0
    (*m_LVStringArray)->dimSizes[0] = 0;
    (*m_LVStringArray)->dimSizes[1] = 0;
    // Set total size of array structure. For now it is only as big as the long variable.
    err = DSSetHandleSize((UHandle)m_LVStringArray, sizeof(long));
    // code to check for error
    return 0;
    void CArgoTestsLabVIEW::PopulateResultMap()
    int numberOfResults;
    int i;
    int charCnt;
    numberOfResults = (*m_LVStringArray)->dimSizes[0];
    if (numberOfResults == 0) {
    return;
    m_resultMap.RemoveAll();
    for (i = 0; i < numberOfResults; i++) {
    charCnt = (*((*m_LVStringArray)->String[i * 2]))->cnt;
    (*((*m_LVStringArray)->String[i * 2]))->str[charCnt] = '\0';
    charCnt = (*((*m_LVStringArray)->String[i * 2 + 1]))->cnt;
    (*((*m_LVStringArray)->String[i * 2 + 1]))->str[charCnt] = '\0';
    m_resultMap.SetAt((LPCTSTR) (*((*m_LVStringArray)->String[i * 2]))->str, (LPCTSTR) (*((*m_LVStringArray)->String[i * 2 + 1]))->str);
    The problem I have is that I eventually get an access violation from
    the run-time engine if I try to call the test VI in a loop. I'm
    obviously having a memory management problem, but it escapes me as to
    where the problem is. Anybody have any ideas?

    smercurio_fc wrote:
    The problem I have is that I eventually get an access violation from the run-time engine if I try to call the test VI in a loop. I'm obviously having a memory management problem, but it escapes me as to where the problem is. Anybody have any ideas?
    (*((*m_LVStringArray)->String[i * 2]))->str[charCnt] = '\0';
    Hi smercurio,
          Have you solved this?  I don't work with C much anymore, but it looks, here, as if the memory at str[charCnt] isn't yours to address/change.
    Is index "charCnt" one char past the end of the String-memory allocated by LabVIEW? 
    just an idea!
    Hmmm, maybe page 9 is a bit far back to fish in the unanswered posts.
    Message Edited by Dynamik on 03-03-2006 02:03 AM
    When they give imbeciles handicap-parking, I won't have so far to walk!

  • How to call labview DLL from visual C++?

    Hi,
    I'm trying to call a LV DLL from a VC++ application
    by using the LoadLibrary and GetProcAddress functions.
    The DLL contains a simple sum function. The Library is
    loaded correctly, but the result is always 0.0000.
    I have loaded a VC++ DLL in a similar way and it works
    correctly. Also, I have tested the DLL by loading it in LV,
    and it works correctly. The calling convention is defined
    to be stdcall in LV Application Builder.
    I have also tried this solution, but I will get a compiler error
    from one the header files that are created by the LV when
    the DLL is made. The error comes from this line
    typedef char                int8;
    and the error states that
    ..\fundtypes.h(107) : error C2371: 'int8' : redefinition; different basic types
    If someone knows of newer tutorial(for LV 8.2) or knows how to use those
    LoadLibrary and GetProcAddress function for LV DLLs, I will appreciate the
    information greatly.
    Below is the code that I'm using for loading the LV DLL.
    Thanks
    #include "stdafx.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <map>
    #include <windows.h>
    int _tmain(int argc, _TCHAR* argv[])
        HINSTANCE LVLib = LoadLibrary(TEXT("Testdll"));
        typedef double (__stdcall *MYPROC)(double, double);
        if (LVLib != NULL)
            MYPROC ProcAdd = (MYPROC) GetProcAddress(LVLib, "Add");
            if (ProcAdd != NULL)
                double d = (ProcAdd)(5.5, 6.6);
                printf("sum = %f\n", d);
            else
                printf("Invalid function pointer\n");
        else
            printf("Failed to load the library\n");
        return 0;

    I was just about to post the header file of the DLL, when
    I noticed that there's a function called LVDLLStatus.
    This little thingie turned out to be a rather handy tool.
    With that function I found that in the DLL I had a problem
    with another function that prevented the DLL to be correctly
    loaded.
    This other function in the DLL is for generating digital output
    and it worked as it should, when tested from LV.
    Anyway if someone is interested, I got it working by using
    the LoadLibrary and GetProcAddress function, as in the
    source code thatI posted earlier.
    I will investigate what is wrong with that digital output, and
    post into a another thread if I have problems with that.

  • Example code for calling LabVIEW VI from C#

    I'm a bit rusty about LabVIEW. Haven't used it for about three years now
    I'm making an automation tool in Visual C# where the user should be able to select a VI to call and setup the input and output parameters.
    I must then make some VI-browser code where inputs and outputs are listed for a selected VI.
    I will also have to make the code that opens and runs the selected VI.
    Any hints and links could help as I havent done much "Call VI Server" or COM Interop with C# yet.
    /Jan

    Hello Jan
    I have a link to an example that shows how to control a LabVIEW VI through ActiveX.
    http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3DC9156A4E034080020E74861&p_...
    Will this work for you...
    Regards
    Mohadjer
    NI-DK

  • Calling LabView dlls from VB

    I am using the .net environment and this NI e xample...
    http://zone.ni.com/devzone/cda/epd/p/id/3990
    which is just a simple dll that outputs some numbers.
    I get the following error
    Attempting managed execution inside OS Loader lock. Do not attempt to
    run managed code inside a DllMain or image initialization function
    since doing so can cause the application to hang.
    and it crashes! Any suggestions?

    This issue is addressed in the forum linked by Ravens Fan.
    Donovan

  • How to call LabVIEW from TestDirector

    Hai to all,
    I want to call LabVIEW function from TestDirector. That TestDirector using VBScript. is it posible? if posible can you give the procedure.
    thanks for advance!
    reddy

    Hello,
    in this case you have to contact Mercury for more informations. There are no experiences in this way from the LV side.
    Regards
    Thomas D.
    NI Germany
    (SRQ 204139)

Maybe you are looking for

  • OWB 10.2 Multilanguage Support  (MLS) - no way?

    Hi Experts, it seems Oracle forgot to implement the MLS Support for Dimensions. 1. Languagespecific Descriptions for Dimension, Attributes, Hierarchies, ...: You can specify this in OWB (Properties on a Dimension, Tab Translations), but this has no e

  • Network Shared Variable Description

    Hi, I've created alot of Network Shared Variables through Project Explorer...and i have also added a description for each one in the shared variable properties screen Could someone please tell me how i can get access to the description through LabVIE

  • Need help with adjustment brush in LR3.6, Windows 7

    I have a couple questions regarding adjustment brushes in LR 3.6 which I either can't find the answer for or the answer isn't working for me. 1.  I recently found out there should be Iris Enhance, Skin Soften, etc. brushes in the presets.  I can't fi

  • Switchover take too long

    Dear gurus, I'd like to do switchover on my dataguard. but at first step in primary, when i typed 'SQL> alter database commit to switchover to physical standby with session shutdown;' the process stuck for about 2 hours and hasn't finished yet till n

  • Desktop exports older version of EXCEL

    Hi All discoverer desktop is exporting the output in older version of Excel. same report when opened and exported in plus it is exporting in current MS Excel version. any clues why its happening so ?? is this a settings issue? is this desktop version