LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I Only read from TCP/IP listener if there is data?

In my data acquisition software that I've written, I have a TCP/IP listener to occasionally receive messages from Matlab.  I only want to do that if there are available bytes to be read.  I've thought of setting the mode on the listener to Immediate, but it says in the help that there will still be a timeout error.  The main things that I'm looking at are avoiding timeout errors, and I don't want waiting for the message to interfere with the data acquisition.

Thanks,
Alan Stemmons
alanstem469@yahoo.com
0 Kudos
Message 1 of 6
(3,555 Views)
Hi as469,
the listener waits only for a connection. To wait for some byte use the "read TCP vi" with timeout "-1".

Hope it helps.
Mike
0 Kudos
Message 2 of 6
(3,551 Views)
Sorry, I wasn't clear.  I only use the listener to open the connection at the very beginning, then use the read block from then on.  The actual problem that I seem to be having is that the DAQ input buffer keeps overrunning while it doesn't when I don't include the tcp/ip stuff at all.  The main reason that the tcp/ip would help is to keep a log file of where the antennas are pointed throughout the data acquisition relative to when acquisition was started.  I could have matlab do the log file, but it would be better to have labview do it.

Thanks
0 Kudos
Message 3 of 6
(3,542 Views)
Sorry, but I'm not totally clear on who's talking to who, and who's doing what here. You said that you're receiving messages from Matlab. What kind of messages? Where is the data acquisition running? On Matlab or LabVIEW? Who's connecting to whom?
0 Kudos
Message 4 of 6
(3,535 Views)
The data acquisition software is running in Labview, while Matlab is running software to control the antenna position.  What I would like to do, is have Matlab send a message when the antenna has arrived at the correct position telling Labview to start acquiring, and then also send a message to Labview telling it when to stop acquiring.  In between this time, while labview is acquiring, Matlab will also send messages to Labview telling where the antenna is pointed.  An example message would be "Az=180, El=45\n".  The purpose for this is to keep a log file of when the antenna moves relative to when data acquisition started.  The problem that I've had when I tried doing this with a TCP/IP read block with a short timeout is that the read buffer overruns.  Basically, I just have a while loop with a Daqmx read block, then the data from that read block is written to a binary file.  In this while loop there is a TCP/IP read block that uses immediate mode with a timeout of 10 ms.  It tries comparing the string that is read to "Stop Acquiring\n".  That is the condition to terminate the the while loop.  I'm not going to worry about the log file until I can actually get it to acquire for the whole time.  It would be nice if there was some way to make this interrupt driven, so it would only pay attention to the tcp/ip read block if there was actually data.  I'm assuming that's where the problem is, although I might be wrong.

Thank you.
0 Kudos
Message 5 of 6
(3,532 Views)
Use two separate parallel loops.
 
Loop 1 is your communication loop.  When it gets a command from TCP/IP, it queues up a command in a queue.
Loop 2 is your DAQ/State machine.  It dequeues the command from the queue with no timeout.  If the dequeue function does not timeout and gets a command, it does whatever the command tells it to, possibly changing the next state of the state machine.  States could be start DAQ, acquire DAQ, stop DAQ, Idle.  If the function does timeout, it executes the current state.  In the IDLE state, you may want to have it change the timeout of the dequeue function to something larger so that it doesn't spin the loop endlessly in the event nothing happens.  Then decrease the timeout of the dequeue to 0 in the start DAQ so that the loop runs as quickly as it needs to to process the DAQ read functions.
 
As you expand to logging, you will want to have a second queue passing the data to be logged to a third loop.
 
I'm sure there are other ways to execute this architecture, this is the first that came to my mind.
0 Kudos
Message 6 of 6
(3,521 Views)