Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

USB low-full-high speed peripherals Forum Discussions

JeHu_3414236
Level 5
Level 5
10 likes received First like received

If I open the USB Serial COM port in my terminal program and disconnect the USB, the USB Serial Port device will remain in the Windows Device Manager and the terminal program will not have any indication that the device is disconnected.  If I close the terminal program, then the USB Serial Port is removed from Device Manager.  This only happens with the Cypress driver.  I am using version 3.13.0.59.  If I change the VID to some unrecognized value in Windows and let it load the default Windows driver, I don't see this problem.  Once I disconnect USB, the port is gone from Device Manager and my terminal program shows an error.  I am using Windows 10 64-bit.  Does anyone know why this happens?  I prefer the behavior of the Windows driver.  Can I change something on the CYUSBS234 config or Cypress driver to make it behave like the Windows driver?

0 Likes
1 Solution
Keerthy
Moderator
Moderator
Moderator
50 solutions authored 25 solutions authored 10 solutions authored

Hi,

You may do this by using the "ManagementEventWatcher" class. It subscribes to temporary event notifications based on a specified event query. You can also register a callback function which get triggered when an event happens. EventArrivedEventHandler can be used for the same. Please find the example code snippet below:

string m_deviceRemovalQuery = "SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 3";

m_removalEvtWatcher = new ManagementEventWatcher(m_deviceRemovalQuery);

m_removalEvtWatcher.EventArrived += new EventArrivedEventHandler(m_removalEvtWatcher_EventArrived);

m_removalEvtWatcher.Start();

void m_removalEvtWatcher_EventArrived(object sender, EventArrivedEventArgs e)

{

}

Regards,

Keerthy

View solution in original post

0 Likes
3 Replies
SrinathS_16
Moderator
Moderator
Moderator
250 solutions authored 100 solutions authored 100 likes received

Hello,

This is a feature of the Cypress driver called port persistence. The terminal application using the COM port can continue accessing the device even if the device is disconnected and reconnected. The COM port is not lost from the device manager if the application has the device opened.

Best regards,

Srinath S

0 Likes

Thanks.  How do I detect the device is disconnected in my application?  I have a test app that calls SetCommMask(hComm, EV_RXCHAR); then WaitCommEvent().  After the device is disconnected, WaitCommEvent() does not return any error.  Using the Windows driver, it will return an error so I know to alert the user or do some other cleanup code.

0 Likes
Keerthy
Moderator
Moderator
Moderator
50 solutions authored 25 solutions authored 10 solutions authored

Hi,

You may do this by using the "ManagementEventWatcher" class. It subscribes to temporary event notifications based on a specified event query. You can also register a callback function which get triggered when an event happens. EventArrivedEventHandler can be used for the same. Please find the example code snippet below:

string m_deviceRemovalQuery = "SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 3";

m_removalEvtWatcher = new ManagementEventWatcher(m_deviceRemovalQuery);

m_removalEvtWatcher.EventArrived += new EventArrivedEventHandler(m_removalEvtWatcher_EventArrived);

m_removalEvtWatcher.Start();

void m_removalEvtWatcher_EventArrived(object sender, EventArrivedEventArgs e)

{

}

Regards,

Keerthy

0 Likes