Need to disable DTR on serial port

Geoffrey Hausheer winedevel9605 at phracturedblue.com
Mon Apr 12 09:09:06 CDT 2004


On Mon, 12 Apr 2004 09:26:30 +0200, "Rein Klazes" said:
> > 1) it might be better to call COMM_WhackModem() after tcsetattr() so 
> > previous flow control settings don't interfere with setting the RTS/DTS 
> > lines.
> > 
> > 2) #ifdef guards around TIOCM_DTR and TIOCM_RTS?
> > 
> 
> Agreed, I will fix this in a moment.
> 

Well, I tried Rein's latest patch out, and it still doesn't let me
communicate with the device (using either my test program or TzMax).  I
am not sure if the patch isn't working (I can see the relevant code being
called in winedbg), if there is something else required that wine isn't
doing, or if it is a timing issue.

In case it is interesting, here is my test app.  This appears to be the
minimum set of commands needed to communicate with the device.

Note the tight write/query loop.  Adding even a 'Sleep(1)' within that
loop prevents the communication from working in Windows.

I'm open to any other suggestions.
Thanks,
.Geoff
-------------- next part --------------
#include <windows.h>

int main(int argc, char *argv[])
{
   DCB dcb;
   HANDLE hCom;
   BOOL fSuccess;
   char *pcCommPort = "COM1";

   hCom = CreateFile( pcCommPort,
                    GENERIC_READ | GENERIC_WRITE,
                    0,    // must be opened with exclusive-access
                    NULL, // no security attributes
                    OPEN_EXISTING, // must use OPEN_EXISTING
                    0,    // not overlapped I/O
                    NULL  // hTemplate must be NULL for comm devices
                    );

   if (hCom == INVALID_HANDLE_VALUE) 
   {
       // Handle the error.
       printf ("CreateFile failed with error %d.\n", GetLastError());
       return (1);
   }

   // Build on the current configuration, and skip setting the size
   // of the input and output buffers with SetupComm.

   // SetupComm(hCom, 49152, 49152);
   COMMTIMEOUTS timout;
   timout.ReadIntervalTimeout = 0;
   timout.ReadTotalTimeoutMultiplier = 0;
   timout.ReadTotalTimeoutConstant = 0;
   timout.WriteTotalTimeoutMultiplier = 0;
   timout.WriteTotalTimeoutConstant = 0;
   SetCommTimeouts(hCom, &timout);

   fSuccess = GetCommState(hCom, &dcb);

   if (!fSuccess) 
   {
      // Handle the error.
      printf ("GetCommState failed with error %d.\n", GetLastError());
      return (2);
   }

   // Fill in DCB: 57,600 bps, 8 data bits, no parity, and 1 stop bit.

   dcb.BaudRate = CBR_2400;     // set the baud rate
   dcb.ByteSize = 8;             // data size, xmit, and rcv
   dcb.Parity = NOPARITY;        // no parity bit
   dcb.StopBits = TWOSTOPBITS;    // one stop bit
   dcb.fDtrControl = DTR_CONTROL_DISABLE;
   fSuccess = SetCommState(hCom, &dcb);
   fSuccess = GetCommState(hCom, &dcb);

   printf("DWORD0: %d\n", dcb.DCBlength);
   printf("DWORD1: 0x%08x\n", dcb.BaudRate);
   printf("DWORD2: 0x%08x\n", *((unsigned long *)(&dcb)+2));
   printf("DWORD3: 0x%08x (reserved:2,xon:2)\n", 
          *((unsigned long *)(&dcb)+3));
   printf("DWORD4: 0x%08x (xoff:2,bytesize,parity)\n", 
          *((unsigned long *)(&dcb)+4));
   printf("DWORD5: 0x%08x (Stopbits,xon,xoff,err)\n", 
          *((unsigned long *)(&dcb)+5));
   printf("DWORD6: 0x%08x (eof,ext,reserved:2)\n", 
          *((unsigned long *)(&dcb)+6));

   if (!fSuccess) 
   {
      // Handle the error.
      printf ("SetCommState failed with error %d.\n", GetLastError());
      return (3);
   }

   printf ("Serial port %s successfully reconfigured.\n", pcCommPort);
   char d[10] = "C",junk[10];
   COMSTAT stat1;
   DWORD err, count =0;
   int i, j, done = 0;
   
   PurgeComm(hCom, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
   ClearCommError(hCom, &err, &stat1);
   for (j = 0; j < 1000; j++) {
     PurgeComm(hCom, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
     WriteFile(hCom, &d, 1, &count, NULL);
     for(i = 0; i < 1; i++) {
        ClearCommError(hCom, &err, &stat1);
        if (stat1.cbInQue) {
          printf("Found %d chars in %d(%d) trys!\n", stat1.cbInQue, i, j);
          done = 1;
          break;
        }
      }
      if (done) {
        break;
      }
   }
   return (0);
}




More information about the wine-devel mailing list