Serial port data problem

Serial port data problem

Post by chand » Sat, 12 Jul 2003 04:46:17



Hello everyone,
 My scenario is like this...There is a bluetooth device that send data
from 1000 to 0, then again I start from 1000 and so on. I have my
application running on iPaq which has receives this data. My pocket pc
uses the anycom bluetooth CF card. There are three problems I am
facing..

1. I dont get data in proper order. I always get data from 766 only
and then gets data till 640. Then I get data from 895 till 788. Then I
get another 50 - 60 data items, which sometimes start form 222 or 400.
Most of time this is the case...sometimes it differs. Why dont I get
data in proper order?

2. The first data is always 766...I never get from 1000. Can anyone
tell why there is data loss(if thats the case)..or why it starts from
766?

3. After sometime, my application stops receiving data. The connection
is still there..but I dont get any more data. It flags a timeout
error. I tried removing timeout..but I still get timeout error. I am
not sure why.

 Any suggestion what might be going wrong here.I think people working
on serial port might have encountered something similar like it. My
code is as follows..

serialPortHandle = CreateFile (L"COM6:",GENERIC_WRITE | GENERIC_READ,
      0, NULL, OPEN_EXISTING, 0, NULL);

SetupComm(serialPortHandle, INQUEi, OUTQUEi);

PortDCB.DCBlength = sizeof (DCB);    

// Get the default port setting information.
 GetCommState (serialPortHandle, &PortDCB);

// Change the DCB structure settings.
  PortDCB.BaudRate = 9600;              // Current baud
  PortDCB.fBinary = TRUE;               // Binary mode; no EOF check
  PortDCB.fParity = FALSE;               // Enable parity checking
  PortDCB.fOutxCtsFlow = FALSE;         // No CTS output flow control
  PortDCB.fOutxDsrFlow = FALSE;         // No DSR output flow control
  PortDCB.fDtrControl = DTR_CONTROL_DISABLE;
                                        // DTR flow control type
  PortDCB.fDsrSensitivity = FALSE;      // DSR sensitivity
  PortDCB.fTXContinueOnXoff = TRUE;     // XOFF continues Tx
  PortDCB.fOutX = FALSE;                // No XON/XOFF out flow
control
  PortDCB.fInX = FALSE;                 // No XON/XOFF in flow control
  PortDCB.fErrorChar = FALSE;           // Disable error replacement
  PortDCB.fNull = FALSE;                // Disable null stripping
  PortDCB.fRtsControl = RTS_CONTROL_DISABLE;
                                        // RTS flow control
  PortDCB.fAbortOnError = FALSE;        // Do not abort reads/writes
on
                                        // error
  PortDCB.ByteSize = 8;                 // Number of bits/byte, 4-8
  PortDCB.Parity = NOPARITY;            // 0-4=no,odd,even,mark,space
  PortDCB.StopBits = ONESTOPBIT;        // 0,1,2 = 1, 1.5, 2

  // Configure the port according to the specifications of the DCB
  // structure.
  if (!SetCommState (serialPortHandle, &PortDCB))
  {
    // Could not create the read thread.
    MessageBox (g_hWnd, TEXT("Unable to configure the serial port"),
                TEXT("Error"), MB_OK);
    return FALSE;
  }

 if(serialPortHandle != NULL)
 {
          // I dont want to time out. I want data to be returned as
soon as I
          // get in the buffer.
  COMMTIMEOUTS commTimeOuts;
  commTimeOuts.ReadIntervalTimeout = 0;                        
commTimeOuts.ReadTotalTimeoutMultiplier = 0;
  commTimeOuts.ReadTotalTimeoutConstant = 0;
  commTimeOuts.WriteTotalTimeoutMultiplier = 0;
  commTimeOuts.WriteTotalTimeoutConstant = 0;
  SetCommTimeouts(serialPortHandle, &commTimeOuts);

  // Specify a set of events to be monitored for the port.
  SetCommMask (serialPortHandle, EV_RXCHAR | EV_ERR);
  if (dwCommModemStatus & EV_ERR)
  {
   wsprintf(szTemp, _T("SerialPort::ReadData - WaitCommEvent = EV_ERR
: %ld"), GetLastError());
   MessageBox(g_hWnd, szTemp, _T("Reading CHeck"), MB_OK);
   return 0;
  }

  while (serialPortHandle != INVALID_HANDLE_VALUE)
  {
   // Wait for an event to occur for the port.
  WaitCommEvent (serialPortHandle, &dwCommModemStatus, 0);

  // Re-specify the set of events to be monitored for the port.
   SetCommMask (serialPortHandle, EV_RXCHAR | EV_ERR);
   if (dwCommModemStatus & EV_ERR)
   {
   wsprintf(szTemp, _T("SerialPort::ReadData - WaitCommEvent = EV_ERR
: %ld"), GetLastError());
   MessageBox(g_hWnd, szTemp, _T("Reading CHeck"), MB_OK);
   return 0;
   }

   if (dwCommModemStatus & EV_RXCHAR)
   {
   // Loop for waiting for the data.
   do
   {
   // Read the data from the serial port.
   ReadFile(serialPortHandle, &ch, 1, &cBytes, NULL);

   // Display the data read.
   if (cBytes == 1)
   {
   currentData = ch;//atoi(&ch_temp);
   ch_temp = (CHAR)ch;
   wc = WriteFile(fileHandle,&ch_temp, 1, &cBytes, NULL);
   ProcessBlueData(ch_temp);
   }
   else
   {
  wsprintf(szTemp, _T("No Data received %ld"), GetLastError());
   MessageBox(g_hWnd, szTemp, _T("Reading CHeck"), MB_OK);
   }
  } while (cBytes == 1);
       }
            }
 }
 else
 MessageBox(g_hWnd, _T("Serail port not created"), _T("Error Port"),
MB_OK);

Thanks,

Chandra.

 
 
 

1. Slow Serial port & unable to add a new serial port

Hi,

I have two problems with serial ports on a new Dell machine running
windows XP Pro. The pc has one built-in serial port

1. The build serial port com1 is used by a DOS program providing a unix
terminal.
The speed is set at 19200 baud (?). the application is very, very
sluggish.

A second similar dell machine, but running win2000Pro, with the same
settings does not have this problem.
(the unix,rather Xenix has a 16 serial port extension board)

2. I need extra serial ports on the pc.
I bought a startech pci2s550 2 port serial card.
Xp recognizes the card, but refuses to install the (latest) drivers.
I contacted the startech support, they said the drivers should work, but
they don't :(

does there exist a generic serial port driver ?

best regards
Glenn de moor

2. WIN 3.5 DISKS (S)

3. Dell laptop with no serial port - support for virtual serial ports with targus r

4. Crashes when trying to close background tasks

5. Challenge: Virtual serial ports from real serial port

6. Crash on a 5200/75

7. AT&T WorldNet Svc on NT

8. no data through serial port com2

9. Serial data to USB port

10. Getting the Serial Com Ports to Work with data cable in Windows XP Pro

11. send & receive data via serial port

12. Software to monitor data on the iPaq Serial Port