View Single Post
  #9   Spotlight this post!  
Unread 25-01-2008, 11:58
Kingofl337's Avatar
Kingofl337 Kingofl337 is offline
You didn't see anything....
AKA: Adam
FRC #0501 (Power Knights)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 1998
Location: Manchester, NH
Posts: 861
Kingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond reputeKingofl337 has a reputation beyond repute
Send a message via Yahoo to Kingofl337
Re: Does reading from the serial port work?

Here you go this is the basics. If you want it to echo the actual character used use WriteSerialPortOne(unsigned char). Other wise you get the ascii byte code. If you compare byte == "X" for instance it will work.

EDIT: DON'T USE THIS, IT DOESN'T WORK, I WAS A DOLT! SEE BELOW

Code:
void main ( void )
{
      unsigned char byteswaiting; 
      unsigned char byte; 
      unsigned char x; 

      while ( 1 )
      {
            byteswaiting =  GetSerialPort1ByteCount( );
            if ( byteswaiting != 0 )
            {
                  PrintToScreen ( "Output: " ) ;
                  for ( x = 0 ; byteswaiting == x ; x++ )
                  {
                        byte = ReadSerialPortOne( );
                        if ( byte == 13 )
                        {
                              PrintToScreen ( "\n" ) ;
                        }
                        else
                        {
                              PrintToScreen ( "%d" , byte ) ;
                        }
                  }
            }
      }
}
__________________
FIRST Team 501 PowerKnights - Mentor
FIRST Team 40 Checkmate - Mentor Alum
FIRST Team 146 Blue Lightning - Alumni

Last edited by Kingofl337 : 28-01-2008 at 16:09.