Cette page vous affiche les différences entre la révision choisie et la version actuelle de la page.
robotics:computing:linux_asynchronous_serial_programming_how_to [2011/02/07 00:15] gdo |
— (Version actuelle) | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== Introduction ====== | ||
- | This article describes asynchrous serial programming using signal handler. | ||
- | |||
- | == References == | ||
- | * Serial Programming HOWTO : [[http://tldp.org/HOWTO/Serial-Programming-HOWTO/]] | ||
- | |||
- | == Hardware used : == | ||
- | * A desktop PC. | ||
- | * Roboard RB-100 : [[http://www.roboard.com/RB-100.htm]] | ||
- | * Mini PCI VGA Card : [[http://www.icop.com.tw/pddetail.aspx?id=93&pid=4]] | ||
- | * 4 Go micro SD card plugged in the built-in micro-SD card reader. | ||
- | * An internet connection. | ||
- | |||
- | == 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. There is just one function to initialize the serial communication. | ||
- | Only serial port device, baudrate and if there is a parity checking can be set. Everything else is hard coded, supposing we use 8 bits of data, 1 stop bit and a prefix on parity error. | ||
- | Then it results in a very simple header file **serialCom.h** : | ||
- | <code>#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 : PARMRK = If IGNPAR is not set, prefix a character with a parity error or | ||
- | framing error with \377 \0 */ | ||
- | #define SERIAL_INPUT PARMRK | ||
- | |||
- | /* Handler type definition */ | ||
- | typedef void | ||
- | (*serial_handler)(int status); | ||
- | |||
- | /* Serial port initialization function */ | ||
- | int | ||
- | serialConfiguration(serial_handler, const char* device, tcflag_t baudrate, | ||
- | char parity); | ||
- | |||
- | #ifdef __cplusplus | ||
- | } | ||
- | #endif | ||
- | |||
- | #endif | ||
- | </code> |