Register a function, this function will be invoked when UDSClass is initialized.
Non-async or async function
Perform actions following UDS initialization using a normal function.
Util.Init(()=>{
console.log('Hello UDS!')
})
Perform actions following UDS initialization using an async function.
Util.Init(async ()=>{
const file=await fs.readFile(path.join(process.env.PROJECT_ROOT,'file.bin'))
let length=file.length
console.log('Hello UDS file! file length is', length)
})
The last registered function will override the previous ones.
// The following code will be ignored
Util.Init(async ()=>{
console.log('1')
})
// The following code will take effect
Util.Init(async ()=>{
console.log('2')
})
Unsubscribes from CAN messages.
The identifier of the CAN message to unsubscribe from. If true
, unsubscribes from all CAN messages.
The callback function to remove from the event listeners.
Unsubscribes from an event listener for a specific key.
The key to unsubscribe from. Only the first character of the key is used, * is a wildcard.
The callback function to remove from the event listeners.
Unsubscribes from LIN messages.
The identifier of the LIN message to unsubscribe from. If true
, unsubscribes from all LIN messages.
The callback function to remove from the event listeners.
Unsubscribes from an event listener for a variable update.
The name of the variable to unsubscribe from, * is a wildcard.
The callback function to remove from the event listeners.
Subscribe to an event, invoking the registered function when the event is emitted.
The
UDS
is a UDSClass type and has already been created by Service.
send functions
Util.On('Can.testService.send', async (req) => {
// The req is a `DiagRequest`
console.log(req.getServiceName(), ': send');
});
recv function
Util.On('Can.testService.recv', async (req) => {
// The req is a `DiagResponse`
console.log(req.getServiceName(), ':recv');
});
Registers an event listener for CAN messages.
The CAN message ID to listen for. If true
, listens for all CAN messages.
The callback function to be invoked when a CAN message is received.
Registers an event listener for CAN messages that will be invoked once.
The CAN message ID to listen for. If true
, listens for all CAN messages.
The callback function to be invoked when a CAN message is received.
Registers an event listener for a specific key.
The key to listen for. Only the first character of the key is used, * is a wildcard.
The callback function to be executed when the event is triggered. This can be a synchronous function or a function returning a Promise.
Registers an event listener for a specific key that will be invoked once.
The key to listen for. Only the first character of the key is used, * is a wildcard.
The callback function to be executed when the event is triggered. This can be a synchronous function or a function returning a Promise.
Registers an event listener for LIN messages.
The LIN message ID or ${databaseName}.${frameName} to listen for. If true
, listens for all LIN messages.
The callback function to be invoked when a LIN message is received.
Registers an event listener for LIN messages that will be invoked once.
The LIN message ID or ${databaseName}.${frameName} to listen for. If true
, listens for all LIN messages.
The callback function to be invoked when a LIN message is received.
Registers an event listener for a variable update.
The name of the variable to listen for, * is a wildcard.
The callback function to be executed when the variable is updated. This can be a synchronous function or a function returning a Promise. The callback receives an object with name and value properties.
Registers an event listener for a variable update that will be invoked once.
The name of the variable to listen for, * is a wildcard.
The callback function to be executed when the variable is updated. This can be a synchronous function or a function returning a Promise. The callback receives an object with name and value properties.