Hello, The attached patch has some changed that I need to apply some others in the C# side in the class library.
Is it ok to commit? Carlos.
Index: serial.c =================================================================== --- serial.c (revisiĆ³n: 59128) +++ serial.c (copia de trabajo) @@ -41,11 +41,12 @@ /* This is a copy of System.IO.Ports.SerialSignal */ typedef enum { - Cd = 0, /* Carrier detect */ - Cts = 1, /* Clear to send */ - Dsr = 2, /* Data set ready */ - Dtr = 3, /* Data terminal ready */ - Rts = 4 /* Request to send */ + NoneSignal, + Cd = 1, /* Carrier detect */ + Cts = 2, /* Clear to send */ + Dsr = 4, /* Data set ready */ + Dtr = 8, /* Data terminal ready */ + Rts = 16 /* Request to send */ } MonoSerialSignal; int @@ -67,8 +68,6 @@ tcflush(fd, TCIOFLUSH); tcsetattr(fd,TCSANOW,&newtio); - fcntl (fd, F_SETFL, O_NONBLOCK); - return fd; } @@ -79,19 +78,9 @@ } guint32 -read_serial (int fd, guchar *buffer, int offset, int count, int timeout) +read_serial (int fd, guchar *buffer, int offset, int count) { guint32 n; - struct pollfd ufd; - - ufd.fd = fd; - ufd.events = POLLHUP | POLLIN | POLLERR; - - poll (&ufd, 1, timeout); - - if ((ufd.revents & POLLIN) != POLLIN) { - return -1; - } n = read (fd, buffer + offset, count); @@ -123,6 +112,20 @@ tcflush(fd, input ? TCIFLUSH : TCOFLUSH); } +gint32 +get_bytes_in_buffer (int fd, gboolean input, gint32 *error) +{ + gint32 retval; + + *error = 0; + if (ioctl (fd, input ? TIOCINQ : TIOCOUTQ, &retval) == -1) { + *error = -1; + return -1; + } + + return retval; +} + gboolean set_attributes (int fd, int baud_rate, MonoParity parity, int dataBits, MonoStopBits stopBits, MonoHandshake handshake) { @@ -249,22 +252,42 @@ return TIOCM_DTR; case Rts: return TIOCM_RTS; + default: + return 0; } /* Not reached */ return 0; } +static MonoSerialSignal +get_mono_signal_codes (int signals) +{ + MonoSerialSignal retval = NoneSignal; + + if ((signals & TIOCM_CAR) != 0) + retval |= Cd; + if ((signals & TIOCM_CTS) != 0) + retval |= Cts; + if ((signals & TIOCM_DSR) != 0) + retval |= Dsr; + if ((signals & TIOCM_DTR) != 0) + retval |= Dtr; + if ((signals & TIOCM_RTS) != 0) + retval |= Rts; + + return retval; +} + gint32 -get_signal (int fd, MonoSerialSignal signal) +get_signals (int fd) { - int signals, expected; + int signals; - expected = get_signal_code (signal); if (ioctl (fd, TIOCMGET, &signals) == -1) return -1; - return (expected & signals) != 0; + return get_mono_signal_codes (signals); } gint32 @@ -291,6 +314,21 @@ return 1; } +gint32 +poll_serial (int fd) +{ + struct pollfd pinfo; + + pinfo.fd = fd; + pinfo.events = POLLIN; + pinfo.revents = 0; + + if (poll (&pinfo, 1, 0) == -1) + return -1; + + return (pinfo.revents & POLLIN) != 0 ? 1 : 0; +} + /* * mono internals should not be used here. * this serial stuff needs to be implemented with icalls.
_______________________________________________ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list