08-23-2015 02:24 AM
My requirement is simple :
1. I have a TCP server running ( Arduino board)
2. The client is Labview code based running on WIN7.
3. If server gets a query "LAST" from the client , it sends one set of aqcuired data that is about 50 bytes long.
4. If server gets a query "FULL" from the client, it sends all availabe set of aqcuired data that is about 50 x 50 bytes long maximum or just 50 bytes at minimum. It all depends when exactly the Client made the request as the Arduino server keeps on storing data sets in a buffer..
Refer attached VI in LV12. It works well for the LAST case where i need to get just one data set. But I have no clue how to make it work for the variable length of data. In essence after sending the FULL request, I must be able to leave my Labview Client open for as long as the server keeps sending data. But how ?
08-23-2015 10:08 AM
I'm assuming that the LAST command works fine, and you are able to successfully "get" the Last set of data correctly. I'm also assuming that otherwise the Server gathers data (in an array, I'm assuming) without sending anything, and the intent is that the FULL command will get the Server to send all the N sets of data in its array, one after another (in the same manner it sent a single element with the LAST command) until all the data are sent.
If the Client has a way of breaking up data from the Server into "chunks" corresponding to the chunks that the Server is accumulating in its "To be sent" Array, you should be able to implement the FULL command by simply putting the Client "Read and Save One Chunk) into a While loop, Use the presence of a Timeout Error (you might want to reduce the TimeOut to something small, like 10 msec) to tell you "There is no more data at this time, so the FULL command is complete" (clear the Error, of course, and wire True to the While Loop's Stop indicator). If there is no Timeout Error, then the data are valid and you can process the Chunk in whatever manner is appropriate.
Bob Schor
08-23-2015 11:14 PM
@Bob_Schor wrote:
I'm assuming that the LAST command works fine, and you are able to successfully "get" the Last set of data correctly. I'm also assuming that otherwise the Server gathers data (in an array, I'm assuming) without sending anything, and the intent is that the FULL command will get the Server to send all the N sets of data in its array, one after another (in the same manner it sent a single element with the LAST command) until all the data are sent.
Bob Schor
A confirmed YES to all of the assumptions above..
The method which you described to collect pending data sets in a while loop is one possible method - but in my case i need a method by which I should be able read either one set of data or many sets of data depening on the query. KIndly note the query happens only once in either case - because my Arduino is coded to check the incoming client request opnly once and if its a FULL request, just goes into a loop pumping out data at timed intervals of about 10ms.
In other words I need a TCD Read which can wait for data till a end condition is met.
08-24-2015 08:50 AM - edited 08-24-2015 08:51 AM
If you look at the options for TCP Read you can set the 'mode' to CRLF which will stop reading as soon as the CRLF characters are received. If your arduino terminates each command/message with a CRLF then you can use this to read in individual commands (or a timeout error occurs).
If you can't do that, you need to either:
1) Read a whole bunch of data and parse out the commands from the string you get using a string buffer (e.g. on a shift register)
2) Read one character at a time until you get the end of a command
3) Prepend your packet with the data length (typically a U32 typecasted to a string), read the 4 bytes, convert to a number and then read that many bytes to get the whole message
08-24-2015 09:52 AM - edited 08-24-2015 09:53 AM
Well it looks like finally I have to sweat it out with this option :
3) Prepend your packet with the data length (typically a U32 typecasted to a string), read the 4 bytes, convert to a number and then read that many bytes to get the whole message
The way I have coded the Arduino for the FULL option, it just needs one string "FULL" from LV Client to start the dispatch process and its inside a WHILE loop where in the terminator is the data set address. When the data set address reaches "00" the process stops. I have tried to sniff the result with a stanadlone TCP CLIENT SERVER APP ( www.nsauditor.com ) and its working perfect.
But the problem with LV Read function is the BYTES input. If it had an option of "Infinite" bytes till a CRLF , my life would be easier !!
Thanks for your time Sam_Sharp.