Import dll callback function

Having trouble with this line "void   (*m_callback)(_t_pciCommand *cmd);" in PciApi.h file. I have replaced it with NULL and was able to import 2 functions, PciAllocCommand and PciSendCommand. I was then able to get valid information using GetValueByPointer.VI, but crash most of the time.
typedef struct _t_pciCommand
                t_pciCommandType                      m_command;
                t_commandError                          m_error;
                long                                               m_gpVal;
                void                                                (*m_callback)(_t_pciCommand *cmd);
                long                                              m_param[MAX_PCI_PARAMS];
                int                                               m_state;
                int                                               m_retries;
                int                                               m_expected;           
                long                                            m_origParam[MAX_PCI_PARAMS];
} t_pciCommand;
All files attached. Based on this callback funtion, I can't seem to resolve 2 functions, called PciAllocCommand and PciSendCommand.
Thanks,
John
Solved!
Go to Solution.
Attachments:
PciApiDll7.zip ‏630 KB

The manual is "pci_api_manual_jb.doc", The funtion I care most about is PciAllocCommand and the #1 issue I have is how to pass "m_param[0]" , "m_param[1]" and "m_param[2]" to the dll. The original h file is "PciApp(original).h" . The second issue would be if removing the callback functionality I need a VI to poll the status of "t_PciCommand "Function without writing to it.
For example, PciAllocCommand(c_baudrate, NULL, 0). How do I set baud = m_param[0]?
Also I am adding a TestApp.exe example of what I want to do in Labview, focusing on the Param1 and Param2
Attachments:
PciApiDll7.zip ‏630 KB
TestApp.zip ‏67 KB

