elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Tutorial básico de Quickjs


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / Error al leer datos función read en: 3 Agosto 2017, 16:05 pm
Buenas,

Estoy intentando mostrar por pantalla los mensajes recibidos por parte de arduino mediante puerto serie. Para ello he configurado el puerto serie de la siguiente forma:

Código:

// Open the port in read-write mode
m_portHandler = open(pDev, O_RDWR | O_NOCTTY);
if(m_portHandler < 0)
return;

// Get the port attributes and flush all data on queues
tcgetattr(m_portHandler, &my_termios);
tcflush(m_portHandler, TCIOFLUSH);

// Setup the communication
my_termios.c_iflag &= ~(BRKINT | IGNPAR | PARMRK | INPCK |ISTRIP | IXON | INLCR | IGNCR | ICRNL);
my_termios.c_iflag |= IGNBRK | IXOFF;
my_termios.c_oflag &= ~(OPOST);
my_termios.c_cflag |= CLOCAL | CREAD;
my_termios.c_cflag &= ~PARENB;
my_termios.c_cflag |= CS8;
my_termios.c_cflag &= ~CSTOPB;
my_termios.c_cflag &= ~CRTSCTS;   
my_termios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON | NOFLSH | TOSTOP | ISIG | IEXTEN);
my_termios.c_cc[VMIN]=1; //Each simple read call will be blocked until recive at least one byte
my_termios.c_cc[VTIME]=0; //No timeout for reading
cfsetispeed(&my_termios, B115200);
cfsetospeed(&my_termios, B115200);
tcsetattr(m_portHandler, TCSANOW, &my_termios);

Y he usado la siguiente función para leer los datos recibidos en el puerto serie e imprimirlos por pantalla:
Código:
void lee()
{
char c;
read(m_portHandler,&c,1);
fprintf(stdout,"%x",uint8_t(c));

        }

Los datos se imprimen por pantalla pero al parecer lo imprime por bloques. Aunque la función read está configurara para que lea de byte en byte, hasta que no tiene un bloque completo no imprime nada. Por tanto, los últimos datos de información no se imprimen.
He probado a añadir más datos para completar el bloque y en ese caso si se imprimen.
No sé como solucionarlo, ¿alguna idea?.

Gracias :)
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines