2

I am trying to use libevent for manage the serial communication between an embedded Linux device and a pc.

First problem with libevent. I've created a C Project in eclipse , in the main I am creating some events and it is ok for the compiler:

#include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
 #include <event.h>
 #include "function_test.h"
....
int main(void) {

struct event ev_sighup;  //reports that the user's terminal is disconnected
struct event ev_sigterm; //program termination
struct event ev_sigint;  // program interrupt


int rv = 0;

/* Set up libevent & signal handling */

event_init();
event_set(&ev_sighup, SIGHUP, EV_SIGNAL, peripherals_end, NULL);
event_add(&ev_sighup, NULL);
event_set(&ev_sigterm, SIGTERM, EV_SIGNAL, peripherals_end, NULL);
event_add(&ev_sigterm, NULL);
event_set(&ev_sigint, SIGINT, EV_SIGNAL, peripherals_end, NULL);
event_add(&ev_sigint, NULL);

.....

}

But then, in "function_test.c":

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <event.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include "function_test.h"

.....
/*serial  file descriptor */
int 232_fd= -1;


/* Event triggered when data is available  */

struct event ev_rs232read;

.....

event_set(&ev_rs232read, 232_fd, EV_READ|EV_PERSIST, readRs232, NULL);

if ((rv = event_add(&stm32_ev_read, NULL)) < 0) {
    // log error
    return RTN_ERR;
}

return RTN_OK;

}

And misteriously Eclipse doesn't finds event.h (only in function_test.c) and thereby I got the next errors:

warning: implicit declaration of function ‘event_set’
../src/function_test.c:114: error: ‘EV_READ’ undeclared (first use in this function)
../src/function_test.c:114: error: (Each undeclared identifier is reported only once
../src/function_test.c:114: error: for each function it appears in.)
../src/function_test.c:114: error: ‘EV_PERSIST’ undeclared (first use in this function)
...
Cristina
  • 159
  • 3
  • 16
  • Libevent is probably overkill in this case. First of all, libevent is strictly sockets. In theory, it responds to other events: usually your own events. But it is simply not meant for serial communications. In addition, most of libevent is built for a socket layer and requires an ipaddress and port. What you are doing I had to do back in 2001 and it worked great. But I have long-since lost my code for that. – Mickey Kawick Sep 03 '13 at 13:33
  • The problem may be that I am using some functions from libevent version previous to 2.0. By other side, then Libevent is not a good option for managing this kind of communication? – Cristina Sep 03 '13 at 15:20

1 Answers1

0

Does this bug repeats during the compilation with GNU Autotools or just simple Makefile?

Vitaly Isaev
  • 5,392
  • 6
  • 45
  • 64