Hi,

I took my ReadSerial() and dumped the code directly inot the
frmOpenEvent on the Monitoring Frm.  The code is below, along with the
OpenSerial() code.

I added         EvtGetEvent(&event, 0) to my code to get a penDown
event.  The penDown event only works when I REM out the SerReceive
functions..  Obviously, there is something else going on here.

My overall goal here is to read from a serial transmitter (whichs
sends the data via radio}, get the data, save the data and plot in
realtime.  A custom receiver was made to receive the data.

The data being sent out is a StartCharacter, the Data(3 characters)
and then a checksum(sum of the Data(3 characters)).  What I want to do
is look for the ASCII Char 165 as the StartChar and then read, save
and plot the next 3 Data Characters. Then when the StartChar is read
again, save and plot the next 3 Data Characters and so on.  Sounds
straight forward.

What happens right now is that when I go into Monitoring mode to
receive the data, the palm device basically seams to  lock until I
turn off the transmitter.   It is obviously receiving data and no
errors are occuring (unless I turn of the transmitter).

Your help would be greatly appreciated.
Thanks,
Darrin

char            szBuf[1024];
static int              index = 0;
int             i, iA, iX;
Err             error;
ULong           ulBytes, ulPendingBytes, ulStartTime, ulEndTime;
CharPtr                 sA, cStatus, sBytes, sBuffer, sBufferGreater; 
CharPtr                 sX, ;           
ULong           ulStartTick, ulLastTick, ulReceive;
EventType       event;
long            timeout;
SWord           prevX, prevY;
Boolean         penDown, Done;
                                
ulLastTick = TimGetTicks();
ulStartTick = ulLastTick;
                
OpenSerial();
                
iA = 0;
                
fBreak = false; 

if (Connected == 0) return;  // Connected set to 1 in OpenSerial() 
                                          //   if successful
        timeout = SysTicksPerSecond() / 2;
        
error = SerReceiveWait(gSerialRefNum, sizeof(gSerialBuffer), timeout);
                
if (error == serErrTimeOut)
{
        FrmAlert(InterbyteTimeoutAlert);
        SerReceiveFlush(gSerialRefNum,100);
}
if (error == serErrLineErr) 
{
        FrmAlert(RS232LineErrorAlert);
        SerReceiveFlush(gSerialRefNum,100);
}
  
ulStartTime = TimGetTicks();
          
do
 {
        SerReceiveCheck(gSerialRefNum, &ulPendingBytes);

        if(ulPendingBytes)
        {
                 //Draw buffer count to screen to confirm that there

                           //is something in the buffer
                sBuffer = "Buffer";
                StrIToA(sBytes, (int)ulBytes);
                 WinDrawChars(sBuffer, StrLen(sBuffer), 25, 20);
                 WinDrawChars(sBytes, StrLen(sBytes), 55, 20);
                 Done = true;
        }

        ulEndTime = TimGetTicks();

}while ((Done == false) && ((ulEndTime-ulStartTime) <= timeout));

ulStartTime = TimGetTicks();

do
{
        EvtGetEvent(&event, 0);  // Get current event

            if (event.eType == penDownEvent)
           {
                EvtGetPen( &prevX, &prevY, &penDown);  
                          //Get pen position
                if (prevY<130)
                {
                        DrawFlags(); 
                }
                else
                {
                        fBreak = true;
                }
        }
                                
             if (fBreak) break;

             ulBytes = SerReceive(gSerialRefNum,&gSerialBuffer, 
            1,0,&error);
                        
        if (error == serErrLineErr) 
             {
                        FrmAlert(RS232LineErrorAlert);
                SerReceiveFlush(gSerialRefNum,100);
        }
                
        if(ulBytes)
        {
                //Draw the character to the screen
                sX = gSerialBuffer;
                WinDrawChars(sX, StrLen(sX), 25, 50);
             }
        else
                {
                        ulEndTime = TimGetTicks();
        }

}while((ulEndTime - ulStartTime) <= timeout);

CloseSerial();
PortOpen = false;
//        FrmGotoForm(DisplayForm);
handled = true;
}
  return(handled);
}               


void OpenSerial(void)
{
        Err error;
        SerSettingsType sstSetup;
  
        error = SysLibFind("Serial Library", &gSerialRefNum);
        ErrNonFatalDisplayIf(error != 0, "Can't find serial library");
   
        error = SerOpen(gSerialRefNum, 0, glBaudRate);
        if (error != 0) 
        {
              if (error == serErrAlreadyOpen) 
              {
                FrmAlert(SerialInUseAlert);
                     SerClose(gSerialRefNum);
              } 
              else
              {
                FrmAlert(CanNotOpenSerialAlert);
              }
             }
   
        Connected = 1;

        error = SerSetReceiveBuffer(gSerialRefNum, gSerialBuffer,
sizeof(gSerialBuffer));
        
        SerGetSettings(gSerialRefNum, &sstSetup);
   
        sstSetup.baudRate = 4800;

        sstSetup.flags =    serSettingsFlagBitsPerChar8 | 
                        serSettingsFlagStopBitsM |
                       serSettingsFlagStopBits1;
   sstSetup.ctsTimeout = 0;

   // Ask Serial Manager to update the port settings
   
   error = SerSetSettings( gSerialRefNum, &sstSetup ); 

   if ( error )  SerClose( gSerialRefNum ); 

        SerReceiveFlush(gSerialRefNum, 100);
}       

On Wed, 8 Nov 2000 13:47:00 -0500, "Dave Lippincott" <[EMAIL PROTECTED]>
wrote:

>
>Is your ReadSerial routine allowing OS messages to be processed?
>
>----- Original Message -----
>From: "Deveau, Darrin" <[EMAIL PROTECTED]>
>To: "Palm Developer Forum" <[email protected]>
>Sent: Wednesday, November 08, 2000 8:50 AM
>Subject: Serial question
>
>
>> Hi,
>>
>> I am working on an application which receives data through the serial
>port.
>>
>> I want to be able to stop transmission by tapping the screen.
>>
>> The following is a code snippet from the form which I load to begin
>> receiveing the serial data.
>>
>> switch (event->eType)
>> {
>> case frmOpenEvent:
>>
>>     OpenSerial();
>>     Read Serial();
>>     etc...
>>
>> Case ctLSelectEvent
>>
>> etc.....
>>
>> I added the following to the Read Serial
>>
>> if(event->eType == penDownEvent)
>> {
>>    if (event->screenY<80)
>>    {
>>      DrawFlags();
>>    }
>>    else
>>    {
>>      break;
>>    }
>> }
>>
>> The break or DrawFlags() will not happen unless I actually turn off the
>> transmitter to terminate communication upon which I receive an error as
>> expected.
>>
>> Any Suggestions.
>>
>> Thanks,
>> Darrin
>>
>>
>> --
>> For information on using the Palm Developer Forums, or to unsubscribe,
>please see http://www.palmos.com/dev/tech/support/forums/
>>
>>
>
>
>




-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/

Reply via email to