J2534-API 开发

J2534-API 开发

开发J2534设备
第一步, 是开发设备,符合J2534的接插件及线束引脚的定义.
第二步,设备上位机需要开发一套符合J2534的接口API Passthru相关的函数需要封装成API.
在这里插入图片描述

打开设备PassThruOpen

long PassThruOpen(void* pName, unsigned long *pDeviceID);

Parameters

pName - C-string,端口编号,可以输入IP地址,也可以输入NULL,也可以输入COM#,如果输入NULL,则自动匹配
Pointer to a null terminated C-string that identifies a PassThru device. Permitted values include: an IPv4 address in dot-decimal notation, a serial port in COM# notation, or the unit’s configurable name. Pass a NULL pointer to search all ports and present a selection dialog if more than one device is discovered.

pDeviceID - u32 ,反馈句柄,后续连接等操作都需要使用这个句柄
Pointer to an unsigned long (4 bytes) that receives a handle to the vehicle interface. The returned handle is used as an argument to other PassThru functions which require a vehicle interface but not an active communication channel.

案例

PassThruOpen(NULL, &DeviceID);

连接设备PassThruConnect

long PassThruConnect(unsigned long DeviceID, unsigned long ProtocolID, unsigned long Flags, unsigned long BaudRate, unsigned long *pChannelID);
PassThruConnect(DeviceID, ISO15765, Flags, 500000, &ChannelID);

Parameters

DeviceID - Vehicle interface identifier.
ProtocolID - The protocol identifier selects the network layer protocol that will be used for the communications channel.
Flags - Protocol specific options that are defined by bit fields. This parameter is usually set to zero.
BaudRate - Initial baud rate for the channel.
pChannelID - Pointer to an unsigned long (4 bytes) that receives the handle to the open communications channel. The returned handle is used as an argument to other PassThru functions which require a communications channel reference.

案例

PassThruConnect(DeviceID, ISO15765, Flags, 500000, &ChannelID);

断开连接PassThruDisconnect

long PassThruDisconnect(unsigned long ChannelID);

Description

Terminate an existing logical communication channel between the User Application and the vehicle network (via the PassThru device). Once disconnected the channel identifier or handle is invalid. For the associated network protocol this function will terminate the transmitting of periodic messages and the filtering of receive messages. The PassThru device periodic and filter message tables will be cleared.

Parameters

ChannelID - Logical communication channel identifier

案例

Example:
unsigned long Flags = 0;

unsigned long ChannelID;

unsigned long DeviceID;

PassThruOpen(NULL, &DeviceID);

PassThruConnect(DeviceID, ISO15765, Flags, 500000, &ChannelID);

// Perform vehicle communication here

PassThruDisconnect(ChannelID);
PassThruClose(DeviceID);

IO控制PassThruIoctl

long PassThruIoctl(unsigned long HandleID, unsigned long IoctlID, void *pInput, void *pOutput);

Description

The PassThruIoctl function is a general purpose I/O control function for modifying the vehicle network interface’s characteristics…

Parameters

HandleID - 设备句柄
Either a logical communications channel or a PassThru device identifier, depending on the specific function.

IoctlID - 函数identifier
Function identifier.

pInput - 输入参数指针
Pointer to input structure. Must be NULL if parameter is unused.

pOutput - 输出参数指针
Pointer to output structure. Must be NULL if parameter is unused.

Ioctl Functions

// IOCTL IDs

#define GET_CONFIG 1

#define SET_CONFIG 2

#define READ_VBATT 3

#define FIVE_BAUD_INIT 4

#define FAST_INIT 5

#define SET_PIN_USE 6

#define CLEAR_TX_BUFFERS 7

#define CLEAR_TX_BUFFER 7

#define CLEAR_RX_BUFFERS 8

#define CLEAR_RX_BUFFER 8

#define CLEAR_PERIODIC_MSGS 9

#define CLEAR_MSG_FILTERS 10

