Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

I am developing a ELM327 Simulator device(http://en.wikipedia.org/wiki/ELM327) using VC++ in MFC..It implements Serial port communication with my PC and tab..My PC contains BLuetooth plugged into it and the device (tab) is being paired with my PC..My program should send the required result for the received response..
Eg:
For Speed, Command : 010D should respond with output 41 0D 12

My problem is that device is not receiving response from PC after sending command..
What could probably the reason be..

OnReceiveData function in my program is as follows:

C++
LRESULT CELM327SimDlg::OnReceiveData(WPARAM wParam, LPARAM lParam)
{
	int iLen = (int)wParam;   // iLen has value 5
	LPBYTE lpDataBuffer = (LPBYTE)lParam;  //lpDataBuffer has value AT Z

	// Parse and handle the received here.
	WORD wCmd = m_ELM327Cmd.ParseAndGetCmd(lpDataBuffer, iLen);  //Goes to ParseAndGetCmd function
	if( ELM327_CMD_SUP_CMD == wCmd )      //If condition fails program control goes to else part 
	{
		for( int i = 0; i < 3; i++ )
		{
			m_objSerialPort.SendData(m_ELM327Cmd.GetSupBuf(i), m_ELM327Cmd.GetSupBufLen());
		}
	}
	else
	{

		DWORD dwData = 0;

		switch(wCmd)                   // Not getting to switch block
		{
		case ELM327_CMD_RPM:
			dwData = m_ctrlRPMSlider.GetPos();
			break;

		case ELM327_CMD_SPEED:
			dwData = m_ctrlSpeedSlider.GetPos();
			break;

		case ELM327_CMD_MAF:
			dwData = m_ctrlMAFSlider.GetPos();
			break;

		case ELM327_CMD_FUELLVL:
			dwData = m_ctrlFuelSlider.GetPos();
			break;

		default:
			break;
		}				

		if(m_ELM327Cmd.SetResponse(wCmd, dwData))    //Program calling SetResponse function. 
		{
			m_objSerialPort.SendData(m_ELM327Cmd.GetResponseBuf(), m_ELM327Cmd.GetResponseLen());
		}
	}

	if( NULL != lpDataBuffer )
	{
		delete [] lpDataBuffer;
		lpDataBuffer = NULL;
	}

	return 0;
}


SendData function

<pre lang="c++">
// Send data to comport
void CSerialPort::SendData(LPBYTE lpBuffer, DWORD dwBytes)
{
	if(m_bConnected)
	{
		if( NULL == lpBuffer || dwBytes == 0 )
		{
			return;
		}

		LPBYTE lpDataBuffer = new BYTE[dwBytes];
		if( NULL == lpDataBuffer )
		{
			return;
		}

		CopyMemory(lpDataBuffer, lpBuffer, dwBytes );
		::PostMessage( m_hWnd, UWM_SEND_DATA, (WPARAM)dwBytes, (LPARAM)lpDataBuffer );
	}

	return;
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900