There is nothing plugged on com1....???
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: There is nothing plugged on com1....???

  1. #1
    Join Date
    Apr 2004

    There is nothing plugged on com1....???

    I have to check if in the port Com1 is puggled some device.
    I had use this code and if the device is plugged it is work correctly but if there is nothing it don' t return nothing
    Some advice???

    hCom = CreateFile( port,
    0, // comm devices must be opened w/exclusive-access
    NULL, // no security attributes
    OPEN_EXISTING, // comm devices must use OPEN_EXISTING
    0, // not overlapped I/O
    NULL // hTemplate must be NULL for comm devices

    if (hCom == INVALID_HANDLE_VALUE) {
    dwError = GetLastError();
    return E_OPENING;

  2. #2
    Join Date
    May 2000
    If the device when connected to the Com1 port brings up Carrier (DCD), then you can check for it.

    // Code example

    BOOL CheckCarrier()
    DWORD dwModemStatus = 0;
    BOOL fDeviceCarrier = FALSE;
    dwModemStatus = EV_RLSD;

    // No DCD from Device
    if((m_hComm==NULL) || (m_hComm==INVALID_HANDLE_VALUE))
    return FALSE;

    if(!GetCommModemStatus(m_hComm, &dwModemStatus))
    // DCD still low;
    // DCD is high from device
    fDeviceCarrier = MS_RLSD_ON & dwModemStatus;
    return fDeviceCarrier;
    return FALSE;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)