Asynchronously writing and callback function

hi everybody,
i am working on an asynchronous write operation as described in
'Asynchronously Reading and Writing with the NI-DAQmx Visual C++ Class Library'
in the Visual Studio .NET documentation.
I've worked with asynchronous read functions and callbacks (the OnEvent function in this example) before, and it worked
well.
Atm i am doing output to 16 digital outputs on my PCI6259 card. I want to output a waveform stored in a vector containing about 1000 samples.
So i installed the event handler for my writer object, and started the output by calling
'WriteMultiSamplePortAsync'.
The problem is, that the callback function 'OnEvent' is called after the first sample of my vector is sent, and not after the complete vector.
i need to know when my whole buffer is through, because i have to recalculate it and send it again...
Anyone has an idea where the problem is?
Thx in advance
markus

Well i've attached a somehow simplified code of my problem.
First i start two tasks, one counter, which acts as sample clock for my digital output, and the digital output task itself.
In this example i use a output frequency of 100kHz.
Then an event handler for my digital write operation is installed.
Next, i create a vector with size 1000, fill it with some data and write it out calling 'WriteMultiSamplePortAsync'
What i would expect now, is that the OnEvent-function is called, as soon as all of the 1000 samples of my output vector have been sent.
But what really happens is that OnEvent is called after the first of the 1000 samples has been written.
As i said before, the same procedure works fine with analog input tasks.
Regards
Markus
Attachments:
AsyncDigitalOut.cpp ‏3 KB

