コード例 #1
0
ファイル: SEARCH.CPP プロジェクト: jimmccurdy/ArchiveGit
void CSearchingDialog::ProcessFindSpeed(void)
{
	CString csFormat;
	CString csStatus;

	StopTimer();				// No more timers while we're in here.

	static long lSpeeds[] =
	{
		1200L,
		2400L,
//		4800L,
//		9600L,
		0L
	};

/*
// Look through the ports.
*/

	CModem Modem;
	m_pModem = &Modem;			// Allow user to cancel
	Modem.WaitForOk(1000, "OK");

	int nResult = Modem.Init(m_nPort, 1200L);	// Be able to talk to all modems we support.
	m_lSpeed = 0;		// No speed found yet.

	if (m_State == Cancelled || m_nPort == -1)
	{
		nResult = GCPP_USER_ABORT;
	}

	if (nResult == GCPP_OK)
	{
		Modem.WaitForOk(1000, "OK");

		long lSpeed;
		for (int nSpeedIndex = 0; (lSpeed = lSpeeds[nSpeedIndex]) != 0L; nSpeedIndex++)
		{
			Modem.GetPort()->SetBaud(lSpeed);

			Util::SafeLoadString(IDS_TESTING_COMMUNICATIONS_PORT, csFormat);
			csStatus.Format(csFormat, m_nPort, lSpeed);
			ShowStatus(csStatus);

			for (int nTry = 0; nTry < MaxOkAttempts; nTry++)
			{
				TRACE("Speed %ld: Try write #%d...\n", lSpeed, nTry);
				Modem.GetPort()->RXFlush();
				nResult = Modem.Write("E1V1Q0", 1);
				if (m_State == Cancelled || m_nPort == -1)
				{
					nResult = GCPP_USER_ABORT;
				}

				if (nResult == GCPP_OK)
				{
					m_lSpeed = lSpeed;			// This one tested OK!
					break;
				}

				if (nResult == GCPP_USER_ABORT)
				{
					break;
				}
			}

			if (m_lSpeed != lSpeed)
			{
			/* The last one failed. Break out now. */
				break;
			}
			// Go to next speed.
		}
	}

	m_pModem = NULL;

//	TRACE("Done with result %d (%d)\n", nResult, m_State);
	if (nResult == GCPP_USER_ABORT || m_State == Cancelled)
	{
	// User abort. Just return.
		return;
	}
	else if (m_lSpeed == 0L)
	{
		Util::SafeLoadString(IDS_CANT_DETERMINE_MODEM_SPEED, csStatus);
		ShowStatus(csStatus);
		SetState(Failed);
	}
	else
	{
		Util::SafeLoadString(IDS_FOUND_MODEM_SPEED, csFormat);
		csStatus.Format(csFormat, m_nPort, m_lSpeed);
		ShowStatus(csStatus);
		SetState(Succeeded);
	}
}
コード例 #2
0
ファイル: SEARCH.CPP プロジェクト: jimmccurdy/ArchiveGit
void CSearchingDialog::ProcessFindModem(void)
{
	CString csFormat;
	CString csStatus;

	StopTimer();				// No more timers while we're in here.

/*
// Look through the ports.
*/

	for (m_nPort = 1; m_nPort < LastPort; m_nPort++)
	{
		CModem Modem;

		m_pModem = &Modem;			// Allow user to cancel
		Modem.WaitForOk(1000, "OK");
		int nResult = Modem.Init(m_nPort, 1200);	// Be able to talk to all modems we support.
		if (m_State == Cancelled || m_nPort == -1)
		{
			nResult = GCPP_USER_ABORT;
		}
		if (nResult == GCPP_OK)
		{
			Util::SafeLoadString(IDS_TRYING_COMMUNICATIONS_PORT, csFormat);
			csStatus.Format(csFormat, m_nPort);
			ShowStatus(csStatus);

			Modem.WaitForOk(1000, "OK");

			for (int nTry = 0; nTry < MaxOkAttempts; nTry++)
			{
				TRACE("Try write #%d...\n", nTry);
				Modem.GetPort()->RXFlush();
				nResult = Modem.Write("E1V1Q0", 1);
				if (m_State == Cancelled || m_nPort == -1)
				{
					nResult = GCPP_USER_ABORT;
				}
				if (nResult == GCPP_OK)
				{
					m_pModem = NULL;

				/* State that we are searching for the port. */

					Util::SafeLoadString(IDS_FOUND_MODEM, csFormat);
					csStatus.Format(csFormat, m_nPort);
					ShowStatus(csStatus);

					SetState(FindSpeed);
					return;
				}

				TRACE("nResult == %d (%d)\n", nResult, m_nPort);
				if (nResult == GCPP_USER_ABORT)
				{
					nResult = GCPP_USER_ABORT;
					break;
				}
			}
		}
		m_pModem = NULL;

		if (nResult == GCPP_USER_ABORT || m_State == Cancelled)
		{
			return;
		}

	// Go to next port.
	}

	Util::SafeLoadString(IDS_CANT_FIND_MODEM, csStatus);
	ShowStatus(csStatus);
	SetState(Failed);
}