Syntax
#include "j2534_v0404.h"
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 - 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
GET_CONFIG
Reports various CarDAQ configuration parameters. The values of multiple parameters may be obtained with a single function call, by initializing an array of SCONFIG items.
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
Configures various CarDAQ configuration parameters. The values of multiple parameters may be set with a single function call, by initializing an array of SCONFIG items.
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);
CLEAR_RX_BUFFER
Empties the receive message queue.
unsigned long status;
status = PassThruIoctl(ChannelID, CLEAR_RX_BUFFER, NULL, NULL);
CLEAR_MSG_FILTERS
Halts all network message filters for the logical communication channel.
unsigned long status;
status = PassThruIoctl(ChannelID, CLEAR_MSG_FILTERS, 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.
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.
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);