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 123 of file DATA_GET/rs232.c.

References handle_com.

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

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

Definition at line 81 of file DATA_GET/rs232.c.

References ASSERT, g_cto, g_dcb, handle_com, RS232_RX_SIZE, and RS232_TX_SIZE.

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

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

Definition at line 130 of file DATA_GET/rs232.c.

References DWORD, and handle_com.

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

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

Definition at line 136 of file DATA_GET/rs232.c.

References DWORD, and handle_com.

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


Variable Documentation

COMMTIMEOUTS g_cto [static]

Initial value:

Definition at line 39 of file DATA_GET/rs232.c.

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 49 of file DATA_GET/rs232.c.

HANDLE handle_com = NULL [static]

Definition at line 36 of file DATA_GET/rs232.c.


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