Category : C Source Code
Archive   : WINKERM.ZIP
Filename : KERMCOMM.C

 
Output of file : KERMCOMM.C contained in archive : WINKERM.ZIP
/*******************************************************************************
** **
** Kermit for Microsoft Windows **
** ---------------------------- **
** KERMCOMM.C **
** **
** This module contains the functions to interface with the Windows **
** interupt driven communications driver. **
** **
*******************************************************************************/

// INCLUDES -------------------------------------------------------------------

#include "kermit.h"

//-----------------------------------------------------------------------------
VOID NEAR DebugDCB(DCB FAR *lpDCB)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
char MsgStr [512];

sprintf(MsgStr, "BaudRate=%i, "
"ByteSize=%i, "
"Parity=%i, "
"StopBits=%i, "
"RlsTimeout=%i, "
"CtsTimeout=%i, "
"DsrTimeout=%i, "
"fBinary=%i, "
"fRtsDisable=%i, "
"fParity=%i, "
"fOutxCtsFlow=%i, "
"fOutxDsrFlow=%i, "
"fDtrDisable=%i, "
"fOutX=%i, "
"fInX=%i, "
"PeChar=%i, "
"fNull=%i, "
"fChEvt=%i, "
"fDtrflow=%i, "
"fRtsflow=%i, "
"XonChar=%i, "
"XoffChar=%i, "
"XonLim=%i, "
"XoffLim=%i, "
"PeChar=%i, "
"EvtChar=%i, "
"EofChar=%i, "
"TxDelay=%i",
lpDCB->BaudRate,
lpDCB->ByteSize,
lpDCB->Parity,
lpDCB->StopBits,
lpDCB->RlsTimeout,
lpDCB->CtsTimeout,
lpDCB->DsrTimeout,
lpDCB->fBinary,
lpDCB->fRtsDisable,
lpDCB->fParity,
lpDCB->fOutxCtsFlow,
lpDCB->fOutxDsrFlow,
lpDCB->fDtrDisable,
lpDCB->fOutX,
lpDCB->fInX,
lpDCB->PeChar,
lpDCB->fNull,
lpDCB->fChEvt,
lpDCB->fDtrflow,
lpDCB->fRtsflow,
lpDCB->XonChar,
lpDCB->XoffChar,
lpDCB->XonLim,
lpDCB->XoffLim,
lpDCB->PeChar,
lpDCB->EvtChar,
lpDCB->EofChar,
lpDCB->TxDelay);
MessageBox(hAppWnd, MsgStr, "Debug: Communications DCB", MB_OK);
}

//-----------------------------------------------------------------------------
BOOL SetupComm(VOID)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
int Result;
DCB ComDCB;

GetCommState(nCid, &ComDCB);

ComDCB.BaudRate = CommSet.BaudRate;
ComDCB.ByteSize = (BYTE)CommSet.DataBits;
ComDCB.Parity = (BYTE)CommSet.Parity;
ComDCB.StopBits = (BYTE)CommSet.StopBits;
ComDCB.fOutX = (BYTE)ComDCB.fInX = (BYTE)CommSet.FlowControl;
ComDCB.fOutxCtsFlow = (BYTE)ComDCB.fRtsflow = (BYTE)CommSet.HandShake;
ComDCB.XonChar = 17;
ComDCB.XoffChar = 19;

Result = SetCommState(&ComDCB);

if (Result < 0) {
KermitFmtMsgBox(MB_OK | MB_ICONASTERISK,
"Error %i setting comm state", Result);
DebugDCB(&ComDCB);
return(FALSE);
}

return(TRUE);
}

//-----------------------------------------------------------------------------
BOOL Disconnect(BOOL bVerify)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
int Result;

if (bKermit && !AbortXfer(TRUE))
return(FALSE);

if (bVerify) {
MessageBeep(0);
if (KermitFmtMsgBox(MB_OKCANCEL | MB_ICONQUESTION,
"Break Kermit Connection") != IDD_OK)
return(FALSE);
}

if ((Result = (CloseComm(nCid))) < 0) {
MessageBeep(0);
KermitFmtMsgBox(MB_OK | MB_ICONEXCLAMATION,
"Error %i closing comm port", Result);
return(FALSE);
}

bConnected = FALSE;
CheckMenuItem(hAppMenu, IDM_CONNECT, MF_UNCHECKED);
EnableCommCommands(MF_GRAYED);
SetKermitCommands("StartMenu", MF_GRAYED);
CloseTerm();
return(TRUE);
}

//-----------------------------------------------------------------------------
BOOL Connect(VOID)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
int Result;
static char PortStr[] = "COM?";

PortStr[3] = (char)('1' + CommSet.CommPort);
if ((Result = OpenComm(PortStr, RXBUFSIZE, TXBUFSIZE)) < 0) {
KermitFmtMsgBox(MB_OK | MB_ICONEXCLAMATION,
"Error %i opening %s:", Result);
return(FALSE);
}

nCid = Result;
bConnected = TRUE;

if (!SetupComm()) {
Disconnect(FALSE);
return(FALSE);
}

CheckMenuItem(hAppMenu, IDM_CONNECT, MF_CHECKED);
EnableCommCommands(MF_ENABLED);
SetKermitCommands("StartMenu", MF_ENABLED);
OpenTerm();
return(TRUE);
}

//-----------------------------------------------------------------------------
VOID DebugComm(VOID)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
DCB dsDCB;

GetCommState(nCid, &dsDCB);
DebugDCB(&dsDCB);
}

//-----------------------------------------------------------------------------
int ReadCommStr(LPSTR lpsDest, int nMaxChars, BOOL bShowErr)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
int nLength;
int nComErr;

while (nComErr = GetCommError(nCid, NULL))
if (bShowErr)
WriteTermFmt("", nComErr);

if ((nLength = ReadComm(nCid, lpsDest, nMaxChars)) < 0)
nLength = -nLength;

return(nLength);
}

//-----------------------------------------------------------------------------
VOID WriteCommChar(char cCommChar)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
WriteComm(nCid, &cCommChar, 1);
}

//-----------------------------------------------------------------------------
VOID WriteCommStr(LPSTR lpsCommStr, int nStrLen)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
WriteComm(nCid, lpsCommStr, nStrLen);
}

//-----------------------------------------------------------------------------
VOID WriteCommFmt(PSTR pszFmt, ...)

// Description of what function does.

// Param(s): x...............Description.

// Returns: Result description.

{
char sWork[128];
va_list pArg;
int nLen;

va_start(pArg, pszFmt);
nLen = vsprintf(sWork, pszFmt, pArg);
va_end(pArg);

WriteCommStr(sWork, nLen);
}


  3 Responses to “Category : C Source Code
Archive   : WINKERM.ZIP
Filename : KERMCOMM.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/