Hierarchy

  • Service
    • DiagResponse

Constructors

Properties

service: ServiceItem
testerName: string

Methods

  • Sync service params to tester sequence, after change, the sequence params will be updated.

    Returns Promise<void>

    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 return the value of the provided parameter.

    Parameters

    • paramName: string

      param name

    Returns string | number

    param value

    Util.Init(()=>{
    const testService = DiagRequest.from('Can.testService');
    console.log('SERVICE-ID Buffer:', testService.diagGetParameter('SERVICE-ID'))
    })
  • This function returns the names of all parameters associated with the given diag.

    Returns string[]

    An array of strings storing the names of all parameters.

    Util.Init(()=>{
    const testService = DiagRequest.from('Can.testService');
    console.log('parameter names:', testService.diagGetParameterNames())
    })
  • This function will return the Buffer of the provided parameter.

    Parameters

    • paramName: string

      param name

    Returns Buffer

    Buffer value of provided parameter.

    Util.Init(()=>{
    const testService = DiagRequest.from('Can.testService');
    console.log('SERVICE-ID:', testService.diagGetParameterRaw('SERVICE-ID'))
    })
  • This function will return the bit size of the provided parameter.

    Parameters

    • paramName: string

      param name

    Returns number

    param bit size

    Util.Init(()=>{
    const testService = DiagRequest.from('Can.testService');
    console.log('SERVICE-ID Size:', testService.diagGetParameterSize('SERVICE-ID'))
  • This function will return a raw data of one service.

    Returns Buffer

    raw data of one service.

    Util.Init(()=>{

    const testService = DiagRequest.from('Can.testService')
    console.log('get raw data:', testService.diagGetRaw())
    })
  • This function will return the response code of one response.

    NOTE: Positive response does not have response code.

    Returns number

    response code.

    // here testService2 is a RequestDownload(0x34) service
    Util.On('Can.testService2.recv', (v)=>{
    console.log('response code', v.diagGetResponseCode())
    })
  • This function will return whether the response is a positive response or not.

    Returns boolean

    bool

    Util.On('Can.testService.recv', (v)=>{
    console.log('response is positive:', v.diagIsPositiveResponse())
    })
  • This function will change the provided parameter's value.

    Parameters

    • paramName: string

      parameter's name need to be changed.

    • value: string | number

      new value of the provided parameter.

    Returns void

    Add relative param in Service.

    1. 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'))
      })
    2. 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'))
      })
    3. 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'))
      })
    4. 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'))
      })
    5. 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.

    Parameters

    • paramName: string

      parameter's name need to be changed.

    • value: Buffer

      new Buffer value of the provided parameter.

    Returns void

    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.

    Parameters

    • paramName: string

      parameter name

    • bitLen: number

      new bit size of the provided parameter.

    Returns void

    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.

    Parameters

    • data: Buffer

      The new data's buffer value.

    Returns void

    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.
  • This function will return the service describe setting in Service.

    Returns undefined | string

    service describe.

    Util.Init(()=>{
    const testService = DiagRequest.from('Can.testService');
    console.log('Desc:', testService.getServiceDesc())
    })
  • This function will return the service name

    Returns string

    Util.Init(()=>{
    const testService = DiagRequest.from('Can.testService');
    console.log('ServiceName:', testService.getServiceName())
    })
  • Unsubscribe from an event.

    Type Parameters

    Parameters

    • event: T

      The event type.

    • listener: (data: ServiceEvent[T]) => void | Promise<void>

      The function to unsubscribe.

    Returns void

    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 recv

    Type Parameters

    Parameters

    • event: T

      The event to be listened.

    • listener: (data: ServiceEvent[T]) => void | Promise<void>

      the function when event

    Returns void

    Util.Init(()=>{
    const testService = DiagRequest.from('Can.testService')
    testService.On('send', ()=>{
    console.log('send event happened.')
    })

    testService.On('recv', ()=>{
    console.log('recv event happened.')
    })
    })
  • Subscribe to an event, only once.

    Type Parameters

    Parameters

    • event: T

      The event type.

    • listener: (data: ServiceEvent[T]) => void | Promise<void>

      The function to subscribe.

    Returns void

  • Sends a diagnostic output command to the specified device.

    Parameters

    • OptionaldeviceName: string

      The name of the device to send the diagnostic command to.

    • OptionaladdressName: string

      The address name associated with the device.

    Returns Promise<number>

    The diagnostic output timestamp.

  • Returns string

  • Parameters

    • serviceName: "{{{serviceName}}}"

      serviceName's type '{{{serviceName}}}' is the string configured by Service.

    Returns DiagResponse

        Util.Init(async ()=>{
    // add param arrayParam in Service.
    const testService = DiagRequest.from('Can.testService')
    testService.On('send', ()=>{
    console.log('send event happened.')
    })
    }
  • Parameters

    Returns DiagResponse

    req's type '{{{DiagRequest}}}' is the DiagRequest object.

    Util.On('Can.testService.send', (v)=>{
    const response = DiagResponse.fromDiagRequest(v)
    })