Pular para o conteúdo

Portas seriais [RESOLVIDO]

Responder tópico
  • Denunciar
  • Indicar

1. Portas seriais [RESOLVIDO]

Enviado em 17/12/2012 - 11:26h

Pessoal, boa vida!

Estou precisando criar um programinha em C que me permita escrever e ler strings hex na porta serial.

Alguém pode me indicar como fazê-lo? Algum exemplo, artigo, documento, etc...?

Grato!

Live long and prosper!

Responder tópico

2. RS-232

Melhor resposta

Enviado em 17/12/2012 - 12:08h

FROM: http://www.easysw.com/~mike/serial/serial.html

include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */

/*
* 'open_port()' - Open serial port 1.
*
* Returns the file descriptor on success or -1 on error.
*/

int
open_port(void)
{
int fd; /* File descriptor for the port */


fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
/*
* Could not open the port.
*/

perror("open_port: Unable to open /dev/ttyS0 - ");
}
else
fcntl(fd, F_SETFL, 0);

return (fd);
}

3. Thanx

Enviado em 17/12/2012 - 12:15h

Muito obrigado uilianries!!

Responder tópico

Responder tópico

Entre na sua conta para responder.

Fazer login para responder