SoloCodigo

Programación General => C/C++ => Mensaje iniciado por: diego.martinez en Jueves 6 de Octubre de 2011, 18:18

Título: FIONREAD was not declared in this scope?
Publicado por: diego.martinez en Jueves 6 de Octubre de 2011, 18:18
Buenas:

Me salta el error
/home/diego/pru_project/src/pru_project.cpp: In function 'int main()':
/home/diego/pru_project/src/pru_project.cpp:65: error: 'FIONREAD' was not declared in this scope
/home/diego/pru_project/src/pru_project.cpp:65: error: 'ioctl' was not declared in this scope
make[2]: *** [pru_project.o] Error 1

En el codigo, parece que no encuentra la constante de FIONREAD pero en la documentación pone que esta en termios.h e ioctl lo mismo.
Estoy programando en Unix (Ubuntu) y usando Kdevelop.

Que puede estar pasando? por que la cabecera la tengo incluida en el modulo.
Gracias!



Código: C++
  1. /***************************************************************************
  2.  by Diego Martinez
  3.  ***************************************************************************/
  4.  
  5.  
  6.     #include <stdio.h>   /* Standard input/output definitions */
  7.     #include <string.h>  /* String function definitions */
  8.     #include <unistd.h>  /* UNIX standard function definitions */
  9.     #include <fcntl.h>   /* File control definitions */
  10.     #include <errno.h>   /* Error number definitions */
  11.     #include <termios.h> /* POSIX terminal control definitions */
  12. #include <iostream>
  13. #include <getopt.h>
  14.  
  15.     /*
  16.      * 'open_port()' - Open serial port 1.
  17.      *
  18.      * Returns the file descriptor on success or -1 on error.
  19.      */
  20.  
  21.     int open_port(void)
  22.     {
  23.       int fd; /* File descriptor for the port */
  24.  
  25.  
  26.       fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
  27.       if (fd == -1)
  28.       {
  29.        /*
  30.         * Could not open the port.
  31.         */
  32.  
  33.         perror("open_port: Unable to open /dev/ttyS0 - ");
  34.       }
  35.       else
  36.       {
  37.         fcntl(fd, F_SETFL, 0);
  38. //The FNDELAY option causes the read function to return 0 if no characters are available on the port. To restore normal (blocking) behavior, call fcntl() without the FNDELAY option:
  39.         fcntl(fd, F_SETFL, FNDELAY);           
  40.         //configuramos el puerto
  41.         struct termios options;
  42.         // Get the current options for the port...
  43.         tcgetattr(fd, &options);
  44.         // Set the baud rates to 19200...      
  45.         cfsetispeed(&options, B9600); //baudios de entrada
  46.         cfsetospeed(&options, B9600); //baudios de salida
  47.         //Enable the receiver and set local mode...
  48.         options.c_cflag |= (CLOCAL | CREAD);
  49.      // Set the new options for the port...
  50.         tcsetattr(fd, TCSANOW, &options);
  51.         }
  52.  
  53.  
  54.       return (fd);
  55.     }
  56.  
  57. int main()
  58. {
  59. int hcom=open_port();
  60.  
  61.  
  62. while(true)
  63. {
  64. int bytes;
  65. ioctl(hcom, FIONREAD, &bytes);
  66. if (bytes>0)
  67.         printf("Datos!\r\n");
  68. }
  69.  
  70. close(hcom);
  71.  
  72. return 0;
  73. }
Título: Re:FIONREAD was not declared in this scope?
Publicado por: Eternal Idol en Jueves 6 de Octubre de 2011, 19:29
Proba con:
Código: [Seleccionar]
#include <sys/ioctl.h>
Título: Re:FIONREAD was not declared in this scope?
Publicado por: diego.martinez en Viernes 7 de Octubre de 2011, 12:19
pues si, era eso. Lo desconcertante es que he estado leyendo un manual para la lectura del rs232 que me decian lo de que estaba incluido en termios.h y luego googleando lo mismo... que curioso

muchas gracias EternalIdol!
Título: Re:FIONREAD was not declared in this scope?
Publicado por: Eternal Idol en Sábado 8 de Octubre de 2011, 00:30
De nadas  :guitar: