1. 加载dll
includes
{
#pragma library("..\dll\osek_tp.dll")
}
2. 设置诊断ID
variables
{
const dword lrrDiag_TxId = 0x791;
const dword lrrDiag_RxId = 0x711;
const byte tpPaddingByte = 0xCC;
byte diagDataBuff[4096];
long receLength;
long tpHandle;
byte gReceUpdateFlag = 0;
mstimer mainTimer;
}
使能诊断连接
tpHandle = CanTpCreateConnection(0);
CanTpSetTxIdentifier(tpHandle, lrrDiag_TxId); //设置ID
CanTpSetRxIdentifier(tpHandle, lrrDiag_RxId);
OSEKTL_SetRxId(lrrDiag_RxId);
CanTpSetPadding(tpHandle, tpPaddingByte);//设置填充位
gReceUpdateFlag =0;
receLength =0;
setTimer(mainTimer,10);
3. 实现回调函数
OSEKTL_DataInd( long count)
{
OSEKTL_GetRxData( diagDataBuff, elcount( diagDataBuff));
receLength = count;
}
void CanTp_ReceptionInd( long connHandle, byte data[])
{
long byteCnt=0;
for (byteCnt=0; byteCnt<receLength; byteCnt++)
{
write("Received Data[%d] is %x", byteCnt, diagDataBuff[byteCnt]);
}
gReceUpdateFlag = 1;
}
4. 发送诊断报文
byte rspData[6] = {0x50, 0x03, 0x00, 0x32, 0x01, 0xF4};
CanTpSendData(handle, rspData, elcount(rspData));