• Viernes 3 de Mayo de 2024, 01:06

Autor Tema:  FIONREAD was not declared in this scope?  (Leído 3925 veces)

diego.martinez

  • Miembro MUY activo
  • ***
  • Mensajes: 297
    • Ver Perfil
FIONREAD was not declared in this scope?
« en: Jueves 6 de Octubre de 2011, 18:18 »
0
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. }

Eternal Idol

  • Moderador
  • ******
  • Mensajes: 4696
  • Nacionalidad: ar
    • Ver Perfil
Re:FIONREAD was not declared in this scope?
« Respuesta #1 en: Jueves 6 de Octubre de 2011, 19:29 »
0
Proba con:
Código: [Seleccionar]
#include <sys/ioctl.h>

Nacional y Popular En mi país la bandera de Eva es inmortal.


Queremos una Argentina socialmente justa, económicamente libre y  políticamente soberana.
¡Perón cumple, Evita dignifica!


La mano invisible del mercado me robo la billetera.

diego.martinez

  • Miembro MUY activo
  • ***
  • Mensajes: 297
    • Ver Perfil
Re:FIONREAD was not declared in this scope?
« Respuesta #2 en: Viernes 7 de Octubre de 2011, 12:19 »
0
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!

Eternal Idol

  • Moderador
  • ******
  • Mensajes: 4696
  • Nacionalidad: ar
    • Ver Perfil
Re:FIONREAD was not declared in this scope?
« Respuesta #3 en: Sábado 8 de Octubre de 2011, 00:30 »
0
De nadas  :guitar:

Nacional y Popular En mi país la bandera de Eva es inmortal.


Queremos una Argentina socialmente justa, económicamente libre y  políticamente soberana.
¡Perón cumple, Evita dignifica!


La mano invisible del mercado me robo la billetera.