#define CLEAR_FUNCT_MSG_LOOKUP_TABLE 11

#define ADD_TO_FUNCT_MSG_LOOKUP_TABLE 12

#define DELETE_FROM_FUNCT_MSG_LOOKUP_TABLE 13

#define READ_PROG_VOLTAGE 14

获取配置GET_CONFIG

typedef struct
{
unsigned long Parameter;
unsigned long Value;
} SCONFIG;

typedef struct
{
unsigned long NumOfParams;
SCONFIG *ConfigPtr;
} SCONFIG_LIST;

unsigned long status;
SCONFIG CfgItem;
SCONFIG_LIST Input;
CfgItem.Parameter = DATA_RATE;
CfgItem.Value = 0;
Input.NumOfParams = 1;
Input.ConfigPtr = &CfgItem;

status = PassThruIoctl(ChannelID, GET_CONFIG, &Input, NULL);

设置配置SET_CONFIG

unsigned long status;
SCONFIG CfgItem;
SCONFIG_LIST Input;
CfgItem.Parameter = DATA_RATE;
CfgItem.Value = 10400;
Input.NumOfParams = 1;
Input.ConfigPtr = &CfgItem;

status = PassThruIoctl(ChannelID, SET_CONFIG, &Input, NULL);

READ_PROG_VOLTAGE

Reports CarDAQ’s current output voltage for ECU programming. Because this request does not require an active communication channel, the handle should be a DeviceID.

unsigned long VoltageLevel;
PassThruIoctl(DeviceID, READ_PROG_VOLTAGE, NULL, &VoltageLevel);

READ_VBATT

Reports the battery voltage on pin 16 of the J1962 connector. Because this request does not require an active communication channel, the handle should be a DeviceID.

unsigned long VoltageLevel;

PassThruIoctl(DeviceID, READ_VBATT, NULL, &VoltageLevel);

CLEAR_TX_BUFFER

Empties the transmit message queue.

unsigned long status;

status = PassThruIoctl(ChannelID, CLEAR_TX_BUFFER, NULL, NULL);

CLEAR_PERIODIC_MSGS

Halts all continuous messages.

unsigned long status;

status = PassThruIoctl(ChannelID, CLEAR_PERIODIC_MSGS, NULL, NULL);

FAST_INIT

Performs an fast initialization sequence with the target ECU.
This function is ISO14230-4 (KWP2000) specific. This function causes the PassThru device to initiate a fast initialization sequence with the target ECU. The ECUs on the ISO9141 bus require initialization in order to communicate with the PassThru device. The fast initialization sequence will use 10.4K-baud rate. The PassThru device transmits a Wake Up pattern on the serial bus. After the Wake Up time interval expires the PassThru device transmits the StartCommunicationRequest message. The ECU answers back with the StartCommunicationResponse message with its supported transmission mode parameters defined by the two key bytes. The PassThru device returns the 2-byte KeyWord parameters to the UserApplication. The UserApplication must decode the communication identifier and configure the PassThru device transmission parameters (via PassThruIoctl) so the PassThru device can correctly send and receive messages over the vehicle network.
This function must be called after the PassThruConnect function and the UserApplication must configure the ECU specified transmission parameters or else the PassThru device will not be able transfer messages to/from the vehicle network.
使用目标ECU执行快速初始化序列。
该功能是ISO14230-4 (KWP2000)特有的。该函数使PassThru设备与目标ECU启动快速初始化序列。为了与PassThru设备通信,ISO9141总线上的ecu需要初始化。快速初始化序列将使用10.4 k波特率。PassThru设备在串行总线上传输唤醒模式。在Wake Up时间间隔过期后,PassThru设备发送StartCommunicationRequest消息。ECU用StartCommunicationResponse消息进行应答,该消息带有由两个密钥字节定义的其支持的传输模式参数。PassThru设备将2字节的关键字参数返回给UserApplication。UserApplication必须解码通信标识符并配置PassThru设备传输参数(通过passthrioctl),以便PassThru设备可以在车辆网络上正确地发送和接收消息。
此函数必须在passthrconnect函数之后调用,并且UserApplication必须配置ECU指定的传输参数,否则PassThru设备将无法向车辆网络传输消息。

