10-21-2008 03:52 PM
Hi,
I'm trying to figure out a way to monitor a serial port for activity while still being able to use the rest of my program. A simplified example would be to have a boolean button control a case structure that outputs a string to an indicator. I want to be able to watch the serial port for an incoming string while still being able to push the boolean button and have that string appear in the indicator.
Thanks
10-21-2008 04:10 PM
One way to do it is to use the VISA Bytes at Port function to poll to see if there is any activity on the serial port. If the Bytes at Port > 0 then you've got something on your port and you can read it. If not, then you can monitor your button. You can do this numerous ways (have the Boolean press captured by an event structure while the timeout case monitors the Bytes at Port, monitor the Bytes at Port in a parallel loop and send a notifier to your main loop when you see something, etc).
Hope this helps!
jason
10-21-2008 04:22 PM
10-21-2008 04:26 PM - last edited on 04-19-2024 01:36 PM by Content Cleaner
I like using VISA events.
You can set up a loop that just monitors events from the serial port and reports back to your main loop.
Dan
10-21-2008 04:44 PM
I didn't set up my main program in a loop. I've tried playing around with a visa wait on event in a while loop, maybe it was the way I set up the while loop the wait on event was in, but it just sat in the loop and never left it, so I was not able to use the rest of my program. That's what I did for my simple visaevents test. I figured if I could push the button and make the string appear while it's watching the serial port, then my real program would work. It didn't work for me
http://myfreefilehosting.com/f/dfcc6914bb_1.83MB
10-21-2008 07:04 PM
At minimum, you would need to have a parallel thread in your program. It typically takes form of parallel loops.
A more sophisticated coding approach would be to have a Dynamic VI (daemon) whose purpose would be to carry out serial communication.
Data could be sent to/from the main program using Action Engines.
R