🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #4556

Very Slow communication Init on Windows-98, why?

#4556
From: Ram
Date: Mon, 09 Jan 2006 10:39
90 lines
6713 bytes
Hi, below is the function that i'm using to init my communication
for COM1, when i run it on my PC (Windows-2000) it's runs very 
fast, but when i run the same application on another PC with
Windows-98 it's takes MUCH more time, for the test i wrote a loop
that runs this function 5,000 times over and over again, on my PC
the loop took about 10 seconds, this was the time that it took
it to run ONLY 50 loops on the Windows-98 computer.... (100 times
slower than my PC)

Why does it happen? and how can i fix in my function to make it
run faster on the Win-98 computer? it's important becouse in the
communication protocol that i'm using i should init the com for 
each message (i send some bytes with parity and the rest of the
message without parity, so for each message i have to call the
init function 2 times) and it's takes lot of time in the Win-98
computer.

Thanks, here is the function:


int InitCommunication( void )
{
  COMMTIMEOUTS read_timeout;			                               // timeout structure
  char    ComName[30];
  HANDLE  ComHndl = NULL;
  DCB     PortDCB;                                                             // device control block structure

  if ( SystemInfo.ErrorInfo.Status != NO_ERRORS )                              // If Error -> Exit
    return 0;

  if ( SystemInfo.ComInfo.ComHandle )                                          // If Port already open
  {
    CloseHandle( SystemInfo.ComInfo.ComHandle );                               // Close Port
    SystemInfo.ComInfo.ComHandle = NULL;                                       // Reset Port Handle
  }

  strcpy( ComName, SystemInfo.ComInfo.ComPort );                               // Set ComName

  ComHndl = CreateFile( ComName, GENERIC_WRITE + GENERIC_READ, 0, NULL,        // Open the asked Com Port
                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );

  if ( ComHndl == INVALID_HANDLE_VALUE )                                       // Check COM Handle
    return FAIL;

  PortDCB.DCBlength= sizeof( PortDCB );                                        // Sizeof( DCB )

  GetCommState( ComHndl, &PortDCB );
  PortDCB.BaudRate                         = SystemInfo.ComInfo.BaudRate;      // Current baud rate
  PortDCB.fBinary                          = true;                             // Binary mode, no EOF check
  PortDCB.fParity                          = 0;                                // 0 = Disable Parity Checking
  PortDCB.fOutxCtsFlow                     = 0;                                // CTS output flow control
  PortDCB.fOutxDsrFlow                     = 0;                                // DSR output flow control
  PortDCB.fDtrControl                      = DTR_CONTROL_ENABLE;               // DTR flow control type
  PortDCB.fDsrSensitivity                  = 0;                                // DSR sensitivity
  PortDCB.fTXContinueOnXoff                = 1; // 0;                          // XOFF continues Tx
  PortDCB.fOutX                            = 0;                                // XON/XOFF out flow control
  PortDCB.fInX                             = 0;                                // XON/XOFF in flow control
  PortDCB.fErrorChar                       = 0;                                // Enable error replacement
  PortDCB.fNull                            = false;                            // Enable null stripping
  PortDCB.fRtsControl                      = RTS_CONTROL_ENABLE;               // RTS flow control
  PortDCB.fAbortOnError                    = 0;                                // Abort reads/writes on error
  PortDCB.ByteSize                         = 8;                                // Number of bits/byte, 4-8
  PortDCB.Parity                           = (char)SystemInfo.ComInfo.Parity;  // 0-4 = No, Odd, Even, Mark, Space
  PortDCB.StopBits                         = ONESTOPBIT;                       // 0, 1, 2 = 1, 1.5, 2

  PortDCB.XonLim                           = 50;                               // Transmit XON threshold
  PortDCB.XoffLim                          = 50;                               // Transmit XOFF threshold
  PortDCB.XonChar                          = 0;                                // Tx and Rx XON character
  PortDCB.XoffChar                         = 0;                                // Tx and Rx XOFF character
  PortDCB.ErrorChar                        = 0;                                // Error replacement character
  PortDCB.EofChar                          = 0;                                // End of input character
  PortDCB.EvtChar                          = 0;                                // Received event character
  read_timeout.ReadIntervalTimeout = 0;                                        // Read Interval Timeout
  read_timeout.ReadTotalTimeoutMultiplier  = 0;                                // Read Total Timeout Multiplier
  read_timeout.ReadTotalTimeoutConstant = SystemInfo.ComInfo.RxTimeout;        // Read Total Timeout Constant
  read_timeout.WriteTotalTimeoutMultiplier = 0;                                // Write Total Timeout Multiplier
  read_timeout.WriteTotalTimeoutConstant = SystemInfo.ComInfo.TxTimeout;       // Write Total Timeout Constant

  if ( !SetCommState( ComHndl, &PortDCB ) )                                    // Configures Com Port
    return FAIL;                                                               // Return If Fail

  if ( !SetCommTimeouts( ComHndl, &read_timeout ) )                            // Set Tx & Rx Timeouts
    return FAIL;

  SystemInfo.ComInfo.ComHandle = ComHndl;                                      // Set Communication Handle
  hndl = SystemInfo.ComInfo.ComHandle;

  return PASS;   		                                               // COM Init was successful
}
Technical Details
Message-ID: <43c24b5a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!feed5.newsreader.com!newsreader.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,35fcdf173fbb2ee3,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Ram" <Ram@NoSpam.com>
Sender: "Ram" <Ram@NoSpam.com>
Reply-To: "Ram" <Ram@NoSpam.com>
Subject: Very Slow communication Init on Windows-98, why? 
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 62.0.27.159     
NNTP-Posting-Host: 207.105.83.66
Message-ID: <43c24b5a$1@newsgroups.borland.com>
Date: 9 Jan 2006 03:39:06 -0700
X-Trace: newsgroups.borland.com 1136806746 207.105.83.66 (9 Jan 2006 03:39:06 -0700)
Lines: 91
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!feed5.newsreader.com!newsreader.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail