0

我正在使用 MFC 中的 VC++ 开发 ELM327 模拟器设备(http://en.wikipedia.org/wiki/ELM327)。它实现了与我的 PC 和选项卡的串行端口通信。我的 PC 包含插入它的蓝牙和设备(选项卡)正在与我的 PC 配对。我的程序应该发送接收到的响应所需的结果。例如:对于速度,命令:010D 应该响应输出 41 0D 12

我的问题是它在发送命令后没有收到来自 PC 的响应..可能是什么原因..

谢谢大家

我的 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;

}

4

0 回答 0