Describe
SAE-J2534 with nodejs
Install
npm install sae_j2534_api
Method description
Attribute: drivers(array)
Host driver array, driver contents include:
name: device/driver name.
vendor: device vendor.
library: driver library path.
Method: open(library)
This function is used to establish a connection and intialize the Pass-Thru Device.
library: String, device library path.
return: int, 0 is success.
Method: close()
This function is used to close the connection to a Pass-Thru Device.
return: int, 0 is success.
Method: connect(protocol, baudrate, flags)
This function is used to establish a logical connection with a protocol channel on the specified SAE J2534 device.
protocol: channel protocol, reference to the definition of saej2534.
baudrate: bus baudrate.
flags: connect flags, reference to the definition of saej2534.
return: int, 0 is success.
Method: disconnect()
This function is used to terminate a logical connection with a protocol channel.
return: int, 0 is success.
Method: recv(timeout)
This function reads messages and indications from the receive buffer.
timeout: recv timeout, unit: millisecond.
return: object, contents include protocol, id, flags, payload.
Method: send(id, payload, timeout)
This function is used to send messages.
id: send msg can id.
payload: send msg data.
timeout: send timeout, unit: millisecond.
return: int, 0 is success.
Method: startPeriodicMsg(id, payload, interval)
This function will immediately queue the specified message for transmission, and repeat at the specified interval.
id: periodic msg can id.
payload: periodic msg data.
timeout: periodic interval, unit: millisecond.
return: object, contents include err, data. When err equals 0, the operation is successful and data is message id.
Method: stopPeriodicMsg(msgId)
This function stops the specified periodic message.
msgId: specified message id.
return: int, 0 is success.
Method: startMsgFilter(filterType, mask, pattern, flowControl)
This function starts filtering of incoming messages.
filterType: filter type, PASS_FILTER/BLOCK_FILTER/FLOW_CONTROL_FILTER, reference to the definition of saej2534.
mask: msg id mask.
pattern: pattern msg id.
flowControl: flow control msg id.
return: object, contents include err, data. When err equals 0, the operation is successful and data is filter id.
Method: stopPeriodicMsg(filterId)
This function removes the specified filter.
filterId: specified filter id.
return: int, 0 is success.
Usage Example
/**************************//* ProtocolID definitions *//**************************/const J1850VPW = 1;const J1850PWM = 2;const ISO9141 = 3;const ISO14230 = 4;const CAN = 5;const ISO15765 = 6;const SCI_A_ENGINE = 7;const SCI_A_TRANS = 8;const SCI_B_ENGINE = 9;const SCI_B_TRANS = 10; /*******************************//* PassThruConnect definitions *//*******************************/// 0 = Receive standard CAN ID (11 bit)// 1 = Receive extended CAN ID (29 bit)const CAN_29BIT_ID = 0x00000100;// 0 = The interface will generate and append the checksum as defined in ISO 9141-2 and ISO 14230-2 for// transmitted messages, and verify the checksum for received messages.// 1 = The interface will not generate and verify the checksum-the entire message will be treated as// data by the interfaceconst ISO9141_NO_CHECKSUM = 0x00000200;// 0 = either standard or extended CAN ID types used ?CAN ID type defined by bit 8// 1 = both standard and extended CAN ID types used ?if the CAN controller allows prioritizing either standard// (11 bit) or extended (29 bit) CAN ID's then bit 8 will determine the higher priority ID typeconst CAN_ID_BOTH = 0x00000800;// 0 = use L-line and K-line for initialization address// 1 = use K-line only line for initialization addressconst ISO9141_K_LINE_ONLY = 0x00001000; /************************//* RxStatus definitions *//************************/// 0 = received i.e. this message was transmitted on the bus by another node// 1 = transmitted i.e. this is the echo of the message transmitted by the PassThru deviceconst TX_MSG_TYPE = 0x00000001;// 0 = Not a start of message indication// 1 = First byte or frame receivedconst START_OF_MESSAGE = 0x00000002;const ISO15765_FIRST_FRAME = 0x00000002; /*v2 compat from v0202*/const ISO15765_EXT_ADDR = 0x00000080; /*DT Accidentally refered to in spec*/// 0 = No break received// 1 = Break receivedconst RX_BREAK = 0x00000004;// 0 = No TxDone// 1 = TxDoneconst TX_INDICATION = 0x00000008; // Preferred nameconst TX_DONE = 0x00000008;// 0 = No Error// 1 = Padding Errorconst ISO15765_PADDING_ERROR = 0x00000010;// 0 = no extended address,// 1 = extended address is first byte after the CAN IDconst ISO15765_ADDR_TYPE = 0x00000080;//CAN_29BIT_ID 0x00000100 defined aboveconst SW_CAN_NS_RX = 0x00040000; /*-2*/const SW_CAN_HS_RX = 0x00020000; /*-2*/const SW_CAN_HV_RX = 0x00010000; /*-2*/ /***********************//* TxFlags definitions *//***********************/// 0 = no padding// 1 = pad all flow controlled messages to a full CAN frame using zeroesconst ISO15765_FRAME_PAD = 0x00000040;//ISO15765_ADDR_TYPE 0x00000080 defined above//CAN_29BIT_ID 0x00000100 defined above// 0 = Interface message timing as specified in ISO 14230// 1 = After a response is received for a physical request, the wait time shall be reduced to P3_MIN// Does not affect timing on responses to functional requestsconst WAIT_P3_MIN_ONLY = 0x00000200;const SW_CAN_HV_TX = 0x00000400; /*-2*/// 0 = Transmit using SCI Full duplex mode// 1 = Transmit using SCI Half duplex modeconst SCI_MODE = 0x00400000;// 0 = no voltage after message transmit// 1 = apply 20V after message transmitconst SCI_TX_VOLTAGE = 0x00800000;const DT_PERIODIC_UPDATE = 0x10000000; /*DT*/ /**********************//* Filter definitions *//**********************/// Allows matching messages into the receive queue. This filter type is only valid on non-ISO 15765 channelsconst PASS_FILTER = 0x00000001; // Keeps matching messages out of the receive queue. This filter type is only valid on non-ISO 15765 channelsconst BLOCK_FILTER = 0x00000002;// Allows matching messages into the receive queue and defines an outgoing flow control message to support// the ISO 15765-2 flow control mechanism. This filter type is only valid on ISO 15765 channels.const FLOW_CONTROL_FILTER = 0x00000003; const binding = ;const device = ; let CANID_HOST = 0x74D;let CANID_ECU = 0x7CD;let arr = devicedrivers;forlet i = 0; i < arrlength; i++ console; console; if 0 != device console; process; console; if 0 != device console; process; var filter = device;if 0 != filtererr console; device; device; process; var periodPayload = Buffer;var periodMsg = device;if 0 != periodMsgerr console; device; device; process; while1 var msg = device; if 0 != msgerr continue; if TX_MSG_TYPE | START_OF_MESSAGE & msgflags continue; console; console; console; console; console; device; if 0 != device console; if 0 != device console; if 0 != device console; if 0 != device console;process