From 4180d357e059271dd29f00ff8212f1839fdc6dba Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Wed, 15 Sep 2010 15:35:20 -0400 Subject: [PATCH] Integrating the EV_READ code. --- serialport_native/serialport_native.cc | 40 ++++++++++++++++++++------ test.js | 1 + 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/serialport_native/serialport_native.cc b/serialport_native/serialport_native.cc index 16e6f63..4164bc4 100644 --- a/serialport_native/serialport_native.cc +++ b/serialport_native/serialport_native.cc @@ -57,15 +57,6 @@ public: } - - static void - signal_handler_IO (int status) - { - printf("%i", status); - printf("received SIGIO signal.\n"); - } - - bool Open(const char* path, int baudrate, int databits, int stopbits, int parity) { if (fd_) return false; struct termios newtio; @@ -340,6 +331,12 @@ protected: SerialPort () : EventEmitter () { fd_ = NULL; + + ev_init(&read_watcher_, io_event); + read_watcher_.data = this; + + ev_init(&write_watcher_, io_event); + write_watcher_.data = this; } ~SerialPort () @@ -350,7 +347,32 @@ protected: } } private: + + void Event (int revents) + { + if (revents & EV_ERROR) { + printf("EV_ERROR"); + return; + } + + if (revents & EV_READ) { + Emit(data_symbol, 0, NULL); + return; + } + } + + + static void + io_event (EV_P_ ev_io *w, int revents) + { + SerialPort *serial_port = static_cast(w->data); + serial_port->Event(revents); + } + + int fd_; + ev_io read_watcher_; + ev_io write_watcher_; }; diff --git a/test.js b/test.js index 81f6038..425f081 100644 --- a/test.js +++ b/test.js @@ -2,6 +2,7 @@ var sys = require("sys"); var SerialPort = require("./serialport_native").SerialPort; sp = new SerialPort; sp.open("/dev/tty"); +sp.write("TEST"); sp.close(); /*