LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Wait on Event User Event

Solved!
Go to solution

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?

0 Kudos
Message 1 of 13
(5,343 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 13
(5,337 Views)

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.

 

 

0 Kudos
Message 3 of 13
(5,305 Views)

I don't think you want to close down your port inside of this VI.  That might be stopping your event from getting through.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 13
(5,302 Views)

@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.

 



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 13
(5,299 Views)

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.

0 Kudos
Message 6 of 13
(5,272 Views)

Can you post both sides. It is very difficult to diagnose a problem with code.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 7 of 13
(5,265 Views)
0 Kudos
Message 8 of 13
(5,213 Views)

Here is the code

0 Kudos
Message 9 of 13
(5,212 Views)
Solution
Accepted by topic author Paul_Knight_Lockheed_Mart

@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.

 



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 10 of 13
(5,204 Views)