7.7.16. Routine control (pdg_RoutineControl)

Communicates UDS service 0x31 (routine control) IO to and from a diagnostic scan tool.

7.7.16.1. Supported targets

All targets

7.7.16.2. Required license

EXT_DIAG (Extended diagnostics library). (See Section 2.3, “Licensed Features”.)

7.7.16.3. Description

Routines can be used to allow a diagnostic tool to perform a custom function within the ECU. For example, a function of the ECU can be started and stopped from the diagnostic tool, or a set of values can be written to or read from ECU memory. The actual routine is defined by the application software.

7.7.16.4. Inports

  • routine_ready

    Flag from the application to inform the platform that the routine is able to run. If this inport is FALSE, the platform will send a negative response to the diagnostic tool if this routine is requested, and the routine_request outport will output noRequest.

    Value type:Boolean
  • routine_running

    Flag from the application to inform the platform that the routine is running.

    Value type:Boolean
  • results_valid

    Flag from application to inform the platform that the data supplied at results inport is valid (i.e. the routine has been run at least one time, and the results are considered valid by the application.) If results are not used for this routine,set Results Length to 0 in the dialog, and ground this inport.

    Value type:Boolean
  • results

    This is the array of bytes that will be transmitted to the diagnostic scan tool when service 0x31 is requested with subfunction 0x03 (requestRoutineResults) AND results_valid is TRUE. If results will not be used, set Results Length to 0 in the dialog, and ground this inport.

    Value type:Array
  • status_record

    This is an optional array of bytes that will be transmitted to the diagnostic scan tool in response to any service 0x31 request. If a status record is not used, set Status Record Length in the dialog to 0 and ground this inport.

    Value type:Array
  • sim_routine_request

    This inport is only used in simulation and only appears if Provide Simulation Input is ticked in the dialog. During simulation, any value supplied to this inport is immediately copied to the routine_request outport.

    Value type:U8
  • sim_rcor

    This inport is only used in simulation and only appears if Provide Simulation Input is ticked in the dialog. During simulation, any array supplied to this inport is immediately copied to the rcor outport.

    Value type:Array

7.7.16.5. Outports

  • routine_request

    Indicates the routine request sub-function that was received from the diagnostic scan tool. Note: the received routine request sub-function will only be output for one sample.

    Table 7.4. RoutineControl request sub-function

    Sub-function Name Value Description
    noRequest0x00 Indicates that no request has been received from the diagnostic tool.
    startRoutine0x01 Indicates that the application must start the routine.
    stopRoutine0x02 Indicates that the application must stop the routine.


    Note: requestRoutineResults (0x03) is handled automatically by the platform. Thus, the routine_request outport will never be 0x03.

    Value type:U8
  • rcor

    Provides the optional routineControlOptionRecord byte array to the application. This outport only appears if the dialog entry RCOR Length is non-zero.

    Value type:Array

7.7.16.6. Mask parameters

  • Routine ID

    A unique routine ID that will be used by the diagnostic tool to identify this routine. Note: routine IDs 0x0202, 0x0203, 0xFF00, and 0xFF01 are reserved by the platform and cannot be used by the application.

    Value type:U16
    Calibratable:No
  • RCOR Length

    Defines the number of bytes in the optional routineControlOptionRecord byte array. Set to 0 if the routine does not use a routineControlOptionRecord.

    Value type:U16
    Calibratable:No
  • Timed Routine

    If ticked, this routine is a "Method B" (timed) routine, and will therefore stop on its own (without a stopRoutine request). If unticked, this routine is a "Method A" (untimed) routine, which requires a stopRoutine request to stop the routine. See ISO 14229-1 section 13 for further details regarding Method A vs. Method B routines.

    Even if ticked, the routine must handle a stopRoutine request to allow the diagnostic tool to stop the routine if necessary.

    Value type:Boolean
    Calibratable:No
  • Results Length

    Defines the number of bytes in the results array. Set to 0 if the routine does not use results.

    Value type:U16
    Calibratable:No
  • Status Record Length

    Defines the number of bytes in the optional statusRecord array. Set to 0 if the routine does not use a statusRecord.

    Value type:U16
    Calibratable:No
  • Provide Simulation Input

    If ticked, two additional inports will be revealed. See sim_routine_request inport and sim_RCOR for further details.

    Value type:Boolean
    Calibratable:No
  • Sample Time

    Defines the sample time that this block will use to check for incoming routine requests, and update outports. Must be a multiple of 0.001.

    Value type:double
    Calibratable:No

7.7.16.7. Notes

Negative response codes to service $31 requests are handled automatically by the platform software. The following list gives the possible negative response codes and the situations in which they are sent.

  • subFunctionNotSupported (0x12): sent when the diagnostic tool requested a subfunction other than startRoutine (0x01), stopRoutine (0x02), or requestRoutineResults (0x03).

  • incorrectMessageLengthOrInvalidFormat (0x13): sent when the diagnostic tool sent a service $31 request message that is too short to contain a 16-bit routine ID.

  • conditionsNotCorrect (0x22): sent when the diagnostic tool sent a startRoutine request when routine_ready is FALSE.

  • requestSequenceError (0x24): This negative code can occur in one of 3 situations:

    1) The diagnostic tool sends a requestRoutineResults command when results_valid is FALSE.

    2) The diagnostic tool sends a startRoutine command for a routine that is already running.

    3) The diagnostic tool sends a stopRoutine command for a routine that is not running.

  • requestOutOfRange (0x31): This negative code can occur if one of the following two situations occur:

    1) The diagnostic tool sends a service $31 request for a routine ID that is not supported by the application or the platform.

    2) The diagnostic tool sends a service $31 request with the the number of bytes in the optional routineControlOptionRecord that is different from what is defined in the RCOR Length dialog parameter.

Routine requests are handled according to the following state diagram

Important notes regarding the routine control state diagram:

1) If the application specifies that the routine is ready AND a startRoutine request is received from the tool, the application MUST start the routine. Otherwise, the routine state machine will stay in the RoutineRequested state until a stopRoutine request is received for the same routine ID. Furthermore, the routine must be started within the amount of time to allow the response message to be transmitted within 1000 ms of when the diagnostic tool sent the request.

2) If a stopRoutine request is received from the diagnostic tool, the application MUST stop the routine. Otherwise, the routine control state machine will stay in the RoutineSopping state. Furthermore, the routine must be stopped within the amount of time to allow the response message to be transmitted within 1000 ms of when the diagnostic tool sent the request.

Some routines are handled by the platform without any input from the application. These routines have routine IDs that may not be used by the application. The reserved routine IDs are: 0x0202, 0x0203, 0xFF00, and 0xFF01.