From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
08-28-2008 08:48 AM
Can labVIEW detect/ generate an event as soon as the data is available at ethernet port? My idea is to use then a event structure to perform desired action.....
Is this possible? Can any one guide how to proceed on this? Sample code can be of great help!
Thanks in advance!
08-28-2008 09:04 AM
Hi there
try the functions in
Instrument I/O -> VISA -> VISA Advanced -> Event Handling
Don't know if that works for TCP/IP, but it's worth a try
08-28-2008 09:20 AM
You're probably thinking of the VISA Enable Event and VISA Wait on Event. Unfortunately, those won't work since they're designed for use with GPIB, serial, and VXI.
To poster: One simple solution is to have a loop that simply calls TCP Read and if there's data you simply generate a user event for your event structure. I would suggest looking up user events. There's an example that ships with LabVIEW.
Other than that you could delve into the API appropriate for whatever operating system you're using and hook into it to have it call a LabVIEW VI as a callback. I would try the previous suggestion first, though.
08-28-2008 11:50 PM
smercurio_fc,
I think you want me to poll the ethernet port using TCP read and then generate user event, but I don't want to do this polling thing. Since data that may arrive at port at irregular intervals and less frequent (30 sec, 1 min. 5min.). So polling port at let's say at 1 sec. shall unnecessary west my processor time. So I want to write program using direct events from ethernet port.
Any suggession on this??
Thanks!
08-29-2008 04:49 AM
Hi there
VISA also works with TCP (see attachment), but the VISA events don't ......
TCP Read uses a TimeOut parameter, so "polling" dosn't mean to waste huge amounts of resources. The TCP Read function returns only when a time out or data arrived. You can catch the time out case and fire the user event after data arrived.
08-29-2008 05:00 AM
Hi Chris,
I think you forgot to attach the attachment!
08-29-2008 05:28 AM - edited 08-29-2008 05:29 AM
Yes, you're right. Use the
Examples -> Networking -> TCP & UDP -> Data Server.vi
to write to Port 6340 on localhost.
08-29-2008 10:03 AM
ITA wrote:smercurio_fc,
I think you want me to poll the ethernet port using TCP read and then generate user event, but I don't want to do this polling thing. Since data that may arrive at port at irregular intervals and less frequent (30 sec, 1 min. 5min.). So polling port at let's say at 1 sec. shall unnecessary west my processor time. So I want to write program using direct events from ethernet port.
Have you actually tried this? You'll find that it's not "wasting" a whole lot of resources. If you create a VI that's just a loop with a 1 second delay and a TCP Read you'll find that it barely registers on the CPU graph, if at all.
chrisger wrote:
TCP Read uses a TimeOut parameter, so "polling" dosn't mean to waste huge amounts of resources.
See my response.
That said, if you do not like the polling mechanism, then as I said, you need to look into using whatever API is available for your operating system and hook into the callbacks, if any, that are available for the TCP/IP stack.
08-29-2008 11:01 AM - edited 08-29-2008 11:02 AM
Polling is not necessary.
Wire a -1 into the timeout for the tcp read and it will block. Then fire your event when you get data. To terminate the TCP Read loop simply close its connection and the TCP Read will error out.
09-01-2008 08:40 AM
Thanks to all of you.
Nathank, I have observed:
If I wire -1 to time out of tcp read, then it waits for NUMBER OF BYTES TO READ (512/ 1024 etc.) specified to tcp read function. (Have tried with keeping no. of bytes to read terminal unwired, changing the modes of tcp read like CRLF, STANDARD, BUFFERED etc......)
In my application I am not sure, how much bytes of data shall appear at what frequency to tcp port......
Any suggessions??