Similar Messages

  • MIDI in using DLL callback function

    I am trying to get MIDI into LV. The dll used is winmm.dll and the function midiinopen (plus others) is described here:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_midiinopen.asp
    The main problem is I don't know how to program the Call Library Function Node properly in order to perform the call
    plus set it to start receiving callback data, being midi messages. I have tried creating and registering a User Event and
    passing the Event ref to the dll's "dwCallback" and then trapping the callback in an Event Structure, but nothing happens.
    I have studied the "Communicating with a Windows MIDI Device in LabVIEW" example but it gives no hint since midi out
    does not require the use of callbacks.
    Please advice,
    Stefan

    Vedeja wrote:
    I am trying to get MIDI into LV. The dll used is winmm.dll and the function midiinopen (plus others) is described here:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_midiinopen.asp
    The main problem is I don't know how to program the Call Library Function Node properly in order to perform the call
    plus set it to start receiving callback data, being midi messages. I have tried creating and registering a User Event and
    passing the Event ref to the dll's "dwCallback" and then trapping the callback in an Event Structure, but nothing happens.
    Damn! Need to make this post shorter as this message
    board just silently told me that it needs to be shorter than 5000 words
    and ate up my lengthy repsonse with no way to get it back.
    You can't configure a Call Library Node to pass a Callback function to
    another function. Callback functions have been alien to LabVIEW for a
    long time with good reasons and what it has now as callback function in
    LabVIEw 7.1 and newer is not directly compatible with C callback
    functions.
    Basically as you want to get data from the callback function back into
    LabVIEW there is really no way around some intermediate software layer
    which in this case almost surely means your own specific wrapper DLL
    written in C.
    If you use LabVIEW 7.1 you could use user events but not in the way you
    describe. Attached is an example of how you can use user events from
    external code. Note the extra DLL you will have to write. You have to
    watch out what data you pass back to the user event as it has to match
    exactly the type you configured the user event for, otherwise LabVIEW
    will simply crash on you.
    For numerics this is quite simply and also shown in the example. For
    strings you can't just pass back a C string pointer but you will have
    to allocate a LabVIEW string handle with
    handle = DSNewHandle(sizeof(int32) + <length of C string>)
    and then copy the C string into it. For specifics about how to do this
    you should refer to the External Code reference manual in your Online
    Bookshelf. Similar rules apply for arrays or clusters for that matter.
    If you want or need to do this for LabVIEW < 7.1 there are two
    possible approaches but both are even less trivial. You could either
    create a wrapper DLL that translates your callback events into LabVIEW
    occurrences and for the data transfer back to LabVIEW you would have to
    implement your own queing too, or you could use the Windows Message
    Queue example somewhere here in the NI examples and adapt it to return
    your specific data. That would solve the data queueing more or less for
    you without having to worry about that.
    Rolf Kalbermatter
    Message Edited by rolfk on 05-22-2006 11:22 AM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions
    Attachments:
    userevent.zip ‏27 KB

  • External Function with a Pointer to a Callback Function Inside a DLL

    Hi.
    I'm loading a DLL and trying to call a function with the following prototype:
    Func1(HANDLE, hHandle, LPVOID (*pCallback)(UINT, UINT LPVOID), CHAR* sPath)
    Now, I have no problem with the variable types, because CVI 9.0.1 recognizes all of them and I have no problem with LoadLibrary() nor with GetProcAddress().
    But, how do I pass a pointer to a callback that is inside the DLL I'm trying to use.
    I've tried to declare the callback like this:
    LPVOID (CALLBACK Callback)(UINT iDevNo, UINT evEvent, LPVOID pData);
    and call the function Func1 like this:
    (Func1)(hHandle, &Callback, NULL);
    but this gets me:
     Undefined symbol '_Callback@12' referenced in "source.c".
    Hope I can get some help.
    I appreciate your time on this issue.
    Regards.
    Daniel Coelho
    VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
    Controlar - Electronica Industrial e Sistemas, Lda
    Solved!
    Go to Solution.

    Hi Daniel,
    First, you have to make sure that the callback function is exported by the DLL, so that the program that uses the DLL can access the function name identifier. Then, you have to make sure that you call GetProcAddress not just on Func1, but also on the exported callback function. You need to store both function address values in their respective function pointers. You then can pass the callback function pointer as an argument to the Func1 call.
    It's probably cleaner if you define typedefs for all your function pointers, in the calling program:
    typedef LPVOID (__stdcall *CallbackType) (UINT , UINT, LPVOID);
    typedef ??? (__stdcall *Func1Type) (HANDLE, hHandle, CallbackType, CHAR*);
    CallbackType     CallbackPtr;
    Func1Type        Func1Ptr;
    dllHandle = LoadLibrary ("...");
    CallbackPtr = (CallbackType)GetProcAddress (dllHandle, "Callback");
    Func1Ptr = (Func1Type)GetProcAddress (dllHandle, "Func1");
    Func1Ptr (..., hHandle, CallbackPtr, NULL);
    Boa Sorte!
    Luis

  • Register a Callback function in LabVIEW

    Is there any way to register a callback function in LabVIEW. For example:
    I have a DLL on Win2k that run a thread. This thread is doing a certain task (it is not important what it does...) I can't predict when this task will end and I need to know when the task is over. The easy way would be to poll this DLL and ask: "Is it over? Is it over?" over and over again. No! I don't want to poll. Not because it's too easy. I want this DLL to wake me up on time.
    Any idea, solutions, function that I'm not aware of, new features...
    Thanks
    Nitrof

    I think I have a much better solution for you. Here is an example program that show how to set a LabVIEW occurence in a dll. Therefore when your dll is done it can set the LabVIEW occurence, meanwhile your VI is just waiting on the occurence.
    More infomration on this is in the external code in LabVIEW manual Using External Code in LabVIEW
    NOTE:This will ONLY work in LabVIEW 7.
    Attachments:
    SetOccurDll.zip ‏165 KB

  • TCP Callback function passing data to teststand

    Hi,
    I'm trying to pass data via a TCP Callback function to teststand using the TCP steptype that I downloaded from Ni.
    When I open a connection, container data is passed to the dll on which it creates a connection, the dll in part creates a TCP Callback function.
    The handle obtained from the connection is then passed back through the container data, and the dll returns back to the sequence editor which will execute the next steps.
    The problem is that when the TCP Callback function gets an TCP_READY event it can not pass data to TestStand because it can not access the container data.
    How can this TCP Callback function pass/alter data to/in Testand?
    Thank you...

    Yes ThiCop,
    That's exactly what I want to establish!
    Here is the example code:
    //Function needed by the TCP functions
    int CVICALLBACK MsgHandler (unsigned handle, int event, int error, void *callbackData)
        char receiveBuf[256] = {0};
        char displayBuf[7] = {0};
        char * tempLookup;
        int  dataSize = sizeof (receiveBuf) - 1;
       switch (event)
          case TCP_CONNECT:
             break;
          case TCP_DISCONNECT:
             break;
          case TCP_DATAREADY:
             if ((dataSize = ClientTCPRead (handle, receiveBuf, dataSize, 1000)) > 0)
                   //  Send data from receiveBuf to a variable in teststand ????
                   //  TS_PropertyGetValString (HandleObject, NULL, "Step.Result.Data", 0, &tempLookup);
                   //  TS_PropertySetValString (HandleObject, NULL, tempLookup, 0, receiveBuf);
             else
                   receiveBuf[dataSize] = '\0';
            break;  
     return 0;
    void __declspec(dllexport) TX_TEST TCPConnectF(tTestData * testData, tTestError * testError)
        int                 error = 0;
        int                 TCPerror;
        double           Port;
        double           Timeout;
        char              *HandleLookup;
        char              *ServerAdd;
        char              *CallbackData;
        ErrMsg           errMsg = {'\0'};
        ERRORINFO   errorInfo;
        tsErrChk (TS_PropertyGetValString (testData->seqContextCVI, &errorInfo, "Step.Result.Handle", 0, &HandleLookup));
        tsErrChk (TS_PropertyGetValNumber (testData->seqContextCVI, &errorInfo, "Step.Result.Port", 0, &Port));
        tsErrChk (TS_PropertyGetValString (testData->seqContextCVI, &errorInfo, "Step.Result.IP", 0, &ServerAdd));
        tsErrChk (TS_PropertyGetValNumber (testData->seqContextCVI, &errorInfo, "Step.Result.Timeout", 0, &Timeout));
        tsErrChk (TS_PropertyGetValString (testData->seqContextCVI, &errorInfo, "Step.Result.Data", 0, &CallbackData));
        TCPerror = ConnectToTCPServer (((unsigned int *) &ConnectionHandle), ((unsigned int) Port), ServerAdd, MsgHandler, 0, Timeout);
        if (TCPerror != 0)
         //Get TCP Error Message
           sprintf(errMsg,"%s",GetTCPErrorString ( TCPerror ));
           error = TCPerror;
           goto Error;
        tsErrChk (TS_PropertySetValNumber (testData->seqContextCVI, &errorInfo, HandleLookup, 0, ((double) ConnectionHandle)));
    Error: 
        // FREE RESOURCES
        CA_FreeMemory(HandleLookup);
        CA_FreeMemory(ServerAdd);
        // If an error occurred, set the error flag to cause a run-time error in TestStand.
        if (error < 0)
            testError->errorFlag = TRUE;
            testError->errorCode = error;
            testData->replaceStringFuncPtr(&testError->errorMessage, errMsg);
        return;   

  • JNI Multithreading/Callback Function Design Issues

    Ok, I have been working on this for quite some time now and I simply can not figure it out. So any ideas are more than welcome. :)
    I have Java code that uses a DLL that I created in C++. My C++ code links with a library made by a 3rd party (don't have access to the source or anything). The 3rd party's code creates a new thread and calls a callback function that I define in my C++ code. This callback is called continuously until I perform some other code to stop it. Now for the tricky part. In my callback function I need to pass some data back in Java. Here is where my design falls apart. Since the callback function is technically part of the 3rd party's thread, I have to call AttachCurrentThread() in the callback to get the JNIEnv pointer in order to ultimately call my desired Java method. The problem is that my Java method (or even the C++ callback function) are only invoked if I do a sleep() in my C++ code after I start the 3rd party code which creates the thread. If I do a Thread.sleep() in Java after I call the native function code, it just sleeps and the callbacks never get called. It appears as though the thread dies as soon as I return from my C++ code.
    So now I am stuck. I have tried creating a thread in Java which simply calls the C++ code and the C++ code just loops waiting for an updated flag, however, this causes the 3rd party's thread creation code to fail (not quite sure why). However, even if their code worked, I'm not convinced this is even proper design. I apologize if this is simply a threading design principle as my multithreading programming techniques are a bit rusty and I've never done a multithreaded application this complex (this is a simplified version, but the idea is the same).
    I welcome any suggestions or even documentation that may lead me in the right direction. Thanks in advance.

    I have a similar issue.
    from java I call a dll I wrote, which calls a third party scanner dll (cyber.dll). Everything works ok, except, when an event in the scanner occurs, it calls the call backin my dll, which calls the callback in java, which kills the vm with an access violation. If I execute the call back to java from a c method which I just called from java, it works, but if it gets called outside of the java execution of the native code, it fails.
    I havent done anything with treads or syncronisation. Do I need to do this AttachCurrentThread stuff? If so, where do I get the _jvm handle as Im not starting the vm from c?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to implement a callback function using LabView's Call Library Function Node?

    I am trying to call a fuction from a SDK.dll library using the Call Library Function Node. The SDK was provided to
    me and I do not have the source code, just the .dll and .h files.
    The SdkSetPropertyEventHandler function has a callback fuction as one of its parameters. How do I implement the
    callback using the CLF node? I am a good LabView programmer but this is my first time using the Call Library
    Function Node. I have read all the info I can find on NI's web site and the discussion board but cannot figure
    this one out. I am using LabView 8.6.
    The SDK.h deacribes the function as:
    //  Function:   SdkSetPropertyEventHandler
    SdkError SDKAPI SdkSetPropertyEventHandler(
                SdkCameraRef                    inCameraRef,
                SdkPropertyEvent                inEvnet,          
                SdkPropertyEventHandler         inPropertyEventHandler,
                SdkVoid*                        inContext );
    //  Description:
    //       Registers a callback function for receiving status
    //          change notification events for property states on a camera.
    //  Parameters:
    //       In:    inCameraRef - Designate the camera object.
    //              inEvent - Designate one or all events to be supplemented.
    //              inPropertyEventHandler - Designate the pointer to the callback
    //                      function for receiving property-related camera events.
    //              inContext - Designate application information to be passed by
    //                      means of the callback function. Any data needed for
    //                      your application can be passed.
    //      Out:    None
    //  Returns:    Any of the sdk errors.
    A separate header file called SDKTypes.h contains the following data:
    typedef  SdkUInt32  SdkPropertyEvent;
    typedef  SdkUInt32  SdkPropertyID;
    typedef  void       SdkVoid;
    typedef  struct __SdkObject*    SdkBaseRef;
    typedef  SdkBaseRef    SdkCameraRef;
     SdkPropertyEventHandler
    typedef SdkError ( SDKCALLBACK *SdkPropertyEventHandler )(
                        SdkPropertyEvent        inEvent,
                        SdkPropertyID           inPropertyID,
                        SdkUInt32               inParam,
                        SdkVoid *               inContext );
    Thanks for your help.
    Alejandro
    Solved!
    Go to Solution.

    alejandroandreatta wrote:
    I am trying to call a fuction from a SDK.dll library using the Call Library Function Node. The SDK was provided to
    me and I do not have the source code, just the .dll and .h files.
    The SdkSetPropertyEventHandler function has a callback fuction as one of its parameters. How do I implement the
    callback using the CLF node? I am a good LabView programmer but this is my first time using the Call Library
    Function Node. I have read all the info I can find on NI's web site and the discussion board but cannot figure
    this one out. I am using LabView 8.6.
    Basically you do not do that. LabVIEW does not know pointers and certainly not function pointers. What you should do instead is writing a C DLL that implements the callback and also exports a function to be called by LabVIEW that translates between the callback and a LabVIEW user event. Look for PostLVUserEvent() here on the NI site to find examples how to do that.
    Rolf Kalbermatter
    Message Edited by rolfk on 02-11-2009 08:00 PM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • ProcessSystemEvents & callback functions

    Hello.
    I have a question about the ProcessSystemEvents() and callback functions. If I have the following "strange" callback function with the follwoing code inside:
    int func(...) {
      while(true) {
       ProcessSystemEvents();
    Could this code create a crash in the underlying run-time lib (cvirte.dll etc), with to many calls to ProcessSystemEvents?
    And will this code stop any other callback function from execution, since we are in an infinite while loop?
    Best regards,
    Christian G.

    A fuction like that should be called only once, if this is what you intend. While sitting in the loop, ProcessSystemEvents permits the system to react to events like the user pressing a button or something like this. You must explicitly avoid dangerous events like calling the function again and again, as well as all user actions that can cause problems (like modifying critical parameters while the function is running, improperly exiting the program and so on). To obtain this you may either disable unwanted buttons on the GUI or set a global flag 'system running' tested on all callbacks and functions to protect the system from unwanted operations.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Callback Functions for the Enterprise API

    I'm using VB to write some API functions to pull journal detail from Enterprise 6.0, but having trouble with the callbacks. I did find some syntax errors in the toolkit.bas file, correct those and am able to pull specific data points, but the enum functions just crash. Because the documentation is scetchy at best, I'm not sure if my functions are wrong, if there are other syntax errors in the .bas file or if the dll's are corrupt.<BR><BR>I'd really appreciate some help from someone who has experience writing callback functions to the Enterprise API.<BR><BR>Thanks in advance.

    Hey there...
    I think part (if not all) of your question can be answered by abstracting it a level. Think of all the tools that are available through PL/SQL or JAVA in the database. For instance...
    * Heterogeneous Services that allow you to access any ODBC/JDBC data source directly from within the Oracle database.
    * DBMS_JOB that allows the scheduling of jobs to run at a given time/interval.
    * DMBS_FILE_UTL that allows Oracle to interact with the file system.
    That doesn't even take into account the things you can do with Java in the database.
    In short, just about everything you mentioned can be done in one shape or form with tools that reside in or around the oracle database.
    HTMLDB is a front end interface tool that has access to all of the tools available to you at database level.
    So in short (and in my opinion): Yes, it is capable of creating Enterprise level applications. I'm building a fairly complex one right now that interfaces with 2 external (non-oracle) databases via Heterogeneous services, and which used DBMS_JOB to schedule jobs to collate data from an external file system.
    I hope this helps..
    Doug Gault
    TXI

  • ActiveX controller methods import as callbacks

    I used the Create ActiveX Controller feature to create a FP.  The ActiveX is part of Mach3, a CNC control program.  The ActiveX has methods like Code(LPCTSTR) that allows you to send G-Code strings to the CNC machine (G-Code is a text-based motor control language).
    The weird thing is that most of the methods in the ActiveX control were imported as events with callbacks.  For example, the only reference to the Code function in the FP is under Event Callback Registration Functions->IMyScriptObject->IMySriptObjectRegOnCode.  The prototype for the callback includes a char * which I assume maps to the LPCTSTR parameter.
    I don't understand why the methods are imported as callbacks.  I've been working with Mach3 tech support, but they don't know anything about CVI. Here's what they told me about their server:
    There are two interfaces that you can get into... One is called Mach4 the other is MyScriptObject, The My script object is all the methods that are used in the VB scripting in Mach3... when I wrap the class in VS I can select what set of objects I would like to get... I am not sure how you do it without VS..
    All the methods under Mach4 are imported as standard function calls.  Why would the "My script object" methods be imported as callbacks?  Is there some way to fix this in CVI, or is the problem in the ActiveX server itself?

    After installing the software i was able to generate a controller, and for the "Code" function i generated a callback called Mach4_IMyScriptObjectRetOnCode. Have you been able to call this ActiveX server in another language such as C#? If so can you provide a very simple example of how to do this?
    CVI generates functions from the wizard automatically based on their types and something in the Mach4 library is either being treated as an event callback or is not being recognized properly. 
    Richard S -- National Instruments --Applications Engineer -- Data Acquisition with TestStand

  • How to call this dll point function by labview

    Void SetCompStatusCallBack(void ((*CompStatusCallBack)(int id, int status, unsigned char conflict)))
    Sets up callback function for getting component status.
    Parameters:
    * CompStatusCallback – entry point for callback function.
    Return Value:
             None.

    left wrote:
    Void SetCompStatusCallBack(void ((*CompStatusCallBack)(int id, int status, unsigned char conflict)))
    Sets up callback function for getting component status.
    Parameters:
    * CompStatusCallback – entry point for callback function.
    Return Value:
             None.
    You don't. This is the callback protoype that would be passed as parameter to another API and as such never will be called by the caller of that API but instead be provided by that caller!
    And LabVIEW does not support function pointers at all, so you really can't do this.
    The only solution is to write a wrapper function in your DLL or in a separate DLL that translates between this interface and some more event oriented LabVIEW functionality such as user events, but unless you do know C to a fairly good level, you should probably leave that to someone else.
    Rolf Kalbermatter
    Message Edited by rolfk on 01-26-2007 04:21 PM
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Programmat​ic access to Import DLL Wizard

    Our company does a number of products, and would like to cut down time when working with the SDK. I am almost pleased with the import wizard in 2012, but I would like a few things changed. I have all the code ready to modify the output from the import DLL wizard with the scripting module, but if I could have it automatically generate and run the whole thing (possibly through a command line post-build instruction in Visual Studio), that would save some hassle.
    It's not a big deal. I just wanted to speed up the process a little, since our SDK format doesn't change. We had a custom VI generator for our SDKs before, but it gets 95% of the way there, and the wizard does everything we missed and gets about 95% of the way there as well. That, or I could try to convince my coworkers to accept the output from the wizard.
    Solved!
    Go to Solution.

    Since the SDK was already released it is probably not an option anymore, but you can certainly increase the chances for the import library wizard to do a good job by choosing standard API parameters. Basically this means to only use skalars (passed by value or reference), C strings and simple arrays. Never use structs that contain arrays (both fixed size or not). Structs only containing skalars are fine though, but don't create structosaurusses, the C equivalent of clustersaurusses in LabVIEW, big unwieldy structs/clusters.
    Then you have to review all the VIs that use output array or string buffers to let the called function write into, to make sure they are preallocated to a reasonable size for the used function.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Can't import DLL

    Hi All,
    I'm trying to use the libsie API to open .sie files from SoMat (there is a plugin for this data format for LabVIEW and DIAdem but it doens't work). I've previously imported dll's using the import wizard with a lot of sucess but I dont' know my way around c or c++ so am a bit stumped on this one. When I try to import the attached dll (you'll need to chage the extension from .doc to .dll) using the attached header file none of the calls show up. They are there in the header file. I'm wondering why this is. Is it a badly formattted header file or is there some other issue?
    I've attached a copy of the zip file that I downloaded from the HBM website. There is a demo .sie file in there if you want to look at one. There appears to be pretty comprehensive documentation on the API on the website.
    Any help or pointers gratefully received.
    Phil
    Solved!
    Go to Solution.
    Attachments:
    sie.h ‏27 KB
    libsie-1-0-0-bundle.zip ‏5817 KB
    libsie.doc ‏160 KB

    It doesn't matter what language was used to create the DLL, so long as it exports a C-compatible interface (which it does).
    If you make a copy of the header file and remove SIE_DECLARE(), leaving whatever is inside the parentheses unchanged, from each function declaration, I suspect you'll be able to import at least some of the functions. I don't know how well the import utility will handle the pointer data types, you might have to edit each Call Library Function Node to fix them manually after importing.

  • How to write c wrapper it containing callback functions

    hi here shambhu below call can be containing some call back functions ,how can create wrapper for this,please suggest me
    _export int GDSRegisterStation(char *sPort, char* sPanel, int iStation, GDSCallback lpGDSTaskCall); /*
    This call hooks up user application onto the GDS environment. From this point on, the GDS application has continuous, concurrent access to the virtual machine representing the test system. As multiple independent test systems may be hooked onto the same host computer, the call needs to specify a "Port" (unsigned uPort) to which GDS memory access is sought. Character string sPanel (up to 63 chars) identifies the calling GDS task to the Virtual Machine. This entry will assist the System Manager in monitoring active GDS tasks by their assigned names. As multiple test stations (each with one or more control channels) may be associated with the same controller, (int) iStation specifies the station to which this application will be connected. (GDSCallback) lpGDSTaskCal specifies the subroutine in the user application that is to be installed as the real-time callback into the Virtual Machine. From this moment on, the specified subroutine will be automatically called by the Virtual Machine to periodically All subsequent calls to the GDS library will apply to this Station and its control channels. This call is made only once and prior to other GDS calls. 0 is returned upon normal completion -1 is returned if the call was a failure due to absence of GDS space associated with the call. Make sure station is connected and On-Line and make sure Port No was correct in the call -2 is returned if the application was already registered by a previous call

    You will have to write a wrapper DLL in C which converts the callback event into a LabVIEW compatible event. The most versatile way would be to generate a user event with the PostLVUserEvent() LabVIEW manager function. Callback functions are however an advanced C programming construct, so you should definitely have a pretty decent understanding of C programming before starting this endeavour. Otherwise you end up with a not working solution or maybe even worse, one that seems to work sometimes but doesn't really do the right thing.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Call Java Method from Callback function

    I am writing a JNI wrapper in c++ for a particular event driven DLL. The DLL makes a network connection to another device and then calls a callback function when events are raised on the device. The DLL has 3 basic functions: connect, disconnect, and registerEventListener. RegisterEventListener takes a function pointer which is called each time an event is raised on the device.
    My wrapper DLL exposes connect and disconnect functions via JNI. I can call these functions just fine from my Java code. Now the question... How do I call a Java method from my c++ callback function? I can call a Java method using env->CallXXXMethod(...) from within a function that is accessible to Java but I don't have access to the JNI parameters in my Callback function.
    So how do I call a Java method from a callback function? If this cannot be done then what is the "right way" to handle native event notification with JNI?

    jschell wrote:
    JNI parameters? Meaning what exactly?
    General outline of a callback
    1. Entry
    2. Get the VM, env - there are methods for this
    3. Attach the thread
    4. Get a java object - how depends on what you are doing, but create it or a static reference.
    5. Get the java method
    6. Call the java method.That is exactly correct. The callback function is called from a separate thread so using a cached pointer to JNIEnv, obtained from the original native method, crashes the JVM. The jmethodID and jclass objects (which are needed to call the static Java method) can be cached without problem. The following is the code I used to attach the current thread and call my static method.
    void MyClass::onEvent(int system_id, char* data)
         //get a pointer to the Java Environment
         JNIEnv *env;
         jvm->AttachCurrentThread((void **)&env, NULL);
         //Call the Java method with the newly aquired data
         jstring js = env->NewStringUTF(data);
         env->CallStaticVoidMethod(cls, mid, system_id, js);
    }My last question is about cleanup in this function. When I use NewStringUTF to "convert" my char* to jstring do I need to do anything special to clean up or will the Java garbage collector take care of it since the jstring is being passed to a Java method?
    Thanks for you help

Maybe you are looking for

  • Firefox is already running, but not responding to open a new window

    I closed the only opened Firefox process that was running. Then clicked the Fox to start Firefox again. I received a message: Firefox is already running, but not responding, to open a new window. You must close the existing Firefox process, or restar

  • I'd like to use this mail sometime

    Hi. I've never been able to use Macmail or learn any of its features. I set up this whole thing including the password and it's never been accepted. Is there a simple and easy way of doing this? I've read all posts and finally had to make one of my o

  • [T61p] ThinkVantage System Update has encountered a problem and needs to close....

    Start System Updater and almost immediately  (at 3% progress) get: ThinkVantage System Update has encountered a problem and needs to close.... and it just won't run. All I can do is hit close.  I've removed it from the system, rebooted, cleaned the r

  • Cross Docking_Error _ Urgent !!

    I am configuring a basic Cross Docking Scenario in Lean WM. I have not activated HU Mgmt. Warehouse is 301 Section 0001 I have set up a Cross-Docking Storage Type - XCD. Have Enabled 2-Step CD in IMG (Cross-Dock Warehouse Level Customization) Have ma

  • Change background color of alternating rows in listview

    Hi all, Does anyone know how to change the background color of alternating rows in a listview in Visual Basic 2013? Best regards, Randy Boulter