A newbie question about USB

A newbie question about USB. I am developing a PC application (not driver) to communicate with a USB

2.0 slave peripheral device. I would like to know, if my application has built a connection and is talking to the USB peripheral, and I disconnect the cable suddenly, will the application be able to identify the event automatically, or it will still stay with the "connection"? Another problem, if I re-connect the usb cable, will the connection be automatically restored? Should I close my application first and then start it again to create a connection with the USB peripheral? Thanks in advance. Johnson
Reply to
Johnson
Loading thread data ...

Hello Johnson,

I am not at all a USB expert. However, my digital camera does exactly that. When I connect it the image transfer routine can automatically fire up (although I disabled that auto-launch feature lately). When I unplug the USB link a window pops up announcing that it lost the link. When I plug it back in the link starts to work again, meaning nothing has crashed and it is able to recognize a connection.

The PC also recognizes what is connected at the other end. For example, if I plug in a memory stick instead of the camera the PC sees that and simply adds it as another drive.

Regards, Joerg

formatting link

Reply to
Joerg

Your application will need to register with windows to receive PnP event (DEVICECHANGE) notifications. When the cable is unplugged, you will receive DEVICEREMOVE events, and when plugged back in, you'll receive a DEVICEARRIVAL event.

However, on removal you'll have to close the connection, and re-open on arrival. It *won't* be 'automatically' restored - there's no concept of maintaining a 'connection' whilst a device is unplugged. Of course, this is an OS implementation issue, and need not have any impact on the application user (they could "see" a persistent connection - there's no need to restart the application).

Regards, Mark

Reply to
Mark McDougall

Thank you Mark.

Reply to
Johnson

Thank you Joerg.

Reply to
Johnson

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.