Чтобы указать на это, можно найти драйверы, а также API и некоторые образцы. по этой ссылке. После установки всего, вы можете перейти к файлам программы OpenECU и там вы найдете папку с образцами.
Это первая версия программы:
Код: Выделить всё
#include
#include
#include
#include
#include
#include "J2534.h"
J2534 j2534;
void reportJ2534Error()
{
char err[512];
j2534.PassThruGetLastError(err);
printf("J2534 error [%s].\n", err);
}
int _tmain(int argc, _TCHAR* argv[])
{
unsigned long devID;
unsigned long chanID;
// Initialization
if (!j2534.init())
{
printf("Can't connect to J2534 DLL.\n");
return 0;
}
if (j2534.PassThruOpen(NULL, &devID))
{
reportJ2534Error();
return 0;
}
if (j2534.PassThruConnect(devID, CAN, 0, 500000, &chanID)) // 500000 is the baud rate
{
reportJ2534Error();
return 0;
}
// Send RPM request
PASSTHRU_MSG txmsg;
txmsg.ProtocolID = CAN;
txmsg.RxStatus = 0;
txmsg.TxFlags = 0;
txmsg.DataSize = 8;
txmsg.Data[0] = 0x02;
txmsg.Data[1] = 0x71; // CAN ID 714 high byte
txmsg.Data[2] = 0x4; // CAN ID 714 low byte
txmsg.Data[3] = 0x22;
txmsg.Data[4] = 0x22;
txmsg.Data[5] = 0xD1;
txmsg.Data[6] = 0x55;
txmsg.Data[7] = 0x55;
unsigned long numTxMsg = 1;
if (j2534.PassThruWriteMsgs(chanID, &txmsg, &numTxMsg, 1000))
{
reportJ2534Error();
}
else
{
printf("RPM request sent to instrument cluster.\n");
}
Sleep(2000); // Wait for 2 seconds instead of 500 ms
// Read RPM response
PASSTHRU_MSG rxmsg;
unsigned long numRxMsg = 1;
long status = j2534.PassThruReadMsgs(chanID, &rxmsg, &numRxMsg, 1000);
if (status == 0 && numRxMsg > 0)
{
// Check if it's an RPM response
if(rxmsg.Data[1] == 0x62 && rxmsg.Data[2] == 0x22 && rxmsg.Data[3] == 0xD1)
{
unsigned int rpmValue = (rxmsg.Data[4] 0) {
printf("Received response: ");
for (unsigned int i = 0; i < rxmsg.DataSize; i++) {
printf("%02X ", rxmsg.Data[i]);
}
printf("\n");
responseReceived = true;
break;
}
Sleep(300); // Wait for 300ms before the next attempt
}
if (!responseReceived) {
printf("No RPM response received from the instrument cluster.\n");
}
// Cleanup: Disconnect and close the device
if (j2534.PassThruDisconnect(chanID)) {
reportJ2534Error(j2534);
}
if (j2534.PassThruClose(devID)) {
reportJ2534Error(j2534);
}
return 0;
}
Как и следовало ожидать, я получаю сообщение о том, что ответ не получен.
Кто-нибудь сталкивался с похожая проблема или может подсказать, что я делаю неправильно?
Подробнее здесь: https://stackoverflow.com/questions/773 ... d-j2534-ap