Similar Messages

  • 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?

  • NI DAQ and Arduino in Matlab (control obj in a callback function triggered by another obj)

    (I am aware that this may not be the most appropriate place to ask, but I'm pretty desperate...)
    I am writing a script to acquire online data from a DAQ card and to control an Arduino microcontroller based on the output of the DAQ card data.
    The acquiring of the DAQ card data works fine, but I'm having problems with (1) the online processing of these data and (2) the corresponding controlling of the Arduino microcontroller. I'll try to explain both problems as clear as possible, the matlab code that has already been written can be found at the bottom of this question.
    I'm using a 64-bit Matlab, so I can only use the Session-Based Interface.
    1) Online processing
    Data are collected at a rate of 1000 samples/s. Each time 250 new samples are available, a callback function is triggered to process these data (using a listener triggered by the 'DataAvailable' event). This processing consists of spectral analysis, using the 'spectrogram' function. The problem is that the spectrogram function should use a window of 500 samples and an overlap of 250 samples. So, new samples should be available for processing every 250 samples, but not only the new 250 samples but also the previous 250 samples are needed to accomplish the overlap. Basically, I need 500 samples for each callback function run, but this function has to be ran every 250 samples.
    2) Controlling the Arduino
    The biggest problem lies in the controlling of the Arduino. After spectral analysis, the calculated value is compared to a predefined treshold and if this value exceeds the treshold, the output of the Arduino should be put to one, else the output should be put to zero. The problem here is that, since the callback function is an external function, it doesn't recognize the Arduino object. The Arduino has been connected to Matlab at the start of the script, but is only available in the 'base' workspace. Connecting the Arduino on each function run isn't a possibility, since this should be done every 250 ms.
    Attempted solutions
    I have tried to make the function into a nested function, so that it can use the same variables as the ones in the script, but Matlab doesn't allow this. When I write a nested function, I get the following error: "A nested function cannot be defined inside a control statement (if, while, for, switch or try/catch)." However, I have never defined one of these statements, so the function isn't inside a control statement. I don't understand why this doesn't work.
    Matlab code
    Script
    %% Preparing Arduino
    % Connecting the arduino chip to Matlab
    a=arduino('COM4');
    % Defining the 13th pin as an output
    a.pinMode(13,'output')
    %% Preparing the DAQ card
    % Searching the DAQ card
    devices = daq.getDevices;
    % Create a session
    s = daq.createSession('ni');
    % Define the input channel
    s.addAnalogInputChannel('Dev1', 0, 'Voltage');
    % Define the total measuring and stimulation time
    s.DurationInSeconds = 4;
    % Define the interval for processing
    s.NotifyWhenDataAvailableExceeds = 500;
    % Loading the optimal stimulation parameters
    load('parameters.mat')
    setappdata(s,'freq',parameters(1))
    setappdata(s,'treshold',parameters(2))
    % Define a listener triggered by the DataAvailable event
    lh = s.addlistener('DataAvailable',@stimulation); 
    % Save the start time
    starttime=clock;
    % Start the measurements
    LFP=s.startForeground;
    Callback function
    function stimulation(src,event)
          freq=getappdata(src,'freq');
          treshold=getappdata(src,'treshold');
          LFP=event.Data;
          [S,F,T,P]=spectrogram(LFP,500,250,[],1000);
          PSD=log(P(freq));
          if PSD>=treshold
             a.digitalWrite(13,1)
          else
             a.digitalWrite(13,0)
          end
    end
    All comments/suggestions are welcome.
    Many thanks in advance!

    Hello hemm,
    As you noted this is most likely not the appropriate place to past these non-NI Development environment related questions.
    Especially since the issue does not seem to be related to the interface with the NI DAQ card.
    Maybe you could add some Message Tags so that people that are following specific tags might be able to  detect your question and help you.
    Would it be an option for you to use NI LabVIEW?
    If this is the case then it might be interesting to note that many of the Arduino users over here are using the NI LabVIEW Interface for Arduino Toolkit:
    http://sine.ni.com/nips/cds/view/p/lang/en/nid/212​478
    This is however being supported from the following page:
    https://decibel.ni.com/content/groups/labview-inte​rface-for-arduino
    Kind Regards,
    Thierry C - Applications Engineering Specialist Northern European Region - National Instruments
    CLD, CTA
    If someone helped you, let them know. Mark as solved and/or give a kudo.

  • Testing asynchronous callback functions

    I have been creating a test suite for an API that my company has been developing and have run into a bit of a snag trying to create tests for a couple of our async callback functions. I have tested a number of our async events properly using the addEventListener and addAsync combination and they have worked brilliantly, but these last couple are slightly different.
    The issue I am running into now is that these problematic async callbacks are not firing an event but just returning a url and so the function signature doesn't match what is expected by the addEventListener/addAsync combination I had been using so far for testing. Is there a different approach required to test an asynchronous method that is not firing an event??
    Thanks in advance for your help.

    Geoff,
    Sorry this has gone unanswered. There are several new async methods that will be making an appearance in the upcoming beta 2. I think these will solve your issue.
    Mike

  • Declaring functions in other functions and callbacks

    Hi - I'm curious to know if the following situation is
    possible (I haven't gotten it to work yet).
    I'd like to load a series of images, and in the callback,
    place them in different positions in my array. Instead of writing a
    separate callback for each image, I'd like to do something like the
    following:
    But it looks like each version of the function gets the end
    version of "i", not the version of i that existed when the function
    was declared.
    Is something like this at all possible?

    Right. The whole point of the question is if is possible to
    dynamically declare functions for use as callbacks.
    For example, in the standard loading functions, you register
    a callback like this:
    var load:Loader = new Loader();
    var req:URLRequest = new URLRequest(swf);
    load.contentLoaderInfo.addEventListener(Event.COMPLETE,
    swfloadcallback);
    load.load(req);
    function swfloadcallback(e:Event):void
    The problem with the standard callback function is that I
    can't add additional arguments to it. For example, I couldn't have
    swfloadcallback take in an additional argument (for example the
    index of the swf I'm trying to load). What I'm wondering is if in
    actionscript 3 it's possible to dynamically declare callbacks such
    that I only have to write the code once, but in essence I am adding
    additional parameters to the callback.
    Hence the example I listed above. What I was trying to
    accomplish there was basically dynamically creating callbacks that
    understood which index to insert the loaded image into. But clearly
    that example doesn't work.

  • Application Builder, Callback function and ActiveX

    I have a software application which calls a callback function. This
    callback function talks to an Activex component. When I try to build
    an application.exe, the exe always hangs. Anyone know how to get
    around this? In the Labview developement envirorment it works just
    fine.
    -Chuck

    What is the ActiveX control that you're calling?
    Where in the execution of the code does the program hang?
    Can you post any of your code?
    What version of LV are you using? What version of Windows?
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • I am trying to write a double buffered data acquisition program using MFC and a callback function.

    i am trying to do a double buffer data acquisition using MFC application framework in Visual Studio.i want to use a callback function to notify when the buffer is half full.do you have some sample reference program that can help me?

    What DAQ board are you using? When you installed NI-DAQ you should have selected to install the support files for VC++. Then there will be several examples on how to do double buffered data acquisition.
    If you have already installed NI-DAQ 6.8 or higher and did not select to include the support files, you can run the NI-DAQ setup program and just add them. If you are using an older version, you will have to uninstall and reinstall.
    Once you have the support files, follow this path to the examples.
    >>Program Files>>National Instruments>>NI-DAQ>>Examaples>>Visual C>>
    If you are doing digital acquistion, goto the di folder, if you are doing analog acquisition goto the ai folder.
    As for the callback function, you can use the NI-DAQ function Config_DAQ_
    Event_Message with DAQEvent Type = 1, where N would equal half your buffer.
    Brian

  • C++: Is it possible using callback function with ncacn_http and rpcproxy server ?

    I have a remote procedure and I can call it using http over rpc. I pass trough an rpc proxy server for arriving to my rpc server.
    But I cannot call a callback function to my client inside the server function.
    Is it possible using callback function with ncacn_http and rpcproxy server ?
    We are using IIS on windows server 2008 R2 and the server rpc and the client on the same PC with rpc rpoxy.
    If I use ncan_ip_tcp all works fine.
    Thanks
    Gianluca

    Hi,
    About the develop question please post to the MSDN forum.
    MSDN forum Developer Network
    http://social.msdn.microsoft.com/Forums/en-US/home?forum=WAVirtualMachinesVirtualNetwork&filter=alltypes&sort=lastpostdesc
    Thanks for your understanding and support.
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • 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

  • 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

  • Event Handlers and Callbacks:  Best way to handle?

    I'm writing an actionscript class. I'm wondering how to deal
    with call backs and event handlers within my class. In particular,
    I'm wondering how I might structure my class so that developers
    using it can choose which arguments get passed to the callback
    function as they code. I've been googling and haven't found any
    particularly useful information on this.
    As far as I can tell, it would appear that the parameters
    passed to any callback function are determined at the time I write
    my class as this anonymous function example illustrates.
    var myObj:Object = new MyClass('foo', 'bar');
    myObj.onLoad = function(arg) {
    // the args passed to this anonymous function are dictated
    by the actionscript defnining MyClass
    I have also seen an approach using named functions and a
    class method for setting the event handler which allows a developer
    to pass some object to be used for scoping the named function but
    this also results in the parameters for the callback being
    predetermined by the actionscript that defines the class
    function myLoad(arg) {
    // the args passed to this function are also dictated by the
    actionscript defining MyClass
    var myObj:Object = new MyClass('foo', 'bar');
    myObj.setOnLoadHandler(this, 'myLoad');
    As far as I can tell, neither approach would let a developer
    specify any parameters for the callback functions (onLoad() in the
    first example, myLoad() in the second example). Which of these
    approaches is considered 'best practice'? Also, what would I do if
    I wanted to specify that the callback should operate on a
    particular movieclip on my timeline? How can I pass that
    movieclip's parameter to the callback function?

    You can download the Library from this link. Inside is an example that shows how to handle windows messages/events.
    http://zone.ni.com/devzone/cda/epd/p/id/4394

  • 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

  • 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

  • How to create a callback function module

    Hi all,
    I am working in a requirement where we need to call a function module at a 'after change' event. So how to create a callback function module and register it with the crmvevent ?_
    I created a sample function module and try to create entries in table crmv_event_cust, but i got an error message saying that the function module name I provided is not in table CRMC_FUNC_ASSIGN. When I try to create entry there, I got a message that function module is not in CRMC_OBJ_FUNC and that table is a standard table with no maintanance options !!
    looks like i am going in wrong way ... can any one please help ??

    Looking at my system all you need to do is create the entry for the callback function in maint view: CRMV_FUNC_ASSIGN.
    Your entry should be as simple as Z-function name Object Function - <same as others in the segment you are assigning>
    IE for the partner it would be CRM_PARTNER as object function, for general order processing CRM_ORDER
    Take care,
    Stephen

  • Help with writing and retrieving data from a table field with type "LCHR"

    Hi Experts,
    I need help with writing and reading data from a database table field which has a type of "LCHR". I have given an example of the original code but don't know what to change it to in order to fix it and still read in the original data that's stored in the LCHR field.
    Basically we have two Function modules, one that saves list data to a database table and one that reads in this data. Both Function modules have an identicle table which has an array of fields from type INT4, CHAR, and type P. The INT4 field is the first one.
    Incidentally this worked in the 4.7 non-unicode system but is now dumping in the new ECC6 Unicode system.
    Thanks in advance,
    C
    SAVING THE LIST DATA TO DB
    DATA: L_WA(800).
    LOOP AT T_TAB into L_WA.
    ZDBTAB-DATALEN = STRLEN( L_WA ).
    MOVE: L_WA to ZDBTAB-RAWDATA.
    ZDBTAB-LINENUM = SY-TABIX.
    INSERT ZDBTAB.
    READING THE DATA FROM DB
    DATA: BEGIN OF T_DATA,
                 SEQNR type ZDBTAB-LINENUM,
                 DATA type ZDBTAB-RAWDATA,
               END OF T_TAB.
    Select the data.
    SELECT linenum rawdata from ZDBTAB into table T_DATA
         WHERE repid = w_repname
         AND rundate = w_rundate
         ORDER BY linenum.
    Populate calling Internal Table.
    LOOP AT T-DATA.
    APPEND T_DATA to T_TAB.
    ENDLOOP.

    Hi Anuj,
    The unicode flag is active.
    When I run our report and then to try and save the list data a dump is happening at the following point
    LOOP AT T_TAB into L_WA.
    As I say, T_TAB consists of different fields and field types whereas L_WA is CHAR 800. The dump mentions UC_OBJECTS_NOT_CONVERTIBLE
    When I try to load a saved list the dump is happening at the following point
    APPEND T_DATA-RAWDATA to T_TAB.
    T_DATA-RAWDATA is type LCHR and T_TAB consists of different fields and field types.
    In both examples the dumps mention UC_OBJECTS_NOT_CONVERTIBLE
    Regards
    C

Maybe you are looking for

  • How to know when an object is deleted?

    Hi, In Java, instances of classes are eliminate by garbage collector and programmers have no chance to do it. I need to do something, when the instance of a class ends its cycle-life . How do I know when an object is going to be deleted, in order to

  • Disaster recovery on a new host. Oracle 11.1.0.6

    Oracle 11.1.0.6, windows server 2003 R2 Service Pack 2 x64) I need to test disaster recovery on a new host(with diferent name). It looks like I am able to complete recovery stage but dbcontrol doesn't work for me. I was told: if you change host name

  • Function module to calculate date in future

    Hi, I am looking for a function module in SAP CRM 2007 that calculates and returns date 'n' days in future of the entered date. This is like the DATE_IN_FUTURE function modules present in SAP. Please let me know if any one has come across such FM. Re

  • Multiple Portlets on Same Server?

    What is the best way for 2 separate groups in an organization to have (or appear to have) their own instance of the Oracle Portal? We have 2 separate groups ready to begin development in the Portal and are trying to figure out a good way to accomplis

  • Rejected email

    incoming email is rejected with message: not enough space However, I emptied all boxes and now have only 33 small messages in inbox. I do not understand all the lingo about server admin etc which were in all topics. Can anyone help me? I installed Ti