unsigned long status;
PASSTHRU_MSG InputMsg;
PASSTHRU_MSG OutputMsg;

memset(&InputMsg, 0, sizeof(InputMsg));
memset(&OutputMsg, 0, sizeof(OutputMsg));

InputMsg.ProtocolID = ISO14230;
InputMsg.TxFlags = 0;
InputMsg.Data[0] = 0xC1; // Format (functional addressing, 1 byte payload)
InputMsg.Data[1] = 0x33; // Initialization address used to activate all ECUs
InputMsg.Data[2] = 0xF1; // Scan Tool physical source address
InputMsg.Data[3] = 0x81; // Data: Start Communication Request Service
InputMsg.DataSize = 4;

status = PassThruIoctl(ChannelID, FAST_INIT, &InputMsg, &OutputMsg);

FIVE_BAUD_INIT

Performs a 5-baud initialization sequence with the target ECU.
This function is ISO9141 and ISO14230-4 (KWP2000) specific. This function causes the PassThru device to initiate a 5-baud initialization sequence with the target ECU. The ECUs on the ISO9141 bus require initialization in order to communicate with the PassThru device. The 5-baud initialization method specifies that the PassThru device send a one byte ECU target address at 5 baud on the ISO9141 bus lines. The target ECU responds with a baud rate synchronization pattern (used by the PassThru Device to gauge the baud rate) followed by two key word bytes, which form an encoded communication identifier. The PassThru device returns the 2-byte KeyWord parameters to the UserApplication. The UserApplication must decode the communication identifier and configure the PassThru device transmission parameters (via PassThruIoctl) so the PassThru device can correctly send and receive messages over the vehicle network.
This function must be called after the PassThruConnect function and the UserApplication must configure the ECU specified transmission parameters or else the PassThru device will not be able transfer messages to/from the vehicle network.
与目标ECU执行5波特初始化序列。
此功能是ISO9141和ISO14230-4 (KWP2000)特有的。该功能使PassThru设备与目标ECU启动一个5波特初始化序列。为了与PassThru设备通信,ISO9141总线上的ecu需要初始化。5波特初始化方法指定PassThru设备在ISO9141总线上以5波特发送一个1字节的ECU目标地址。目标ECU以波特率同步模式(由PassThru设备用于测量波特率)响应,后跟两个关键字字节,形成编码的通信标识符。PassThru设备将2字节的关键字参数返回给UserApplication。UserApplication必须解码通信标识符并配置PassThru设备传输参数(通过passthrioctl),以便PassThru设备可以在车辆网络上正确地发送和接收消息。
此函数必须在passthrconnect函数之后调用,并且UserApplication必须配置ECU指定的传输参数,否则PassThru设备将无法向车辆网络传输消息。
SBYTE_ARRAY InputMsg;
SBYTE_ARRAY OutputMsg;
unsigned long status;

unsigned char EcuAddr[1]; // ECU target address array
unsigned char KeyWord[2]; // Keyword identifier array

EcuAddr[0] = 0x33; // Initialization address used to activate all ECUs

InputMsg.NumOfBytes = 1; // ECU target address array contains one address.
InputMsg.BytePtr = &EcuAddr[0]; // Assign pointer to ECU target address array.
OutputMsg.NumOfBytes = 2; // KeyWord array has 2 bytes allocated.
OutputMsg.BytePtr = &KeyWord[0]; // Assign pointer to KeyWord array.

status = PassThruIoctl(ChannelID, FIVE_BAUD_INIT, &InputMsg, &OutputMsg);

ADD_TO_FUNCT_MSG_LOOKUP_TABLE

