rs232.c File Reference

#include "rs232.h"
#include "error_management.h"

Go to the source code of this file.

Functions

int rs232_close ()
int rs232_open (char *_port, int baud_rate, int byte_size, int parity, int stop_bits)
int rs232_read (void *buffer, int size, int *_read_bytes)
int rs232_write (void *buffer, int size, int *_written_bytes)

Variables

static COMMTIMEOUTS g_cto
static DCB g_dcb
static HANDLE handle_com = NULL


Function Documentation

int rs232_close (  ) 

Definition at line 122 of file ADPCM_STREAMING/rs232.c.

Referenced by get_data(), and main().

00123 {
00124   CloseHandle(handle_com);
00125   return 1;
00126 }

int rs232_open ( char *  _port,
int  baud_rate,
int  byte_size,
int  parity,
int  stop_bits 
)

Definition at line 80 of file ADPCM_STREAMING/rs232.c.

Referenced by get_data(), and main().

00081 {
00082     // Make sure another port is not already opened
00083     ASSERT(!handle_com);
00084 
00085     // Open the existing COMX file to open the port
00086   handle_com = CreateFile(
00087                       _port,
00088                       GENERIC_READ | GENERIC_WRITE,
00089                       0,
00090                       NULL,
00091                       OPEN_EXISTING,
00092                       FILE_ATTRIBUTE_SYSTEM,
00093                       NULL);
00094  
00095     // Make sure it is opened
00096     if (handle_com == INVALID_HANDLE_VALUE)
00097        return 0;
00098 
00099     // buffer size for emission and reception
00100   SetupComm(handle_com, RS232_RX_SIZE, RS232_TX_SIZE);
00101 
00102     // COM port configuration
00103   g_dcb.BaudRate = baud_rate;
00104   g_dcb.ByteSize = byte_size;
00105   g_dcb.Parity = parity;
00106   g_dcb.StopBits = stop_bits;
00107   if(!SetCommTimeouts(handle_com, &g_cto) || !SetCommState(handle_com, &g_dcb))
00108     {
00109       CloseHandle(handle_com);
00110       return 0;
00111     }
00112 
00113     // Flush buffers for emission and reception
00114     // DTR = 1
00115   PurgeComm(handle_com, PURGE_TXCLEAR | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_RXABORT);
00116   EscapeCommFunction(handle_com, SETDTR);
00117 
00118   return 1;
00119 }

int rs232_read ( void *  buffer,
int  size,
int *  _read_bytes 
)

Definition at line 129 of file ADPCM_STREAMING/rs232.c.

Referenced by get_data(), and main().

00130 {
00131   return ReadFile(handle_com, buffer, size, (DWORD *) _read_bytes, (LPOVERLAPPED) NULL);
00132 }

int rs232_write ( void *  buffer,
int  size,
int *  _written_bytes 
)

Definition at line 135 of file ADPCM_STREAMING/rs232.c.

Referenced by main().

00136 {
00137   return WriteFile(handle_com, buffer, size, (DWORD *) _written_bytes, (LPOVERLAPPED) NULL);
00138 }


Variable Documentation

COMMTIMEOUTS g_cto [static]

Initial value:

Definition at line 38 of file ADPCM_STREAMING/rs232.c.

Referenced by rs232_open().

DCB g_dcb [static]

Initial value:

{
  sizeof(DCB),          
  9600,                 
  TRUE,                 
  FALSE,                
  FALSE,                
  FALSE,                
  DTR_CONTROL_ENABLE,   
  FALSE,                
  FALSE,                
  FALSE,                
  FALSE,                
  FALSE,                
  FALSE,                
  RTS_CONTROL_ENABLE,   
  FALSE,                
  0,                    
  0,                    
  0x100,                
  0x100,                
  8,                    
  NOPARITY,             
  ONESTOPBIT,           
  0x11,                 
  0x13,                 
    '?',                  
  0x1A,                 
  0x10                
}

Definition at line 48 of file ADPCM_STREAMING/rs232.c.

Referenced by rs232_open().

HANDLE handle_com = NULL [static]

Definition at line 35 of file ADPCM_STREAMING/rs232.c.

Referenced by rs232_close(), rs232_open(), rs232_read(), and rs232_write().


Generated on Fri Feb 19 02:23:20 2010 for AVR32 UC3 - EVK1104 DSPLib Demo Documentation by  doxygen 1.5.5