M
mike
I have a communication program that uses 2 threads (recieve and transmit). I
have problems when using a usb to serial cable. If the serial device
attached to the cable abnormally terminates ( loses power), I have problems
when the app tries to close the com port. I have 2 different cables with 2
different problems.
1. This is the worst, when the com is closed, the send thread seems to exit
normally but does not completely clean up. ie the call to
WaitForSingleObject( hcom, INFINITE) never returns. When I unplug the usb
end of the device from the computer, the call returns normally. I've tried
just waiting a certain amount of time and exiting and deleting the thread
but the app is still in a bad state as the next time I try to access the
port the app crashes.
2. The second cable is not as bad in that is let's me close the port however
I cannot reconnect as the port seems to be stuck in some irregular state.
But at least the app doesn't crash.
In both cases I have to unplug the usb and plug it back in to get the port
to work properly again.
I'm using CreateFile() with overlapped io to communicate.
WriteFile() to send (with overlapped io)
ReadFile() to read (with overlapped io)
Using AfxBeginThread() to create the threads with m_bAutoDelete set to
FALSE.
When closing the ports PurgeCom is used to try to clear up data.
I've been using serial communications for a while and haven't had problems
until I encountered these usb to serial cables.
Does anyone know how I can safely clean up the thread instance and if there
is anyway to reset the com device from software?
Thanks
have problems when using a usb to serial cable. If the serial device
attached to the cable abnormally terminates ( loses power), I have problems
when the app tries to close the com port. I have 2 different cables with 2
different problems.
1. This is the worst, when the com is closed, the send thread seems to exit
normally but does not completely clean up. ie the call to
WaitForSingleObject( hcom, INFINITE) never returns. When I unplug the usb
end of the device from the computer, the call returns normally. I've tried
just waiting a certain amount of time and exiting and deleting the thread
but the app is still in a bad state as the next time I try to access the
port the app crashes.
2. The second cable is not as bad in that is let's me close the port however
I cannot reconnect as the port seems to be stuck in some irregular state.
But at least the app doesn't crash.
In both cases I have to unplug the usb and plug it back in to get the port
to work properly again.
I'm using CreateFile() with overlapped io to communicate.
WriteFile() to send (with overlapped io)
ReadFile() to read (with overlapped io)
Using AfxBeginThread() to create the threads with m_bAutoDelete set to
FALSE.
When closing the ports PurgeCom is used to try to clear up data.
I've been using serial communications for a while and haven't had problems
until I encountered these usb to serial cables.
Does anyone know how I can safely clean up the thread instance and if there
is anyway to reset the com device from software?
Thanks