Assigns a functional address. CarDAQ only receives a functional messages if its target address appears in this table. This filtering occurs before and separately from any enabled PassThru message filters. A maximum of 31 addresses are supported, and the table is empty by default.

SBYTE_ARRAY InputMsg;
unsigned char FuncAddr[4]; // Functional address array – address values defined in J2178-4
unsigned long status;

FuncAddr[0] = 0x0A; // Engine Air Intake functional address.
FuncAddr[1] = 0x12; // Throttle functional address.
FuncAddr[2] = 0x1A; // Engine RPM functional address.
FuncAddr[3] = 0x32; // Brakes functional address.

InputMsg.NumOfBytes = 4; // Functional address array contains four addresses.
InputMsg.BytePtr = &FuncAddr[0]; // Assign pointer to functional address array.

status = PassThruIoctl(ChannelID, ADD_TO_FUNCT_MSG_LOOKUP_TABLE, &InputMsg, NULL);
DELETE_FROM_FUNCT_MSG_LOOKUP_TABLE
Removes a functional address for J1850PWM. CarDAQ will no longer receive functional messages destined for this address.

SBYTE_ARRAY InputMsg;
unsigned char FuncAddr[2]; // Functional address array – address values defined in J2178-4
unsigned long status;

FuncAddr[0] = 0x12; // Throttle functional address.
FuncAddr[1] = 0x1A; // Engine RPM functional address.

InputMsg.NumOfBytes = 2; // Functional address array contains four addresses.
InputMsg.BytePtr = &FuncAddr[0]; // Assign pointer to functional address array.

status = PassThruIoctl(ChannelID, DELETE_FROM_FUNCT_MSG_LOOKUP_TABLE, &InputMsg, NULL);

CLEAR_FUNCT_MSG_LOOKUP_TABLE

Clears the functional address table. CarDAQ will no longer receive any functional messages.

unsigned long status;

status = PassThruIoctl(ChannelID, CLEAR_FUNCT_MSG_LOOKUP_TABLE, NULL, NULL);
READ_ANALOG_CH1 … CH6

Returns all buffered samples (mV) on a specific ADC channel (1 to 6) since the previous call. This is a vendor-specific extension, only supported by CarDAQ.

// Request 20 ADC samples in mV
unsigned long values[20];
int num = 20;

PassThruIoctl(ChannelID, READ_ANALOG_CH1, &num, values);

READ_CH1_VOLTAGE … CH6

This mode returns the most recent sample (mV) on a specific ADC channel (1 to 6), and flushes all other samples currently in the queue. This is a vendor-specific extension, only supported by CarDAQ.

// Read the most recent ADC sample in mV
PassThruIoctl(ChannelID, READ_CH1_VOLTAGE, NULL, &value);

// For TempDAQ, find thermocouple value in degC
voltage = (value - 6125) / 393.9;
temp = tempC(voltage);

查询版本PassThruReadVersion

long PassThruReadVersion(unsigned long DeviceID, char *pFirmwareVersion, char * pDllVersion, char *pApiVersion);

Description

Retrieve the PassThru device firmware version, the PassThru device DLL version, and the version of the J2534 specification that was referenced. The version information is in the form of NULL terminated strings.

Parameters

DeviceID - 设备句柄
Vehicle interface identifier.
FirmwareVersion - char [80] 固件
Pointer to an 80 character array, allocated by the application, which will receive the firmware version string.
DllVersion - char [80] DLL版本
Pointer to an 80 character array, allocated by the application, which will receive the DLL version string.
ApiVersion - char [80] API版本
Pointer to an 80 character array, allocated by the application, which will receive the API version string in YY.MM format. It corresponds to the ballot date of the J2534 specification that was referenced by the PassThru DLL implementers.

Example:

unsigned long DeviceID;
char FirmwareVersion[80];
char DllVersion[80];
char ApiVersion[80];

PassThruOpen(NULL, &DeviceID);
PassThruReadVersion(DeviceID, FirmwareVersion, DllVersion, ApiVersion);

