Programmatically Interrupting Serial I/O when USB Device is Removed - C++ -


i have application wherein serial i/o conducted attached usb device via virtual com port. when surprise removal of device detected, best way stop serial i/o. should close port? or, should there global variable, maintained indicate presence of device, should checked in each serial i/o function prior attempting transmit/receive data? or, should combination of two, or else? thanks.

i'm assuming running windows. depends on how have designed communication flow.

i have baseport object have derived comport object (and many other communication objects). comport object creates 1 txthread , rxthread class. these threads waiting "overlap" signal read or write operation finished waitformultipleobjects().

the txthreads goes sleep if there nothing , wakes txwrite function (the data between main process , thread goes through trhead safe fifo buffer).

in case need wait event signal port has closed, can cancel pending operations , exit (the treads exits , gets deleted).

to detect if usb port connectd/disconneted listen windows message device_change. if port disconnected set event , waits threads exit before port class deletes , closes port.

i have found approach reliable , safe. it's core in communication platform designed on 8 years ago , still kicking.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -