View unanswered posts | View active topics It is currently Tue May 21, 2013 2:51 am



Reply to topic  [ 3 posts ] 
 Using Wait for Data 
Author Message

Joined: Feb 09, 2009
Posts: 108
Post Using Wait for Data
I know I've asked variations on this question before, but I keep cheating the answer by using the "to count" option with a known number of bytes. Thus far, I've been able to structure everything to always be the same number of bytes received (the current version uses 30 bytes) so I can just always use:

Code: Select all
wait for data from source connectionName to count 30


Now, however, I can no longer use that crutch, as I have data coming which I cannot make other than 12 bytes.

So.

I want to be able to read an arbitrary amount of bytes, stopping after there are no more bytes to read. To that end, I have the following questions:

1. Is a wait statement even needed? Could I replace it with a loop? Something like
Code: Select all
do
read byte from source connectionName to count 1
stick that byte somewhere
loop until no more bytes

How do I tell if there are no more bytes to read?

2. If that doesn't work, then using no "to count" on the wait for data, will read one byte, yes? So I could do that loop above with a Wait and a Read, looping until there is no more data. But same question, how do I tell there is no more data to read?

3. Finally, if there is no way to tell no data is left, can I do:
Code: Select all
wait for 12 bytes
check to see if this fits the 12 byte data style
if yes, goto TwelveByteData
if no, wait for 18 more bytes
do the ThirtyByteData stuff

Will the 18 bytes be "lost" if no one is waiting for them?

Thanks for all the help. I promise I'll have something cool to show from all of this, one day!

Brian


Tue Jun 08, 2010 10:34 pm
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11689
Location: Texas
Post Re: Using Wait for Data
I'd recommend your 2nd approach. The data won't be lost -- it'll be queued up. Untested pseudo code:

Code: Select all
   set twelveByteFormat to false
   set foo to read byte list from source "MyConnName" to count 12 timeout after 1000
   
   if false then -- check foo for 12 byte format here
      -- do something with 12 bytes of data here
      set twelveByteFormat to true
   end if
   
   if not twelveByteFormat then
      set foo to foo & (read byte list from source "MyConnName" to count 18 timeout after 1000)
      -- do something with 18 bytes of data here
   end if

_________________
Image


Wed Jun 09, 2010 8:39 am
Profile WWW

Joined: Feb 09, 2009
Posts: 108
Post Re: Using Wait for Data
Ok, I'll try that. Thanks.

Brian


Wed Jun 09, 2010 12:45 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.