故障查询PassThruGetLastError

long PassThruGetLastError(char *pErrorDescription);

Description

Retrieve a text description for the most recent PassThru error as a null terminated C-string. Call this function immediately after an error occurs. The error string refers to the most recent function call, rather than a specific DeviceID or ChannelID, and any subsequent function call may clobber the description.

Parameters

pErrorDescription - char [80] 错误描述
Pointer to an 80 character array allocated by the application, which will receive the error description string.

Example:

char ErrorMsg[80]
unsigned long status;
unsigned long ChannelID;

status = PassThruOpen(NULL, &DeviceID);
if (status != STATUS_NOERROR)
{
// Failed! Get descriptive error string.
PassThruGetLastError(ErrorMsg);

// Display Error dialog box and/or write to Log file.
}

读取报文PassThruReadMsgs

long PassThruReadMsgs(unsigned long ChannelID, PASSTHRU_MSG *pMsg, unsigned long *pNumMsgs, unsigned long Timeout);

Description

Receive network protocol messages, receive indications, and transmit indications from an existing logical communication channel. Messages will flow through PassThru device to the User Application…

Parameters

ChannelID - Logical communication channel identifier
pMsg - Pointer to the message structure(s). For reading more than one message, this must be a pointer to an array of PASSTHRU_MSG structures. The API/DLL will fill RxStatus, TxStaus, Timestamp, DataSize, ExtraDataIndex and Data.
pNumMsgs - Pointer to the desired number of pMsg frames. On function completion, this variable contains the actual number of pMsg frames that were read. Due to timeouts, the number of messages returned may be less than the number requested. The pMsg structure must be large enough to contain pNumMsgs worth of frames.
Timeout - Timeout (in milliseconds) for read completion. A value of zero reads buffered messages and returns immediately. A non-zero value blocks (does not return) until the specified number of messages have been read, or until the timeout expires.
See Also: PassThruWriteMsgs
See Also: PassThruStartMsgFilter

Example:

PASSTHRU_MSG Msg[2];
unsigned long timeout = 0;

// Initialize the PASSTHRU_MSG structure to all zeroes
memset(&Msg, 0, 2*sizeof(Msg));

// Set the ProtocolID to select protocol frames of interest
Msg[0].ProtocolID = ISO15765;
Msg[1].ProtocolID = ISO15765;

// Attempt to read two messages, immediately return
NumMsgs = 2;
PassThruReadMsgs(ChannelID, &Msg, &NumMsgs, timeout);

报文过滤PassThruStartMsgFilter

long PassThruStartMsgFilter(unsigned long ChannelID, unsigned long FilterType, PASSTHRU_MSG *pMaskMsg, PASSTHRU_MSG *pPatternMsg, PASSTHRU_MSG *pFlowControlMsg, unsigned long *pMsgID);

Description

The PassThruStartMsgFilter function is used to setup a network protocol filter that will selectively restrict or limit network protocol messages received by the PassThru device. The filter messages will flow from the User Application to the PassThru device. There is a limit of ten filter messages per network layer protocol.
The PassThru device will block all vehicle network receive frames by default, when no filters are defined.
The CLEAR_RX_BUFFER (PassThruIoctl function) command must be used after establishing filters to ensure that the receive queue only contains receive frames that adhere to the filter criteria. The PassThruStartMsgFilter function does not cause existing receive messages to be removed from the PassThru device receive queue.

Parameters

