LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Register DQmx event from within event strucutre

I have an application in which I start and stop continuous data acquisition which I have implemented using the producer/consumer (data) template. It works, but there are some things it won't do, such as relabel graphs on the fly (Program freezes when the same event appears in two event structures). I thought that it would be nicer to use the standard producer/consumer (events) structure, but to do that I need to be able to register the "EveryNSampleIntoAcquireBuffer" event within the event loop. I based my approach on two help articles "Event Structure (Labview 2013 Help)" and "Creating Custom Events (lABVIEW 2013 hELP)". I create a custom event and a dummy event for the "EveryN" event (define events.png). I can successfully call the custom event (shown in event.png) and it executes without error and "should" register the "everyN" event, which has now been populated with the correct task (I checked that it had the correct task name). Unfortunately, the event handler for the "EveryN" event never fires. Since the code is essentially the same as the working version (data driven events), I believe that despite the lack of error, I'm not dynamically registering the event properly. Suggestions? Does anyone have an example of dynamically registering an event like this?

 

As an aside, when I first tried to post this I had forgotten to list the board. I corrected that, but it didn't show the attachments, so I added them again. Now it is complaining that there are more than 3 attachments, even though I don't see any listed if they aren't there when this finally gets posted, I will add them as a reply.

0 Kudos
Message 1 of 7
(2,951 Views)

Here are the attachments for the question

Download All
0 Kudos
Message 2 of 7
(2,949 Views)

You can register for events, from within your event structure.  As for posting, zip all your files and just attach a single file, it's easier for uploading, and easier for downloading.

0 Kudos
Message 3 of 7
(2,948 Views)

The question is how, since what I did, didn't work despite the lack of error/warning messages. I have zipped the whole thing  (Run Experiment B, except "Get Terminal name with Device.vi") and added it (including the working data event version, Run experiment.vi)

0 Kudos
Message 4 of 7
(2,934 Views)

Okay so attatched is updated code that I think does what you want.  I don't have hardware to test it.  But it uses a single register for events instead of using two.  I think this helps because you perform the same register each time, you just need to keep track of the User Event you are registering for.  I also changed it to unregister for the previous events, before registering for the new ones.

 

I also deleted about 30 local variables that aren't needed.  This makes code much easier to follow.  Use the terminals when you can.  Many times you were using locals when you didn't need to.  You'd also read a local, then read the same local in the same case.  Do you expect the value to change in that time?  If not then use the same value.  The wire is the variable.

 

I also don't like the icon view for terminals, and prefer labels on the left and right of the terminals.  I also like consistency with label style.  Some are bolded some aren't.  For this reason I rarly bold labels, but if I do I do my best to bold them all.  I also added a handle on the UI being closed, and made the UI look more Windowsy.

0 Kudos
Message 5 of 7
(2,919 Views)

Thanks for the help. Unfortunately, it doesn't work (again with no errors generated). The code executes the generate event vi in Start_Acq with no errors but never fires the user event handler (probe on the error_in wire for that case isn't executed).

 

The hardware required is pretty simple - any multi-function DAQ with at least 4 inputs (3 independent inputs and the output monitor) and an output (I'm actually using a chassis rather than a single board multi-function DAQ). For testing purposes i have the output wired into all four inputs.

 

Your style comments were interesting and your diagrams were still clean.

0 Kudos
Message 6 of 7
(2,911 Views)

In attempt to simplify this I have created a bare bones program (that doesn't work).  Clicking on the play button should cause the light to flash. The version where the event is registered entirely outside the event structure works just fine.

0 Kudos
Message 7 of 7
(2,899 Views)