Tcl Source Code

Artifact [e210ce34aa]
Login

Artifact e210ce34aa9abf129129746921e2d16574b2bffa:

Attachment "tclWinSerial.c.patch" to ticket [656112ffff] added by schroedter 2002-12-29 21:01:44.
*** tcl\win\tclWinSerial.c.old	Wed Nov 27 08:03:56 2002
--- tcl\win\tclWinSerial.c	Sun Dec 29 13:29:40 2002
***************
*** 189,194 ****
--- 189,195 ----
                  Tcl_Interp *interp, CONST char *optionName,
                  CONST char *value));
  static DWORD WINAPI     SerialWriterThread(LPVOID arg);
+ static int      setDefaultOptions (HANDLE handle);
  
  /*
   * This structure describes the channel type structure for command serial
***************
*** 1457,1463 ****
       */
      SetCommTimeouts(handle, &no_timeout);
  
- 
      if (permissions & TCL_READABLE) {
          infoPtr->osRead.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
      }
--- 1458,1463 ----
***************
*** 1483,1488 ****
--- 1483,1497 ----
      Tcl_SetChannelOption(NULL, infoPtr->channel, "-translation", "auto");
      Tcl_SetChannelOption(NULL, infoPtr->channel, "-eofchar", "\032 {}");
  
+ 
+     /*
+      * Setup default configuration
+      * Reset handshake, for Tcl < 8.4 this has implicitly be done by 
+      * configuring -mode.
+      */
+     setDefaultOptions(handle);
+     Tcl_SetChannelOption(NULL, infoPtr->channel, "-handshake", "none");
+ 
      return infoPtr->channel;
  }
  
***************
*** 1554,1559 ****
--- 1563,1602 ----
  /*
   *----------------------------------------------------------------------
   *
+  * setDefaultOptions --
+  *
+  *  Sets the default options of a serial channel.
+  *
+  * Results:
+  *  1=success, 0=error
+  *----------------------------------------------------------------------
+  */
+ static int 
+ setDefaultOptions (handle)
+     HANDLE handle;
+ {
+     DCB dcb;
+ 
+     if (! GetCommState(handle, &dcb)) {
+         return 0;
+     }
+ 
+     /* Default settings for serial communications */ 
+     dcb.fBinary = TRUE;
+     dcb.fErrorChar = FALSE;
+     dcb.fNull = FALSE;
+     dcb.fAbortOnError = FALSE;
+ 
+     if (! SetCommState(handle, &dcb) ) {
+         return 0;
+     }
+ 
+     return 1; 
+ }
+ 
+ /*
+  *----------------------------------------------------------------------
+  *
   * SerialSetOptionProc --
   *
   *  Sets an option on a channel.
***************
*** 1595,1600 ****
--- 1638,1644 ----
      * Option -mode baud,parity,databits,stopbits
      */
      if ((len > 2) && (strncmp(optionName, "-mode", len) == 0)) {
+         DCB mode;
          
          if (! GetCommState(infoPtr->handle, &dcb)) {
              if (interp) {
***************
*** 1603,1610 ****
              }
              return TCL_ERROR;
          }
          native = Tcl_WinUtfToTChar(value, -1, &ds);
!         result = (*tclWinProcs->buildCommDCBProc)(native, &dcb);
          Tcl_DStringFree(&ds);
          
          if (result == FALSE) {
--- 1647,1664 ----
              }
              return TCL_ERROR;
          }
+ 
+         /* 
+         * Work on a copy(mode) of the current configuration(dcb)
+         * to make sure we have a proper DCB
+         */
+         memmove(&mode, &dcb, sizeof(DCB));
+ 
+         /* 
+         * Let the windows API parse the -mode string
+         */
          native = Tcl_WinUtfToTChar(value, -1, &ds);
!         result = (*tclWinProcs->buildCommDCBProc)(native, &mode);
          Tcl_DStringFree(&ds);
          
          if (result == FALSE) {
***************
*** 1616,1626 ****
              return TCL_ERROR;
          }
  
!         /* Default settings for serial communications */ 
!         dcb.fBinary = TRUE;
!         dcb.fErrorChar = FALSE;
!         dcb.fNull = FALSE;
!         dcb.fAbortOnError = FALSE;
  
          if (! SetCommState(infoPtr->handle, &dcb) ) {
              if (interp) {
--- 1670,1684 ----
              return TCL_ERROR;
          }
  
!         /* 
!         * Windows BuildCommDCB() implicitly resets handshake.
!         * We use only "baud,parity,data,stop", otherwise the order of
!         * the -mode, -handshake options becomes important (bug#656112).
!         */
!         dcb.BaudRate = mode.BaudRate;
!         dcb.Parity   = mode.Parity;
!         dcb.ByteSize = mode.ByteSize;
!         dcb.StopBits = mode.StopBits;
          
          if (! SetCommState(infoPtr->handle, &dcb) ) {
              if (interp) {