DTR/RTS fixes in {G|S}etCommState

Rein Klazes rklazes at xs4all.nl
Fri Apr 9 13:06:58 CDT 2004


Hi,

Part fix for Juergen Veiths problem.

Changelog:
	dlls/kernel	: comm.c
	Fix GetCommState and SetCommState, so that these functions
	can be used to set/clear/read the DTR and RTS lines

Rein.
-- 
Rein Klazes
rklazes at xs4all.nl
-------------- next part --------------
--- wine/dlls/kernel/comm.c	2004-01-16 03:21:01.000000000 +0100
+++ mywine/dlls/kernel/comm.c	2004-04-09 19:52:08.000000000 +0200
@@ -1092,6 +1092,11 @@
 	   (lpdcb->StopBits == TWOSTOPBITS)?2:0);
      TRACE("%s %s\n",(lpdcb->fInX)?"IXON":"~IXON",
 	   (lpdcb->fOutX)?"IXOFF":"~IXOFF");
+     TRACE("fOutxCtsFlow %d fRtsControl %d\n", lpdcb->fOutxCtsFlow,
+             lpdcb->fRtsControl);
+     TRACE("fOutxDsrFlow %d fDtrControl%d\n", lpdcb->fOutxDsrFlow,
+             lpdcb->fDtrControl);
+             
 
      fd = get_comm_fd( handle, GENERIC_READ );
      if (fd < 0) return FALSE;
@@ -1385,10 +1390,23 @@
 	  }
 #endif
 
+	if(!lpdcb->fOutxCtsFlow )
+        {
+            if(lpdcb->fRtsControl == RTS_CONTROL_DISABLE)
+                COMM_WhackModem(fd, ~TIOCM_RTS, 0);
+            else    
+                COMM_WhackModem(fd, 0, TIOCM_RTS);
+        }
+        if(lpdcb->fRtsControl == RTS_CONTROL_TOGGLE)
+            FIXME("RTS_CONTROL_TOGGLE is not supported.\n");
+
 	if (lpdcb->fDtrControl == DTR_CONTROL_HANDSHAKE)
-	  {
+        {
              WARN("DSR/DTR flow control not supported\n");
-	  }
+	} else if(lpdcb->fDtrControl == DTR_CONTROL_DISABLE)
+            COMM_WhackModem(fd, ~TIOCM_DTR, 0);
+        else    
+            COMM_WhackModem(fd, 0, TIOCM_DTR);
 
 	if (lpdcb->fInX)
 		port.c_iflag |= IXON;
@@ -1432,14 +1450,19 @@
 {
      struct termios port;
      int fd,speed;
+     int stat = DTR_CONTROL_ENABLE | RTS_CONTROL_ENABLE;
 
      TRACE("handle %p, ptr %p\n", handle, lpdcb);
 
      fd = get_comm_fd( handle, GENERIC_READ );
      if (fd < 0) return FALSE;
-     if (tcgetattr(fd, &port) == -1) {
+     if (tcgetattr(fd, &port) == -1
+#ifdef TIOCMGET
+             || ioctl(fd, TIOCMGET, &stat) == -1
+#endif
+             ) {
                 int save_error=errno;
-                ERR("tcgetattr error '%s'\n", strerror(save_error));
+                ERR("tcgetattr or ioctl error '%s'\n", strerror(save_error));
                 COMM_SetCommError(handle,CE_IOE);
                 release_comm_fd( handle, fd );
 		return FALSE;
@@ -1562,7 +1585,11 @@
 
 	/* termios does not support DTR/DSR flow control */
 	lpdcb->fOutxDsrFlow = 0;
-	lpdcb->fDtrControl = DTR_CONTROL_ENABLE;
+	lpdcb->fDtrControl =
+#ifdef TIOCM_DTR
+            !(stat & TIOCM_DTR) ?  DTR_CONTROL_DISABLE:
+#endif
+                DTR_CONTROL_ENABLE  ;
 
 #ifdef CRTSCTS
 
@@ -1572,7 +1599,11 @@
 	} else
 #endif
 	{
-		lpdcb->fRtsControl = RTS_CONTROL_ENABLE;
+		lpdcb->fRtsControl = 
+#ifdef TIOCM_RTS
+                    !(stat & TIOCM_RTS) ?  RTS_CONTROL_DISABLE :
+#endif
+                    RTS_CONTROL_ENABLE ;
 		lpdcb->fOutxCtsFlow = 0;
 	}
 	if (port.c_iflag & IXON)
@@ -1601,6 +1632,10 @@
 	      (lpdcb->StopBits == TWOSTOPBITS)?2:0);
 	TRACE("%s %s\n",(lpdcb->fInX)?"IXON":"~IXON",
 	      (lpdcb->fOutX)?"IXOFF":"~IXOFF");
+         TRACE("fOutxCtsFlow %d fRtsControl %d\n", lpdcb->fOutxCtsFlow,
+                 lpdcb->fRtsControl);
+         TRACE("fOutxDsrFlow %d fDtrControl%d\n", lpdcb->fOutxDsrFlow,
+                 lpdcb->fDtrControl);
 #ifdef CRTSCTS
 	if (	lpdcb->fOutxCtsFlow 			||
 		lpdcb->fRtsControl == RTS_CONTROL_HANDSHAKE
@@ -1609,7 +1644,6 @@
         else
 
 	  TRACE("~CRTSCTS\n");
-
 #endif
 	return TRUE;
 }


More information about the wine-patches mailing list