ChannelID - 设备句柄
The logical communication channel identifier assigned by the J2534 API/DLL when the communication channel was opened via the PassThruConnect function.
FilterType 过滤类型
PASS_FILTER: 选中通过
PassThru device adds receive messages matching the Mask and Pattern criteria to its receive message queue.
BLOCK_FILTER: 选中屏蔽
PassThru device ignores receive messages matching the Mask and Pattern criteria.
FLOW_CONTROL_FILTER:
PassThru device adds receive messages matching the Mask and Pattern criteria to its receive message queue. The PassThru device transmits a flow control message (only for ISO 15765-4) when receiving multi-segmented frames.
pMaskMsg - MASK
Pointer to the message structure containing the User Application’s mask data. The mask message is applied by the PassThru device to every receive message. The mask is used to isolate the receive message header sections(s) that are of interest to the User Application. A “1” bit value means that the corresponding message bit will be examined; a “0” bit value means that the corresponding message bit will be ignored.
pPatternMsg - 匹配报文
Pointer to the message structure containing the User Application’s pattern data. The PassThru device compares the Pattern message to the receive message after it is ANDed with the Mask message.
For a PASS_FILTER if the Pattern message matches the result of received message ANDed with the Mask message, then the PassThru device adds that message to its receive message queue. Otherwise that receive message will be ignored.
For a BLOCK_FILTER if the Pattern message matches the result of received message ANDed with the Mask message, then the PassThru device ignores that message. Otherwise that receive message will be added to the PassThru device receive message queue.
For a FLOW_CONTROL_FILTER if the Pattern message matches the result of received message ANDed with the Mask message, then the PassThru device adds that message to its receive message queue. Otherwise that receive message will be ignored.
Receive message data bytes outside the range of the pattern are not used in the comparison with the Pattern message.
pFlowControlMsg -
The FlowControl message is only valid for the FLOW_CONTROL_FILTER and the pFlowControlMsg pointer must be set to NULL for the PASS_FILTER or BLOCK_FILTER.
Pointer to the message structure containing the User Application’s flow control message. The User Application specifies either an 11-bit or 29-bit CAN Identifier and an optional one byte extended CAN Address(used for identifying subnetworks connected to CAN gateways). The 11-bit CAN Identifier must be represented as a 4-byte object with the unused 2 bytes and 5 bits set to zero. The 29-bit CAN Identifier is also represented as a 4-byte object with the 3 unused bits set to zero.
This FlowControl mechanism is ISO15765 specific. The ISO15765-2 protocol is a network layer protocol devised for exchanging datagrams between CAN nodes or between a CAN node and an external PassThru device. The ISO15765-2 protocol defines a segmentation method that allows for large transfers(up to 4095 data bytes) to be segmented or broken into a series of CAN frames(up to 7 data bytes).
The FlowControl mechanism is used in a peer to peer data transfer where the transmitting peer is sending more data than can fit into one CAN frame. The transmitting peer splits the data between multiple CAN frames making the data transfer multi-framed or multi-segmented. The purpose of FlowControl is to allow the receiving peer to regulate the rate at which frames are sent by the transmitting peer. The receiving peer’s FlowControl message contains a BlockSize and SeparationTime parameters, which are used by the transmitting peer to shape its data transfer into consecutive frame bursts. The BlockSize is the number of consecutive frames that can be sent in a burst before waiting for the next FlowControl message. The SeparationTime is the minimum time to pause between transmitting consecutive frames.
The FlowControl message is transmitted by the PassThru device when the receive message ANDed with the Mask message matches the Pattern message and the receive message type is FirstFrame or the receive message type is ConsecutiveFrame and the receive frame is the last frame of the consecutive frame burst. FlowControl message filtering occurs only on the CAN Identifier portion of the CAN frame.
The User Application specifies the CAN Identifier (either 11-bit or 29-bit) and the extended address byte (if configured) for the FlowControl message. Extended addressing is configured by PassThruConnect(Flags, option ISO15765_ADDR_TYPE) or configured by PassThruWriteMsgs (TxFlags, option ISO15765_ADDR_TYPE in PASSTHRU_MSG structure).
The PassThru device will supply the Protocol Control Information (PCI) bytes for the FlowControl message. The PCI data includes message type (FlowControl, FirstFrame and ConsecutiveFrame) and associated message specific parameters FlowStatus(ContinueToSend, Wait or Overflow), BlockSize and SeparationTime minimum. The PassThru device will use the default BlockSize (0, FlowControl frames not used) and SeparationTimeMin (0, no time pause between consecutive frames) values or use BS and STmin set by the User Application through the PassThruIoctl function(SET_CONFIG).
Refer to Appendix A (page 64) of SAE J2534-1 for a detailed description of the flow control filter.
MsgID - Pointer to the variable that receives the handle to the message filter. The returned handle is used as an argument to PassThruStopMsgFilter to identify a specific message filter.
See Also: PassThruStopMsgFilter
See Also: PassThruIoctl (CLEAR_MSG_FILTERS)

