New topic: 

How can this happen.

<http://forums.realsoftware.com/viewtopic.php?t=30439>

       Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic         Author  
Message       RGV250           Post subject: How can this happen.Posted: Sun 
Oct 11, 2009 8:04 pm                        
Joined: Sun Oct 04, 2009 11:41 am
Posts: 4              Hi,
I have only been using RB for a couple of weeks and seem to be getting 
somewhere, I now have a piece of code that does not work how it should and I 
can not see a reason why.
Code://Create a temp area for serial data
dim TempArea as string
dim n as integer

//Move serial data to Temp area so it is not overwritten
TempArea = ( me.readall)

//Look for ? in the data
IF left(TempArea,1) = "?" then
  
  //Compare the chr following the ?
  if mid(tempArea,2,1) = "1"  then
  //Write to text box
  textfield1.text = "Tag not present"
  end if
  
  //Compare the chr following the ?
  if mid(TempArea,2,1) = "2"  then
  //Write to text box
  textfield1.text = "Tag failure to read / write"
  end if
  
  //Compare the chr following the ?
  if mid(TempArea,2,1) = "3"  then
  //Write to text box
  textfield1.text = "Access to block 0 not allowed"
  end if
  //End of ? selections
  
end if

//Compare the first 2 chr's
if left(TempArea,2) = "OK" then
  //Write to text box
  textfield1.text = "Function performed successfully"
end if


// Split the incoming data to display in separate boxes
n=temparea.Len
if n > 3 and n < 12 then
  textfield2.text = left(TempArea,2)
  textfield3.text = mid(TempArea,3,8)  //  <<<<<<<<<<< This does not always 
display all the characters
end if



//show all the incoming data
textarea1.appendtext(TempArea)  //  <<<<<<<<<<<<< yet this one does so all the 
data must be there

//Clear the temp area for new incoming data
TempArea = ""

Everything works as planned but occasionally the textfield (marked) does not 
always get filled in correctly, it should have 8 chr's in it but may only have 
between 3 to 6, what I find strange is that the line after writes the correct 
data so it is there.

Regards,
Bobby   
                            Top                timhare           Post subject: 
Re: How can this happen.Posted: Sun Oct 11, 2009 8:42 pm                        
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6525
Location: Portland, OR  USA              You're getting the data in separate 
packets.  Your code wouldn't tell you, because it only responds to specific 
characters at the beginning of the string - everything else just falls through 
to the line that appends it to textarea1.  You are not guaranteed to get the 
entire transmission in a single packet - ie., in a single DataAvailable event.  
You need to buffer the data that comes in and respond when you get a complete 
transmit.

Tim   
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to