Sync service params to tester sequence, after change, the sequence params will be updated.
A promise that resolves when the event has been emitted.
Util.Init(async () => {
const testService0 = DiagRequest.from('Can.testService')
testService.diagSetParameter('key', 0x01)
const testService1 = DiagRequest.from('Can.testService')
console.log(testService0 == testService1) // false
await testService0.syncService()
const testService2 = DiagRequest.from('Can.testService')
console.log(testService0 == testService2) // true
})
This function will change the provided parameter's value.
parameter's name need to be changed.
new value of the provided parameter.
Add relative param in Service.
array parameter
Util.Init(()=>{
// add param arrayParam in Service.
const testService = DiagRequest.from('Can.testService')
console.log('arrayParam:', testService.diagGetParameter('arrayParam'))
testService.diagSetParameter('arrayParam', '12 34 56 78')
console.log('arrayParam:', testService.diagGetParameter('arrayParam'))
})
num parameter
Util.Init(()=>{
// add param arrayParam in Service.
const testService = DiagRequest.from('Can.testService')
// 8 bit number
console.log('8 bits num:', testService.diagGetParameter('numParam'))
testService.diagSetParameter('numParam', '12')
console.log('set parameter with str:', testService.diagGetParameter('numParam'))
testService.diagSetParameter('numParam', 99)
console.log('set parameter with number:', testService.diagGetParameter('numParam'))
// 16 bit number
console.log('8 bits num:', testService.diagGetParameterRaw('numParam'))
testService.diagSetParameterSize('numParam', 16)
console.log('change size to 16 bits:', testService.diagGetParameterRaw('numParam'))
testService.diagSetParameter('numParam', '257')
console.log('set parameter with str', testService.diagGetParameterRaw('numParam'))
testService.diagSetParameter('numParam', 65534)
console.log('set parameter with number', testService.diagGetParameterRaw('numParam'))
})
ascii parameter
The ascii parameter formats the input value into a string. It is advisable to avoid using numbers as input.
Util.Init(()=>{
// add param arrayParam in Service.
const testService = DiagRequest.from('Can.testService')
// 8 bit number
console.log('8 bits num:', testService.diagGetParameterRaw('asciiParam'))
testService.diagSetParameter('asciiParam', 'A')
console.log('set parameter with str:', testService.diagGetParameterRaw('asciiParam'))
// 16 bit number
console.log('8 bits num:', testService.diagGetParameterRaw('asciiParam'))
await testService.diagSetParameterSize('asciiParam', 16)
console.log('change size to 16 bits:', testService.diagGetParameterRaw('asciiParam'))
await testService.diagSetParameter('asciiParam', 'AB')
console.log('set parameter with str', testService.diagGetParameterRaw('asciiParam'))
})
unicode parameter
Util.Init(()=>{
// add param arrayParam in Service.
const testService = DiagRequest.from('Can.testService')
// 8 bit number
console.log('24 bits num:', testService.diagGetParameter('unicodeParam'))
testService.diagSetParameter('unicodeParam', '❤')
console.log('set parameter with str:', testService.diagGetParameter('unicodeParam'))
// 16 bit number
console.log('48 bits num:', testService.diagGetParameter('unicodeParam'))
testService.diagSetParameterSize('unicodeParam', 48)
console.log('change size to 16 bits:', testService.diagGetParameter('unicodeParam'))
testService.diagSetParameter('unicodeParam', '❤️')
console.log('set parameter with str', testService.diagGetParameter('unicodeParam'))
})
float parameter
Util.Init(()=>{
// add param arrayParam in Service.
const testService = DiagRequest.from('Can.testService')
// 8 bit number
console.log('32 bits num:', testService.diagGetParameter('floatParam'))
testService.diagSetParameter('floatParam', 0.12345)
console.log('set parameter with float:', testService.diagGetParameter('floatParam'))
})
This function will change the provided parameter's value with provided Buffer
value.
parameter's name need to be changed.
new Buffer
value of the provided parameter.
Add relative param in Service.
This function modifies the value of a parameter using a Buffer. The Buffer's value will be transferred at the TP layer. You can generate a Buffer using the following methods:
const newValue1 = Buffer.from([0x12, 0x34, 0x56, 0x78]);
const newValue2 = Buffer.alloc(4);
newValue2.writeUInt8(0x01, 0);
newValue2.writeUInt8(0x02, 1);
newValue2.writeUInt8(0x03, 2);
newValue2.writeUInt8(0x04, 3);
const newValue3 = Buffer.from('11223344', 'hex');
To modify an array parameter, you can use the following example:
Util.Init(() => {
const testService = DiagRequest.from('Can.testService');
console.log('arrayParam:', testService.diagGetParameter('arrayParam'));
const newValue1 = Buffer.from([0x12, 0x34, 0x56, 0x78]);
testService.diagSetParameterRaw('arrayParam', newValue1);
console.log('arrayParam:', testService.diagGetParameter('arrayParam'));
});
For more examples on changing different parameter types, please refer to the
diagSetParameter
function.
This function will change the parameter's bit size.
parameter name
new bit size of the provided parameter.
It is only advisable to specify the size of num and array parameters.
Util.Init(()=>{
const testService = DiagRequest.from('Can.testService')
// array parameter
console.log('arrayParam bit size:', testService.diagGetParameterSize('arrayParam'))
testService.diagSetParameterSize('arrayParam', 64)
console.log('arrayParam bit size:', testService.diagGetParameterSize('arrayParam'))
// num parameter
console.log('numParam bit size:', testService.diagGetParameterSize('numParam'))
testService.diagSetParameterSize('numParam', 16)
console.log('numParam bit size:', testService.diagGetParameterSize('numParam'))
console.log('ascii bit size:', testService.diagGetParameterSize('asciiParam'))
testService.diagSetParameterSize('asciiParam', 16)
console.log('ascii bit size:', testService.diagGetParameterSize('asciiParam'))
})
This function modifies all values of a service.
The new data's buffer value.
This function is typically used by a job to modify all data of a service. The following code demonstrates how to generate a new service and set its raw data:
Util.Register('Can.testJob', async (v) => {
//create a new DiagRequest in Can tester
const testService = new DiagRequest('Can');
const newData = Buffer.from([0x10, 0x01, 0x00, 0x01, 0x02]);
await testService.diagSetRaw(newData);
return [testService];
});
- Ensure that the job
Can.testJob
is already configured in Service.- The return type of a job should be a array.
You can also modify the raw data of an existing service with the following code:
Util.Init(() => {
const testService = DiagRequest.from('Can.testService');
const newData = Buffer.from([0x10, 0x02]);
await testService.diagSetRaw(newData);
});
- Ensure that the service
Can.testService
is already configured in Service.- The new raw data size should be equal to the old raw data size.
Unsubscribe from an event.
The event type.
The function to unsubscribe.
Util.Init(() => {
const testService = DiagRequest.from('Can.testService');
testService.On('send', () => {
console.log('send event happened.');
});
// The following code will not work
testService.Off('send', () => {
console.log('send event happened.');
});
});
Note: To unsubscribe from an event, you must provide a non-anonymous function.
Subscribe to an event. When the event occurs, the listener function will be invoked.
The valid event name should be:
'send'
: will be happen before the msg is send'recv'
: will be happen when the response msg is recvThe event to be listened.
the function when event
Subscribe to an event, only once.
The event type.
The function to subscribe.
Sends a diagnostic output command to the specified device.
Optional
deviceName: stringThe name of the device to send the diagnostic command to.
Optional
addressName: stringThe address name associated with the device.
The diagnostic output timestamp.
Static
fromserviceName's type '{{{serviceName}}}' is the string configured by Service.
Static
fromreq's type '{{{DiagRequest}}}' is the DiagRequest object.