Outils pour utilisateurs

Outils du site


robotics:computing:linux_asynchronous_serial_programming_how_to

Ceci est une ancienne révision du document !


Introduction

This article describes asynchrous serial programming using signal handler.

References
Hardware used :
Softwares :
  • Ubuntu 10.10 installed on both Roboard and desktop PC : http://www.ubuntu.com/
  • Package build-essential already installed on your Ubuntu operating system.

Asynchronous serial I/O library

The following code is very simple. We will only be able to set the baudrate and the serial port device when initializing the serial port configuration. Everything else is hard coded, supposing we use 8 bits of data, 1 stop bit and no parity check. Then it results in a very simple header file serialCom.h :

#ifndef _SERIALCOM_H_
#define _SERIALCOM_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include <termios.h>

/* Controls :  CS8      = 8 bits
 *             CREAD    = Enable reading */
#define SERIAL_CONTROL  (CS8 | CREAD);

/* Input    :  IGNPAR   = No parity check */
#define SERIAL_INPUT    IGNPAR;

/* Handler type definition */
typedef void (*serial_handler) (int status);

/* Serial port initialization function */
int serialConfiguration( serial_handler, const char* device, tcflag_t baudrate);

#ifdef __cplusplus
}
#endif

#endif
robotics/computing/linux_asynchronous_serial_programming_how_to.1296663845.txt.gz · Dernière modification: 2012/09/20 10:52 (modification externe)