11-05-2012 11:47 AM
I have a Producer/Consumer program that uses an Event Structure to handle the UI button presses. I want to be able to use the VISA wait on Event to read characters from the RS232 port. So in my Event Structure I created a case for dynamic user events.
I also create a while loop that has the VISA Enable Event and VISA Wait on Event in it. I enabled the "Serial Character" event only. When I get this event I use the Create User Event.VI and Register for Events to get a Event Refnum
How do I get the Event Refnum from this loop into my Producer loop?
Solved! Go to Solution.
11-05-2012 12:34 PM
You have a few options. The simplest would be to initialize your user events outside of both loops and then pass the wire to each loop. Another alternative is to use a Function Global/Action Engine to initialize and store the event refnum. Then use the appropriate action in your code to get the refnum. Another alternative would be to define a LV singleton class and use that throughout the code. Which option is best depends a bit on how complex your code is and how deep you would need to pass the wire. If you are going several levels deep the FG or LVOOP object work better.
11-08-2012 02:01 PM
Mark,
I found the Events FGV Community Example and it does everything I want to do. However, the VISA Wait on Event is doing something different than what I was expecting. When I enter data on the serial port, I can see that the Event and Event Type changes, but I don't get a User Event in my Event Handler.
I have attached the VI.
11-08-2012 02:14 PM
I don't think you want to close down your port inside of this VI. That might be stopping your event from getting through.
11-08-2012 02:26 PM
@crossrulz wrote:
I don't think you want to close down your port inside of this VI. That might be stopping your event from getting through.
I would agree that this is the likely cause of your event not getting through.
11-09-2012 10:49 AM
I had added it because there is a document on NI.com call "Timeout on VISA Wait on Event Even Thought the Event has Occurred" that mentions you should close the event handle with a VISA Close once you have captured your event.
I removed the VISA Close, but I still don't get anything over into my Event Handler. It appears that the Producer Loop that holds the Event Handler is not running. I put an indicator on the Loop Iteration and it is not incrementing, just stays at 0.
The Loop Iteration counter for my VISA Event loop increments and I see events coming in from the serial port.
11-09-2012 10:56 AM
Can you post both sides. It is very difficult to diagnose a problem with code.
11-21-2012 12:39 PM
11-21-2012 12:41 PM
Here is the code
11-21-2012 01:10 PM - edited 11-21-2012 01:14 PM
@Paul_Knight_Lockheed_Mart wrote:
Here is the code
No, that is not the code. That is one subVI and a picture. Where are you waiting for the VISA events? Where are you generating your user event? Based on the picture you are calling the Initialize_Controller_Communication and remaing in that code until the Stop buuton is pressed. You will not start your event structure in the producer loop until this VI completes. So, if you are not hitting the stop button to complete your initializtion it is no wonder you are never seeing your event structure run.