📄 status.c
字号:
PARAMETERS:
dwModemStatus - current modem status flag
COMMENTS: Checks each button according to the state
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
void ReportModemStatus(DWORD dwModemStatus)
{
BOOL fCTS, fDSR, fRING, fRLSD;
BOOL fStat[4];
int i;
fCTS = fStat[0] = MS_CTS_ON & dwModemStatus;
fDSR = fStat[1] = MS_DSR_ON & dwModemStatus;
fRING = fStat[2] = MS_RING_ON & dwModemStatus;
fRLSD = fStat[3] = MS_RLSD_ON & dwModemStatus;
for (i = IDC_STATCTS; i <= IDC_STATRLSD; i++)
CheckDlgButton(ghWndStatusDlg, i, fStat[i-IDC_STATCTS] ? 1 : 0);
return;
}
/*-----------------------------------------------------------------------------
FUNCTION: CheckModemStatus(BOOL)
PURPOSE: Check new status and possibly report it
PARAMETERS:
bUpdateNow - if TRUE, update should be done
if FALSE, update is done only if status is different
COMMENTS: Reports status if bUpdateNow is true or
new status is different from old status
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
void CheckModemStatus( BOOL bUpdateNow )
{
//
// dwOldStatus needs to be static so that it is maintained
// between function calls by the same thread.
// It also needs to be __declspec(thread) so that it is
// initialized when a new thread is created.
//
__declspec(thread) static DWORD dwOldStatus = 0;
DWORD dwNewModemStatus;
if (!GetCommModemStatus(COMDEV(TTYInfo), &dwNewModemStatus))
ErrorReporter("GetCommModemStatus");
//
// Report status if bUpdateNow is true or status has changed
//
if (bUpdateNow || (dwNewModemStatus != dwOldStatus)) {
ReportModemStatus(dwNewModemStatus);
dwOldStatus = dwNewModemStatus;
}
return;
}
/*-----------------------------------------------------------------------------
FUNCTION: ReportComStat( COMSTAT )
PURPOSE: Update status dialog controls based on the COMSTAT structure
PARAMETERS:
ComStat - comstat structure used to update comm stat controls.
HISTORY: Date: Author: Comment:
12/01/95 AllenD Wrote it
12/18/95 AllenD Modified it
-----------------------------------------------------------------------------*/
void ReportComStat(COMSTAT ComStat)
{
CheckDlgButton(ghWndStatusDlg, IDC_CTSHOLDCHK, ComStat.fCtsHold);
CheckDlgButton(ghWndStatusDlg, IDC_DSRHOLDCHK, ComStat.fDsrHold);
CheckDlgButton(ghWndStatusDlg, IDC_RLSDHOLDCHK, ComStat.fRlsdHold);
CheckDlgButton(ghWndStatusDlg, IDC_XOFFHOLDCHK, ComStat.fXoffHold);
CheckDlgButton(ghWndStatusDlg, IDC_XOFFSENTCHK, ComStat.fXoffSent);
CheckDlgButton(ghWndStatusDlg, IDC_EOFSENTCHK, ComStat.fEof);
CheckDlgButton(ghWndStatusDlg, IDC_TXIMCHK, ComStat.fTxim);
SetDlgItemInt(ghWndStatusDlg, IDC_TXCHAREDIT, ComStat.cbOutQue, FALSE);
SetDlgItemInt(ghWndStatusDlg, IDC_RXCHAREDIT, ComStat.cbInQue, FALSE);
return;
}
/*-----------------------------------------------------------------------------
FUNCTION: CheckComStat(BOOL)
PURPOSE: Calls ClearCommError and reports the results.
PARAMETERS:
bUpdateNow - If TRUE, then ReportComStat is called with new results.
if FALSE, then ReportComStat is called only if
new results differ from old.
COMMENTS: Called when the ReaderAndStatusProc times out after waiting on
its event handles. Also called from ReportStatusEvent.
HISTORY: Date: Author: Comment:
12/18/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
void CheckComStat(BOOL bUpdateNow)
{
COMSTAT ComStatNew;
DWORD dwErrors;
__declspec(thread) static COMSTAT ComStatOld = {0};
__declspec(thread) static DWORD dwErrorsOld = 0;
BOOL bReport = bUpdateNow;
if (!ClearCommError(COMDEV(TTYInfo), &dwErrors, &ComStatNew))
ErrorReporter("ClearCommError");
if (dwErrors != dwErrorsOld) {
bReport = TRUE;
dwErrorsOld = dwErrors;
}
if (memcmp(&ComStatOld, &ComStatNew, sizeof(COMSTAT))) {
bReport = TRUE;
ComStatOld = ComStatNew;
}
if (bReport)
ReportComStat(ComStatNew);
ComStatOld = ComStatNew;
return;
}
/*-----------------------------------------------------------------------------
FUNCTION: ReportCommError
PURPOSE: Calls ClearCommError and reports the results
COMMENTS: This function is called if EV_ERR occurs and is called
when the ReaderAndStatusProc times out after waiting on
its event handles.
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
void ReportCommError()
{
COMSTAT comStat;
DWORD dwErrors;
BOOL fOOP, fOVERRUN, fPTO, fRXOVER, fRXPARITY, fTXFULL;
BOOL fBREAK, fDNS, fFRAME, fIOE, fMODE;
char szMessage[100];
//
// Get and clear current errors on the port
//
if (!ClearCommError(COMDEV(TTYInfo), &dwErrors, &comStat))
ErrorReporter("ClearCommError");
//
// get error flags
//
fDNS = dwErrors & CE_DNS;
fIOE = dwErrors & CE_IOE;
fOOP = dwErrors & CE_OOP;
fPTO = dwErrors & CE_PTO;
fMODE = dwErrors & CE_MODE;
fBREAK = dwErrors & CE_BREAK;
fFRAME = dwErrors & CE_FRAME;
fRXOVER = dwErrors & CE_RXOVER;
fTXFULL = dwErrors & CE_TXFULL;
fOVERRUN = dwErrors & CE_OVERRUN;
fRXPARITY = dwErrors & CE_RXPARITY;
//
// create error string
//
strcpy(szMessage, "ERROR: ");
strcat(szMessage, fDNS ? "DNS " : "");
strcat(szMessage, fIOE ? "IOE " : "");
strcat(szMessage, fOOP ? "OOP " : "");
strcat(szMessage, fPTO ? "PTO " : "");
strcat(szMessage, fMODE ? "MODE " : "");
strcat(szMessage, fBREAK ? "BREAK " : "");
strcat(szMessage, fFRAME ? "FRAME " : "");
strcat(szMessage, fRXOVER ? "RXOVER " : "");
strcat(szMessage, fTXFULL ? "TXFULL " : "");
strcat(szMessage, fOVERRUN ? "OVERRUN " : "");
strcat(szMessage, fRXPARITY ? "RXPARITY " : "");
strcat(szMessage, "\r\n");
//
// if there really were errors, then report them
//
if (dwErrors)
UpdateStatus(szMessage);
//
// Report info from the COMSTAT structure
//
ReportComStat(comStat);
//
// Show COMSTAT structure with the error indicator
//
if (comStat.fCtsHold)
UpdateStatus("Tx waiting for CTS signal.\r\n");
if (comStat.fDsrHold)
UpdateStatus("Tx waiting for DSR signal.\r\n");
if (comStat.fRlsdHold)
UpdateStatus("Tx waiting for RLSD signal.\r\n");
if (comStat.fXoffHold)
UpdateStatus("Tx waiting, XOFF char rec'd.\r\n");
if (comStat.fXoffSent)
UpdateStatus("Tx waiting, XOFF char sent.\r\n");
if (comStat.fEof)
UpdateStatus("EOF character received.\r\n");
if (comStat.fTxim)
UpdateStatus("Character waiting for Tx.\r\n");
if (comStat.cbInQue) {
wsprintf(szMessage, "%d bytes in input buffer.\r\n", comStat.cbInQue);
UpdateStatus(szMessage);
}
if (comStat.cbOutQue) {
wsprintf(szMessage, "%d bytes in output buffer.\r\n", comStat.cbOutQue);
UpdateStatus(szMessage);
}
return;
}
/*-----------------------------------------------------------------------------
FUNCTION: ReportStatusEvent(DWORD)
PURPOSE: Report a comm status event
PARAMETERS:
dwStatus - status event flag from WaitCommEvent
COMMENTS: This is different than line status (aka Modem Status).
NOTE: EV_RING isn't detected on Windows 95. This is a known problem.
A workaround to the problem is to rely on GetCommModemStatus, or
set the modem to send a "RING" and have the app detect it.
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
/*-----------------------------------------------------------------------------*/
void ReportStatusEvent(DWORD dwStatus)
{
BOOL fRING, fRLSD, fRXCHAR, fRXFLAG, fTXEMPTY;
BOOL fBREAK, fCTS, fDSR, fERR;
char szMessage[70];
//
// Get status event flags.
//
fCTS = EV_CTS & dwStatus;
fDSR = EV_DSR & dwStatus;
fERR = EV_ERR & dwStatus;
fRING = EV_RING & dwStatus;
fRLSD = EV_RLSD & dwStatus;
fBREAK = EV_BREAK & dwStatus;
fRXCHAR = EV_RXCHAR & dwStatus;
fRXFLAG = EV_RXFLAG & dwStatus;
fTXEMPTY = EV_TXEMPTY & dwStatus;
/*
Construct status message indicating the
status event flags that are set.
*/
strcpy(szMessage, "EVENT: ");
strcat(szMessage, fCTS ? "CTS " : "");
strcat(szMessage, fDSR ? "DSR " : "");
strcat(szMessage, fERR ? "ERR " : "");
strcat(szMessage, fRING ? "RING " : "");
strcat(szMessage, fRLSD ? "RLSD " : "");
strcat(szMessage, fBREAK ? "BREAK " : "");
strcat(szMessage, fRXFLAG ? "RXFLAG " : "");
strcat(szMessage, fRXCHAR ? "RXCHAR " : "");
strcat(szMessage, fTXEMPTY ? "TXEMPTY " : "");
/*
If dwStatus == NULL, then no status event flags are set.
This happens when the event flag is changed with SetCommMask.
*/
if (dwStatus == 0x0000)
strcat(szMessage, "NULL");
strcat(szMessage, "\r\n");
//
// Queue the status message for the status control
//
UpdateStatus(szMessage);
/*
If an error flag is set in the event flag, then
report the error with the status message
If not, then just report the comm status.
*/
if (fERR)
ReportCommError();
/*
Might as well check the modem status and comm status now since
the event may have been caused by a change in line status.
Line status is indicated by the CheckModemStatus function.
*/
CheckModemStatus( FALSE );
/*
Since line status can affect sending/receiving when
hardware flow-control is used, ReportComStat should
be called to show comm status. This is called only if no error
was reported in the event flag. If an error was reported, then
ReportCommError was called above and CheckComStat was already called
in that function.
*/
if (!fERR)
CheckComStat( FALSE );
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -