LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx dynamic event registration with LV2 globals

In an effort to write my code efficiently, I've devloped a set of LV2 globals to do most of the "main" work as my code executes various loops.  Among these tasks is responding to DAQmx events that are registered using the "Register for Events" node.  I have a couple of questions related to doing this:

1.  Can I dynamically register and unregister particular DAQmx events?  There is a dynamic event registration example using mouse events that shows how you can change specific events by leaving the other event registrations unwired.  Additionally, it shows you can dynamically unregister and reregister specific events by wiring a null reference or a new reference to a specific event.  I'd like to know if this functionality is supported for DAQmx events.

2.  Can all this dynamic event registration\unregistration\reregistration be handled inside a LV2 global where the event registration refnum was previouslly stored in a shift register?  Or do "Register for Events" nodes need to be in the same VI as the event structure that will handle them?

3.  Due to the way I handle inputs\outputs to my LV2 globals, I was wondering if these event registration refnums survive conversion to and from the varient type.

I ask these questions becuase I'm running into some problems in my code involving the handling of DAQmx event registration in my LV2 globals.  Specifically, I have an LV2 global that produces an error in the error list described as "Code could not be generated correctly for this VI" with no other explanation and no specific location for the error.  Even more strangely, I have another LV2 global that is constructed very similarly and produces no error.  I've attached a library file "DAQ Interface.llb" for LV8.0.1.  Observe the difference between "Digital Event.vi" and "Analog Capture.vi"  I really don't know what's going on.
0 Kudos
Message 1 of 6
(3,912 Views)
Hi Yuri,
 
DAQmx events should work the same way as user events, making them able to be dynamically registered.  The unregister functionality is also supported in DAQmx. To unregister events, call the DAQmxRegisterSignalEvent function and pass a NULL value for the event callback function pointer. However, you cannot register or unregister an event in NI-DAQmx while a task is running.
 
One thing to note is that each Event Structure must have its own Event Registration Refnum (ERR). Although this requirement is not strictly enforced by the editor, you may experience strange behavior and hangs if you try to handle the same Event Registration with multiple Event Structures. Next, create an ERR for each Event Structure and wire the same User Event Refnum (UER) into both Register Events nodes. Now, when you fire the user event, it will be enqueued into both Event Queues and can be handled by each Event Structure seperately.  The ERR should be able to convert back and forth from variant data type as well.
 
There is also some additional information regarding DAQmx Events in the NI-DAQmx Help file.  If you search in the index, the topics can be found under events » software, in NI-DAQmx
Also, this forum post refer to some other information about using DAQmx events.  Feel free to peruse our other forums or KB's for more information on DAQmx events.
 
As far as the error message you are seeing ( I was also able to duplicate this error 😞  First you should try removing or upgrading your version of NI-DAQmx Base.  If that does not work, delete the two files _daqmxbase.rc, _daqmxbase.rch
 
I hope this can help point you in the right direction. 
 
Regards,
 
Nicholas B
National Instruments
0 Kudos
Message 2 of 6
(3,852 Views)
Thank you for your suggestions.  In the top level VI, only one event structure is used, and the two DAQmx events are handled by this one event structure, so I think everything is okay there.  I looked under system information and support in MAX, and found no DAQmxbase installed, and a search of all files in my computer reveals no _daqmxbase.* files, yet I still get this error.  Also, for DAQmx events, when you refer to wiring a NULL function pointer for dynamically unregister a DAQmx event, I assume you mean wiring a generic ("empty string") DAQmx Event or Task Name constant (i.e., right clicking on the Signal or EveryNSamplesAcq input and selecting "create constant").  When I do this, however, I get an error telling me that the wired task is not valid.  Is this because a valid task must be wired initially, and only later can you dynamically unregister a DAQmx event?
0 Kudos
Message 3 of 6
(3,849 Views)

Hi Yuri,

Yes, the event needs to be registered with a valid DAQmx task name before you can unregister it.  I found specific documentation on that error that stated NI-DAQmx Base was the culprit, but you may have found another case.  Are you running the most recent version of NI-DAQmx?  If not, I would recommend downloading and running it from here.

Regards,

Nicholas B, National Instruments

0 Kudos
Message 4 of 6
(3,829 Views)
I have applied all of the suggestions you gave me, and they have been very useful, but I am still getting an error.  Here is what I am doing:

1.  Create and configure a task (digital input\Change Detection Event).
2.  Register that task to a Register for events structure (DAQmx\Signal).  This Event Registration Reference (ERR) is wired to an event structure that handles the events.
3.  I also wire a branch of the ERR in step 2 to another event structure (not registering it, just making the ERR available to sub vi's in the second structure).  This event structure is a user event handler.
4.  Whenever the user presses a "go" button, in the user event loop, I unregister the DAQmx event (using the branch of the original ERR) by wiring an empty Task constant to the "signal" input of a Register for Events structure made from the ERR.  Then I immediately wire the valid DAQmx task reference to another Register for Events structure using the ERR, and then start the task.  The behavior I going for is that now the first event structure (in a loop) will react to digital change detection events.  All this is done in a sub-vi with appropriate inputs\outputs.
5.  When the user hits stop, I stop the task, and then do the first part of step 4 (unregister the event by wiring an empty DAQmx task to a Register for events structure with the ERR).  This is also done in a sub-vi.

When I do this, I always get an error telling me that I need to wire a valid DAQmx Task to the Register for event structure when trying to unregister the event.  I have also noticed that if the event is already registered, re-registering it (even with the same DAQmx task) causes an error as well--I'm told to unregister the event first.

It is difficult to post code, because there program is much more complicated.  But if it is needed, I can strip it down to the essential parts of concerning this error.

Thanks.


P.S.  All software\drivers are the most current versions.

Message Edited by Yuri33 on 05-10-2007 07:00 PM

0 Kudos
Message 5 of 6
(3,713 Views)

Hi Yuri,

I believe that at this point, we will need the code to attempt to duplicate the issue.  If you could please send a very trimmed down version of the code that only contains elements needed to reproduce the problem, that would help a great deal.  If you could also supply specific instructions on how to replicate the issue with the code, it will help us determine if this is a bug or a configuration issue. 

Thank you very much!

Regards,

Nicholas B

0 Kudos
Message 6 of 6
(3,693 Views)