I have the great problem reading serial data. It seems that "sender" is
too fast for my application. What I have is a test app with two text
fields for receiving and sending data via serial port trigged by
buttons. I have tested it in configurations:
1) Palm III (OS3.5) in cradle -> PC serial port -> Hyper terminal
2) Palm III in cradle -> PC serial port -> POSE 3.0a7 (with serial mapped
to COM port with cradle connected)

Faulty behaviour is similar in both cases.

When sending (text string) data from Palm device to Hyper terminal, it
works well. All the data is received.
But, when trying to receive data from Hyper terminal my app catches first
character only (seems to be very "quick"). When receiving from POSE, I can
catch say say 20, 50, 70 chars out of 100, sometimes even all, but it's
very unreliable! Seems that sender is too quick for my receiver.
I've used various techniques, even SerCom.c official Palm's example, but
no success...

Code excerpt responsible for receiving is below, so if anyone could
help...

Rgds,

-DR


code:


// globals:
// gSerialRefNum - lib refnum storage
// gSerialBuffer - allocated array

static Err ReadFromSerial(void)
{
 Err            error;
 ULong          numBytesPending,numBytes;
 Int            i;
 CharPtr        p;

 error=SerOpen(gSerialRefNum,0,9600);
 if (error!=0)
 {
  //bla, bla...
  return(1);                    //error!!
 }

 //first wait (at least 10 seconds) for the other side to start sending
 //(wait for 1st character)
 error = SerReceiveWait(gSerialRefNum,1,SysTicksPerSecond()*10);

 for ( i=0; i < MaxResponseWaitIterations; i++ )
 {
  error = SerReceiveWait(gSerialRefNum,sizeof(gSerialBuffer)-1,SysTicksPerSecond()*3);
  if (error == 0 || error == serErrTimeOut )
  {
   break;
  }
  else
   SerClearErr(gSerialRefNum);
 }

 //receive data:
 error=SerReceiveCheck(gSerialRefNum,&numBytesPending);
 if (error==serErrLineErr)
 {
  SerReceiveFlush(gSerialRefNum,1);
  FrmCustomAlert(CustomWarningAlert,"Failed to read!",NULL,NULL);
 }
 else
 {
  if (numBytesPending>0)
  {
   numBytes=SerReceive(gSerialRefNum,gSerialBuffer,numBytesPending,0,&error);
   if (error==serErrLineErr)
   {
    SerReceiveFlush(gSerialRefNum,1);
   }

   gSerialBuffer[numBytes]='\0';
  }
 }

 SerSetReceiveBuffer(gSerialRefNum,NULL,0);
 SerClose(gSerialRefNum);

 //...further manipulation with received data in gSerialBuffer

 return(0);
}


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to