SetOutPut always said I did not open the serial port

Category: VC/MFC -> Foundation Classes Author: cfy_tcjj Date: 2007-09-30 12:03:15
 
cfy_tcjj
2007-09-30 12:03:15
When using the mscomm control serial communication program , call SetOutPut function always say "Operation   valid   only   when   the   port   is   open", that is to say my serial is not open, but obviously has been opened, a single stepping into SetOutPut this line , GetPortOpen () is clearly a ah ! ! ! Everything else looks normal, is not sending data , you really want crazy
LIKAILOVE
2007-09-30 12:18:48
Open serial code is as follows :
void   CFewbuttonDlg :: OnOpen ()  
{
CString   strPara;                                                     // serial port parameters
if (myComm.GetPortOpen ())
    myComm.SetPortOpen (FALSE);
myComm.SetCommPort ( myCom);                                 // designated serial number myCom
strPara = myBaudRate;
strPara + = ", ";
strPara + = myParity;
strPara + = ", 8,1 ";
myComm.SetSettings (strPara);                           // communication parameter setting
myComm.SetInBufferSize (1024);                         // specify the receive buffer size
myComm.SetInBufferCount (0);                             // empty receive buffer
myComm.SetInputMode (1);                                     // setting data acquisition mode
myComm.SetInputLen (0);                                       // set the length
myComm.SetRThreshold each reading (1);                                   // OnComm event is set to receive threshold
if (myComm.GetPortOpen ()!)
    myComm.SetPortOpen (1);                                       // open the serial port
m_open.EnableWindow (false);                       // make open port button does not
m_close.EnableWindow (true);                       // so close serial button to take effect
m_option.EnableWindow (false);                     // the settings button does not
m_exit.EnableWindow (false);                             // make the exit button is invalid
CFewbuttonDlg :: OnChangeEdit2 ();
AfxMessageBox (" serial open success ! ");
}
send data function code is as follows :
void   CFewbuttonDlg :: OnTest ()  
{
UpdateData (TRUE);  
VARIANT   temp;
temp = COleVariant (m_senddata);
                m_mscomm.SetOutput (temp); // send data
}
If SetOutPut this line , and then stepping down to take a step into a wincore.cpp will appear inside the code below
CATCH_ALL (e)
{
CWinThread *   pWinThread   =   AfxGetThread ();
if   (  pWinThread  ! =   NULL  )
{
lResult   =   pWinThread- > ProcessWndProcException (e,   & pThreadState- > m_lastSentM
sg);
TRACE1 (" Warning:   Uncaught   exception   in   WindowProc   (returning  % ld) \. n ",
lResult);
}
else
{
TRACE0 (" Warning:.   Uncaught   exception   in   WindowProc \ n ");
lResult   =   0;
}
DELETE_EXCEPTION (e);
}
END_CATCH_ALL

pThreadState- > m_lastSentMsg   =   oldState;
return   lResult;
} CATCH_ALL (e)
{
CWinThread *   pWinThread   =   AfxGetThread ();
if   (   pWinThread  ! =   NULL  )
{
lResult   =   pWinThread- > ProcessWndProcException (e,   & pThreadState- > m_lastSentM
sg);
TRACE1 (" Warning:   Uncaught   exception   in   WindowProc   (returning  % ld) \ n ",
lResult.);
}
else
{
TRACE0 (" Warning:.   Uncaught   exception   in   WindowProc \ n ");
lResult   =   0;
}
DELETE_EXCEPTION (e );
}
END_CATCH_ALL

pThreadState- > m_lastSentMsg   =   oldState;
return   lResult;
}
if every times mistakes are stepping into here, this is what ah?
nedzhong1
2007-09-30 12:33:23
Nobody knows this problem? Or too basic disdain answer ......
a1746495
2007-09-30 12:41:44
COM port you want to open is occupied by other programs , or Bunsen not exist or bad
jl1156395
2007-09-30 12:52:07
stepping into this line SetOutPut , GetPortOpen () is clearly a ah ! ! ! ?
which SetOutPut

and not myComm.SetPortOpen (1); are myComm.SetPortOpen (true);
kirenty
2007-09-30 12:58:21
There
if (myComm.GetPortOpen ())
    myComm.SetPortOpen (FALSE);
myComm.SetCommPort (myCom);
you have to choose the serial port   myComm.SetCommPort (myCom);
and then determine if (myComm.GetPortOpen ())
    myComm.SetPortOpen (FALSE);? // If you have already opened , first off
or you determine which COM port ah
xutianshu1996
2007-09-30 13:04:32
situation I've encountered a serial bad.
suggest you change the machine to test, or use other methods to ensure that your machine serial is good.
gaoguier111
2007-09-30 13:21:24
Also, your onopen () function has problems
regardless of whether it opens the serial port will to AfxMessageBox (" serial Open success "!); this step , to give you the illusion is the serial port has been opened, and the fact that you did not really open
look
huanjihua
2007-09-30 13:29:16
problem has been solved : When I open the serial port : myComm.SetPortOpen (1);   // open the serial port
                        when sending data :     m_mscomm.SetOutput (temp); // send data
actually not the same object ...... too ignorant of the ......
Oh, it seems that small problems are often easily overlooked ah. Thank you !