Example:

PASSTHRU_MSG MaskMsg, PatternMsg, FlowControlMsg;
PASSTHRU_MSG Msg[2];

unsigned long ChannelID;
unsigned long FilterID;
unsigned long NumMsgs;

PassThruOpen(NULL, &DeviceID);
PassThruConnect(DeviceID, ISO15765, Flags, 500000, &ChannelID);

MaskMsg.ProtocolID = ISO15765;
MaskMsg.Data = {0xFF, 0xFF, 0xFF, 0xFF};
MaskMsg.TxFlags = ISO15765_FRAME_PAD;
MaskMsg.DataSize = 4;

PatternMsg.ProtocolID = ISO15765;
PatternMsg.Data = {0x00, 0x00, 0x07, 0xE8};
PatternMsg.TxFlags = ISO15765_FRAME_PAD;
PatternMsg.DataSize = 4;

FlowControlMsg.ProtocolID = ISO15765;
FlowControlMsg.Data = {0x00, 0x00, 0x07, 0xE0};
FlowControlMsg.TxFlags = ISO15765_FRAME_PAD;
FlowControlMsg.DataSize = 4;

PassThruStartMsgFilter(ChannelID, FLOW_CONTROL_FILTER, &MaskMsg, &PatternMsg, &FlowControlMsg, &FilterID);

// Get rid of any messages received before the filter started
PassThruIoctl(ChannelID, CLEAR_RX_BUFFER, NULL, NULL);

// Read messages like normal
NumMsgs = 2;

停止过滤PassThruStopMsgFilter

long PassThruStopMsgFilter(unsigned long ChannelID, unsigned long MsgID);

Description

Terminate the specified network protocol filter. Once terminated the filter identifier or handle value is invalid.

Parameters

ChannelID - Logical communication channel identifier
MsgID - Message identifier or handle assigned by the J2534 API/DLL when PassThruStartMsgFilter function was called.
See Also: PassThruStartMsgFilter
See Also: PassThruIoctl (CLEAR_MSG_FILTERS)

Example:

PassThruStartMsgFilter(ChannelID, PASS_FILTER, &MaskMsg, &PatternMsg, NULL, &FilterID);
// Perform vehicle communication here
PassThruStopMsgFilter(ChannelID, FilterID);

写报文PassThruWriteMsgs

long PassThruWriteMsgs(unsigned long ChannelID, PASSTHRU_MSG *pMsg, unsigned long *pNumMsgs, unsigned long Timeout);

Description

Transmit network protocol messages over an existing logical communication channel. Messages will flow through PassThru device to the vehicle network.

Parameters

ChannelID - Logical communication channel identifier
pMsg - Pointer to the message structure(s). For sending more than one message, this must be a pointer to an array of PASSTHRU_MSG structures.
pNumMsgs - Pointer to the number of desired pMsg frames. On function completion this variable will contain the actual number of messages sent to the vehicle network. Due to timeouts, the number of transmitted messages may be less than the number requested by the UserApplication.
Timeout - Timeout (in milliseconds) for read completion. A value of zero queues as many transmit messages as possible and returns immediately. A non-zero value blocks (does not return) until the specified number of messages have been transmitted, or until the timeout expires.
See Also: PassThruReadMsgs
See Also: PassThruStartPeriodicMsg

Example:

