Hello all,

I have written a program which listens to the serial port and records
certain parts of the data that it receives.  I have been testing this by
sending text files over the serial port via HyperTerminal.  I suspect there
is a problem with how I am flushing the buffer upon opening.  The situation
is that if I open a serial connection and then start streaming data
everything works perfectly.  However if I start streaming data before
opening a serial connection, the code blocks at the SerReceiveFlush call and
only continues once there is a break in the data flow.  Has anyone seen this
or know about a fix?  I will include my OpenSerialPort() method to make this
question more clear.  Thanks very much in advance.

/***********************************************************************/
void OpenSerialPort(void)
    {
    Err                         error = 0;
    FormPtr                     frmP;
    Word                        ObjectIndex;
    int alertButtonPressed;

    error = SysLibFind("Serial Library", &gSerialReference);

    if (error)
          {
          FrmAlert(OpenPortAlert);
          }

    error = SerOpen(gSerialReference, PORT, BAUD);

    // SER_BUFFER_MAX is a constant set to 2500 //
    SerSetReceiveBuffer (gSerialReference, gSerialBuff, SER_BUFFER_MAX);

    switch (error)
        {
          case serErrAlreadyOpen:
            SerClose(gSerialReference);
            alertButtonPressed = FrmAlert(PortBusyAlert);

            if(alertButtonPressed == 0)
                SysReset();
            if(alertButtonPressed == 1)
                FrmAlert(PortUnavailableAlert);
            break;

          case noErrors:
            gSerialPortOpen = true;
            frmP = FrmGetActiveForm();
            //show connection icon
            ObjectIndex = FrmGetObjectIndex(frmP, PortOpenBitmap);
            FrmShowObject(frmP, ObjectIndex);
            AddLineToMessageBox("serial port opened");
            break;

          default:
            FrmAlert(OpenPortAlert);
            break;
        }


    SerReceiveFlush(gSerialReference, 20);              //**POSSIBLE BLOCK**//

    // next line here for debug purposes -- will show me when it flushes
//
    FrmCustomAlert(UserDefinedAlert,"buffer flushed",NULL,NULL);
    }
/***********************************************************************/



------------------------
Chris Chayka
Software Engineer
ElanTech, Inc.
[EMAIL PROTECTED]


-- 
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