menghuihantang Posted June 18, 2008 Report Share Posted June 18, 2008 I am trying to finish a VI which can listen to a TCP/IP connection and also be able to respond to user action at the same time. I put them in one while loop and keep checking each instance, like anything from TCP/IP and does user do anything on the front panel. But the result is the VI is not working at all. When it goes to listen TCP/IP, it stops and waits for data. I wonder if there is an event-driven listening for TCP/IP so that the VI doesn't need to stuck there for incoming data. Or other structure to implement what I want: both monitoring the TCP/IP and responding to user action? Thanks. Quote Link to comment
jdunham Posted June 18, 2008 Report Share Posted June 18, 2008 QUOTE (menghuihantang @ Jun 17 2008, 12:55 PM) I am trying to finish a VI which can listen to a TCP/IP connection and also be able to respond to user action at the same time. I put them in one while loop and keep checking each instance, like anything from TCP/IP and does user do anything on the front panel. But the result is the VI is not working at all. When it goes to listen TCP/IP, it stops and waits for data. I wonder if there is an event-driven listening for TCP/IP so that the VI doesn't need to stuck there for incoming data. Or other structure to implement what I want: both monitoring the TCP/IP and responding to user action? Thanks. Use parallel while loops. That's what LabVIEW is great at. Keep each loop as simple as possible and minimize the interaction with the other loop. If you need to share data or events, you are going to need to use some kind of communication system outside of the dataflow, like local or global variables, queues, notifiers, functional globals, datasockets. Your best bet is probably to have one loop for TCP/IP listening, one for user event listening, and then a third loop where all the action takes place, fed by your own events generated in the other loops and then passed into the main execution loop. Queues are the favorite way to do this. Do a search on "producer-consumer architecture" on this site and at zone.ni.com. Quote Link to comment
Rolf Kalbermatter Posted June 19, 2008 Report Share Posted June 19, 2008 QUOTE (menghuihantang @ Jun 17 2008, 03:55 PM) I am trying to finish a VI which can listen to a TCP/IP connection and also be able to respond to user action at the same time. I put them in one while loop and keep checking each instance, like anything from TCP/IP and does user do anything on the front panel. But the result is the VI is not working at all. When it goes to listen TCP/IP, it stops and waits for data. I wonder if there is an event-driven listening for TCP/IP so that the VI doesn't need to stuck there for incoming data. Or other structure to implement what I want: both monitoring the TCP/IP and responding to user action? Thanks. Jason's solution is the best of course. Another more quick and dirty solution is to use the timeout input to the Listen VI. Set it to a value that is not to slow for user interaction (250ms is usually quite small enough). Of course the listen node then wil return if there has a connection arrived AND also if the timeout has expired and in the second case accordingly return a timeout error which you have to filter and ignore and go back to listening again. But as mentioned, Jason's solution is the more robust one and definitly has my preference by far. Rolf Kalbermatter Quote Link to comment
menghuihantang Posted June 21, 2008 Author Report Share Posted June 21, 2008 QUOTE (rolfk @ Jun 18 2008, 03:56 AM) Jason's solution is the best of course. Another more quick and dirty solution is to use the timeout input to the Listen VI. Set it to a value that is not to slow for user interaction (250ms is usually quite small enough). Of course the listen node then wil return if there has a connection arrived AND also if the timeout has expired and in the second case accordingly return a timeout error which you have to filter and ignore and go back to listening again.But as mentioned, Jason's solution is the more robust one and definitly has my preference by far. Rolf Kalbermatter Thanks, guys. Jason's solution led me to dig in another big topic. I found out that LabVIEW actually has all structure templates ready for use (yeah, I just found out today). Cool. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.