我正在使用MFC中的VC ++开发一个ELM327模拟器设备(http://en.wikipedia.org/wiki/ELM327)。它实现了与我的PC和标签的串口通信。我的Pc包含BLuetooth插入其中,设备(标签)正在与我的PC配对。我的程序应该发送收到的响应所需的结果.. 例如: 对于速度,命令:010D应响应输出41 0D 12
我的问题是,在发送命令之后它没有收到来自PC的响应。可能原因是什么......
感谢All
我对ReceiveData的代码就是这样。
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功能如下
// 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;
}