Thread: COM port CreateFile -> Close Handle Works great, unless the USB device is unplugged,

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    3

    COM port CreateFile -> Close Handle Works great, unless the USB device is unplugged,

    COM port CreateFile -> Close Handle Works great, unless the USB device is unplugged, then it can not be reopened without restarted computer

    If usb device is ever unplugged, i get a return of a ERROR_FILE_NOT_FOUND from Create handle, and cannot continue unless the computer is restarted

    this happens when I am connected to the device and when I am not connected, just if it is unplugged and replugged in

    (this works awesome, and can continue to create and close, until the device is unplugged from the computer and plugged back in)
    Code:
    hcomms[hcommcount-1] = CreateFile(com, 
     GENERIC_READ | GENERIC_WRITE,
     0,
     0,
     OPEN_EXISTING,
     FILE_ATTRIBUTE_NORMAL /*| FILE_FLAG_OVERLAPPED*/,
     0);
    
     if ( hcomms[hcommcount-1] == INVALID_HANDLE_VALUE)
     {
     DWORD error = GetLastError();
     return -1;
     }
    
    
    if (!CloseHandle(hcomms[cindx]))
     {
     errorCode = GetLastError();
     }

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Does any known-to-work software reproduce the issue? Like hyperterminal etc...

    If it only occurs when you're running your code - then your code is probably at fault. Otherwise it would be a buggy driver.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. FTP program
    By jakemott in forum Linux Programming
    Replies: 14
    Last Post: 10-06-2008, 01:58 PM
  2. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  5. Ghost in the CD Drive
    By Natase in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 10-12-2001, 05:38 PM