Hello,

The attached patch adds a pair of small functions to access signals
information for the serial port. 

Carlos.
Index: serial.c
===================================================================
--- serial.c	(revisión: 57943)
+++ serial.c	(copia de trabajo)
@@ -10,6 +10,7 @@
 #include <fcntl.h>
 #include <string.h>
 #include <sys/poll.h>
+#include <sys/ioctl.h>
 
 #include <glib.h>
 
@@ -202,6 +203,62 @@
 	return TRUE;
 }
 
+static gint32
+get_signal_code (MonoSerialSignal signal)
+{
+	switch (signal) {
+		case Cd:
+			return TIOCM_CAR;
+		case Cts:
+			return TIOCM_CTS;
+		case Dsr:
+			return TIOCM_DSR;
+		case Dtr:
+			return TIOCM_DTR;
+		case Rts:
+			return TIOCM_RTS;
+	}
+
+	/* Not reached */
+	return 0;
+}
+
+gint32
+get_signal (int fd, MonoSerialSignal signal)
+{
+	int signals, expected;
+
+	expected = get_signal_code (signal);
+	if (ioctl (fd, TIOCMGET, &signals) == -1)
+		return -1;
+	
+	return (expected & signals) != 0;
+}
+
+gint32
+set_signal (int fd, MonoSerialSignal signal, gboolean value)
+{
+	int signals, expected, activated;
+
+	expected = get_signal_code (signal);
+	if (ioctl (fd, TIOCMGET, &signals) == -1)
+		return -1;
+	
+	activated = (signals & expected) != 0;
+	if (activated == value) /* Already set */
+		return 1;
+	
+	if (value)
+		signals |= expected;
+	else
+		signals &= ~expected;
+	
+	if (ioctl (fd, TIOCMSET, &signals) == -1)
+		return -1;
+	
+	return 1;
+}
+
 /*
  * mono internals should not be used here.
  * this serial stuff needs to be implemented with icalls.
Index: serial.h
===================================================================
--- serial.h	(revisión: 57943)
+++ serial.h	(copia de trabajo)
@@ -27,5 +27,14 @@
 	OnePointFive = 3
 } MonoStopBits;
 
+/* 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 */
+} MonoSerialSignal;
+
 #endif
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revisión: 57943)
+++ ChangeLog	(copia de trabajo)
@@ -1,3 +1,7 @@
+2006-03-14  Carlos Alberto Cortez <[EMAIL PROTECTED]>
+
+	* serial.c: Add functions to handle signals access.
+
 2006-03-09  Carlos Alberto Cortez <[EMAIL PROTECTED]>
 
 	* serial.c: Fix a pair of wrong or incomplete assignations
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to