Я пытаюсь использовать libevent для управления последовательной связью между встроенным устройством Linux и ПК.Rs232 using libevent
Первая проблема с libevent. Я создал проект C в упадке, в главном я создаю некоторые события, и это нормально для компилятора:
#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);
.....
}
Но тогда, в «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;
}
и misteriously Eclipse, не находит event.h (только в function_test.c) и, таким образом, я получил следующие ошибки:
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)
...
В этом случае Libevent, вероятно, будет излишним. Прежде всего, libevent - это строго сокеты. Теоретически он реагирует на другие события: обычно ваши собственные события. Но это просто не предназначено для последовательной связи. Кроме того, большая часть libevent построена для уровня сокета и требует ipaddress и порт. То, что вы делаете, я должен был сделать в 2001 году, и он отлично поработал. Но я давно уже потерял свой код для этого. –
Проблема может заключаться в том, что я использую некоторые функции из версии libevent, предшествующей версии 2.0. С другой стороны, Libevent не является хорошим вариантом для управления этим видом общения? – Cristina
Любые комментарии? :-( – Cristina