Home > Software engineering >  SerialPort PL2303
SerialPort PL2303

Time:10-13

This class in opening a serial port PL2303, repeated open, there will be a serial port was taken to see the next CreatFile is not successful,
Open the can again again,
In the do
{
SetEvent (m_hShutdownEvent);
} while (m_bThreadAlive);
TRACE (" Thread ended \ n ");
//AfxMessageBox (L "ASGBRWHG")
Here with a play can repeat to open the window, why is this m_bThreadAlive need to delay, every brother please help solve

CodePudding user response:

The closure is solved thoroughly ClosePort with the if ((m_Thread!=(CWinThread *) 0 XCDCDCDCD) & amp; & (m_Thread!=NULL))
{
The TerminateThread (m_Thread - & gt; M_hThread, NULL);
M_Thread - & gt; ExitInstance ();
M_Thread - & gt; The Delete ();
} this code

CodePudding user response:

0 XCDCDCDCD said uninitialized variables, VS you have major issues, this code under the Release has a problem,

CodePudding user response:

M_Thread=NULL;//initialize the first
.
The WaitForSingleObject (m_Thread, 2000);//waiting thread end

CodePudding user response:

I have found is m_Com StartMonitoring (); Monitoring thread, the blocked this sentence, you can repeat to open the serial port
///if the thread exists, then turn off the process

If (m_bThreadAlive)
{
Do
{
SetEvent (m_hShutdownEvent);
} while (m_bThreadAlive);
TRACE (" Thread ended \ n ");
//AfxMessageBox (L "ASGBRWHG");
}

Be m_hShutdownEvent didn't finish, CreatFile (), leading to failed to create a handle, want to know the reason

CodePudding user response:

On other serial chip such as duplicate Ch340 using PC open the serial port is not open serial port interval failed to create a handle
  • Related