// Mode/PID 0100: Ask an ECU which OBD-II PIDs are supported with 11-bit CAN
Msg.ProtocolID = ISO15765;
Msg.TxFlags = ISO15765_FRAME_PAD;
Msg.Data = {0x00, 0x00, 0x07, 0xDF, 0x01, 0x00};
Msg.DataSize = 6;

// Indicate that the PASSTHRU_MSG array contains just a single message.
NumMsgs = 1;
PassThruWriteMsgs(ChannelID, &Msg, &NumMsgs, 100);

开启周期PassThruStartPeriodicMsg

long PassThruStartPeriodicMsg(unsigned long ChannelID, PASSTHRU_MSG *pMsg, unsigned long *pMsgID, unsigned long TimeInterval);

Description

Repetitively transmit network protocol messages at the specified time interval over an existing logical communication channel. There is a limit of ten periodic messages per network layer protocol.

Parameters

ChannelID - Logical communication channel identifier
pMsg - Pointer to the message structure containing the User Application’s periodic message.
pMsgId - Pointer to the variable that receives the handle to the periodic message. The returned handle is used as an argument to PassThruStopPeriodicMsg to identify a specific periodic message.
TimeInterval - Time interval (in milliseconds) at which the periodic message is repetitively transmitted. The acceptable range is 5 to 65,535 milliseconds.
See Also: PassThruStopPeriodicMsg
See Also: PassThruIotcl (CLEAR_PERIODIC_MSGS)

Example:

// Mode-PID 010D: Vehicle speed in km/h
Msg.ProtocolID = ISO15765;
Msg.TxFlags = ISO15765_FRAME_PAD;
Msg.Data = {0x00, 0x00, 0x07, 0xDF, 0x01, 0x0D};
Msg.DataSize = 6;

// Request PID 010D every 500 ms
TimeInterval = 500;
PassThruStartPeriodicMsg(ChannelID, &Msg, &MsgID, TimeInterval);

停止周期PassThruStopPeriodicMsg

long PassThruStopPeriodicMsg(unsigned long ChannelID, unsigned long MsgID);

Description

Terminate the specified periodic message. Once terminated the message identifier or handle value is invalid.

Parameters

ChannelID - Logical communication channel identifier
MsgID - Message identifier or handle assigned by the J2534 API/DLL when PassThruStartPeriodicMsg function was called.
See Also: PassThruStartPeriodicMsg
See Also: PassThruIotcl (CLEAR_PERIODIC_MSGS)

Example:

PassThruStartPeriodicMsg(ChannelID, &Msg, &MsgID, TimeInterval);

// Perform vehicle communication here

PassThruStopPeriodicMsg(ChannelID, MsgID);

PassThruSetProgrammingVoltage

long PassThruSetProgrammingVoltage(unsigned long DeviceID, unsigned long PinNumber, unsigned long Voltage);

Description

Output a programmable voltage on the specified J1962 connector pin. Only one pin can have a specified voltage applied at a time. The only exception: it is permissible to program pin 15 for SHORT_TO_GROUND, and another pin to a voltage level.
When switching pins, the user application must disable the first voltage (VOLTAGE_OFF option) before enabling the second. The user application protect against applying any incorrect voltage levels. A current in excess of 200mA will damage CarDAQ; do not ground the FEPS line while energized, even briefly.

Parameters

DeviceID - Vehicle interface identifier.
PinNumber - The J1962 connector pin to which the PassThru device will apply the specified voltage.
Voltage - The voltage value (in millivolts) that will be applied to the specified pin. CarDAQ supports a programmed voltage range of 5000mV to 20000mV with a tolerance of 100 millivolts. The voltage change slope has a maximum settling time of 1 millisecond.

Example:

unsigned long Flags = 0;
unsigned long ChannelID;
unsigned long DeviceID;
unsigned long PinNumber;
PassThruOpen(NULL, &DeviceID);
PinNumber = 15;
PassThruSetProgrammingVoltage(DeviceID, PinNumber, SHORT_TO_GROUND);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值