Exemple #1
0
void 
CConnection::OnEvent(UINT uEvent)
{
	BrowserManagerLock browserManager;
	CBrowserMessageWindow* window = browserManager->FindBrowserMessageWindow(m_Parent->m_Parent->GetBrowserId());
	if (!window) return;

	switch (uEvent)
	{
		case EVT_CONSUCCESS:
			TRACE_I( _T("Connection Established\r\n") );
			break;
		case EVT_CONFAILURE:
			TRACE_I( _T("Connection Failed\r\n") );
			window->PostMessage(BMM_REQUEST_DISCONNECTED_NOTIFY, 0, 0);
			CloseComm();
			m_Parent->m_Connected = false;
			break;
		case EVT_CONDROP:
			TRACE_I( _T("Connection Abandonned\r\n") );
			window->PostMessage(BMM_REQUEST_DISCONNECTED_NOTIFY, 0, 0);
			CloseComm();
			m_Parent->m_Connected = false;
			break;
		case EVT_ZEROLENGTH:
			TRACE_I( _T("Zero Length Message\r\n") );
			break;
		default:
			TRACE_W(_T("Unknown Socket event\n"));
			break;
	}
}
Exemple #2
0
BOOL CRFIDprototypeApp::CheckGSM()
{
	int nRate;
	nRate = _ttoi(m_strRate);

	while (!::OpenComm(m_strPort, nRate))
	{
		CString strError;
		strError.Format(L"无法打开端口%s! 现在设置吗?", m_strPort);
		if (AfxMessageBox(strError, MB_YESNO) == IDNO) return FALSE;

		CSetting dlg;
		dlg.m_strPort = m_strPort;
		dlg.m_strRate = m_strRate;
		dlg.m_strSmsc = m_strSmsc;
		if (dlg.DoModal() == IDOK)
		{
			m_strPort = dlg.m_strPort;
			m_strRate = dlg.m_strRate;
			m_strSmsc = dlg.m_strSmsc;
		
		}
		else
		{
			return FALSE;
		}
	}

	if (!gsmInit())
	{
		CString strError;
		strError.Format(L"端口%s上没有发现MODEM!", m_strPort);
		AfxMessageBox(strError, MB_OK);
		CloseComm();
		return FALSE;
	}

	if (m_strSmsc.IsEmpty())
	{
		AfxMessageBox(L"请设置SMSC!");
		 
 		CSetting dlg;
 		dlg.m_strPort = m_strPort;
 		dlg.m_strRate = m_strRate;
 		dlg.m_strSmsc = m_strSmsc;
 		if (dlg.DoModal() == IDOK)
 		{
 			m_strPort = dlg.m_strPort;
 			m_strRate = dlg.m_strRate;
 			m_strSmsc = dlg.m_strSmsc;
 		}
 		else
 		{
			CloseComm();
 			return FALSE;
 		}
	}

	return TRUE;
}
Exemple #3
0
int far pascal zCloseComm( int pp1 )
{
    int r;

    SaveRegs();
    /*
    ** Log IN Parameters (No Create/Destroy Checking Yet!)
    */
    LogIn( (LPSTR)"APICALL:CloseComm int+",
        pp1 );

    /*
    ** Call the API!
    */
    RestoreRegs();
    GrovelDS();
    r = CloseComm(pp1);
    UnGrovelDS();
    SaveRegs();
    /*
    ** Log Return Code & OUT Parameters (No Create/Destroy Checking Yet!)
    */
    LogOut( (LPSTR)"APIRET:CloseComm int++",
        r, (short)0 );

    RestoreRegs();
    return( r );
}
///////////////////////////////////////////////////////////////////////////////
// StopComm
///////////////////////////////////////////////////////////////////////////////
// DESCRIPTION:
//      Close Socket and Stop Communication thread
// PARAMETERS:
//      None
///////////////////////////////////////////////////////////////////////////////
void CSocketComm::StopComm()
{
    // Close Socket
    if (IsOpen())
    {
        CloseComm();
    }

    // Kill Thread
    if (IsStart())
    {
        SleepEx(DEFAULT_TIMEOUT, TRUE);
        if (WaitForSingleObject(m_hThread, 1000L) == WAIT_TIMEOUT)
            TerminateThread(m_hThread, 1L);
        CloseHandle(m_hThread);
        m_hThread = NULL;
    }

    // Clear Address list
    if (!m_AddrList.empty())
    {
        m_AddrList.clear();
    }

    // Destroy Synchronization objects
    if (NULL != m_hMutex)
    {
        CloseHandle( m_hMutex );
        m_hMutex = NULL;
    }

}
Exemple #5
0
void  TSerialConnection :: Close  ( void )
   {
	TConnection :: Close ( ) ;

	CloseComm  ( DeviceId ) ;
	CharactersReceived = 0 ;
	Origin		   = 0 ;
	DeviceId	   = -1 ;
    }
Exemple #6
0
//-------------------------------------------------------------------
//  Description:
//     Closes the connection to the port.
//
//  portnum    - number 0 to MAX_PORTNUM-1.  This number is provided to
//                 indicate the symbolic port number.
//
//     Returns FALSE if unsuccessful and TRUE if successful.
//
void CloseCOM(int portnum)
{
   if (ComID[portnum] >= 0)
   {
      // Flush and close current port
      FlushComm(ComID[portnum],0);
      FlushComm(ComID[portnum],1);
      // close the port
      CloseComm(ComID[portnum]);
      // reset port and return
      ComID[portnum] = -1;
   }
}
Exemple #7
0
void 
CReconnectListener::OnEvent(UINT uEvent)
{
	switch (uEvent)
	{
		case EVT_CONSUCCESS:
			TRACE_I( _T("Reconnection request") );
			m_Parent->Reconnect();
			break;
		case EVT_CONFAILURE:
			CloseComm();
			m_Parent->RequestStartingReconnectListener();
			break;
		case EVT_CONDROP:
			CloseComm();
			m_Parent->RequestStartingReconnectListener();
			break;
		case EVT_ZEROLENGTH:
			break;
		default:
			TRACE_W(_T("Unknown Socket event\n"));
			break;
	}
}
Exemple #8
0
int XTTY::Connect(BOOL fConnect)
{
	if (fConnect) {		// オンラインにする
		if (m_fConnect)		// 既にオンライン?
			return 0;	// 何もせずに終わる

		m_idComDev = OpenComm("COM2", 1024, 128);
		if (m_idComDev < 0) {	// オープンに失敗?
			OpenComm_Error(m_idComDev);
			return -1;
		}

		DCB dcb;
		GetCommState(m_idComDev, &dcb);
		
		dcb.BaudRate = 57600;
		dcb.ByteSize = 8;
		dcb.Parity = NOPARITY;
		dcb.StopBits = ONESTOPBIT;

		SetCommState(&dcb);
		GetCommState(m_idComDev, &dcb);
		EnableCommNotification(m_idComDev, m_hwnd, 80, -1);
		EscapeCommFunction(m_idComDev, SETDTR);
		m_fConnect = TRUE;
	} else {		// オフラインにする
		if (!m_fConnect)	// 既にオフライン?
			return 0;	// 何もせずに終わる

		EscapeCommFunction(m_idComDev, CLRDTR);
		CloseComm(m_idComDev);
		m_fConnect = FALSE;
	}

	return 0;
}
Exemple #9
0
BOOL CRFIDprototypeApp::CloseGSM()
{
	gsmDeinit();
	CloseComm();
	return TRUE;
}