OTX-Runtime for C++  
Inside Application Process

If an OTX procedure will be executed, the OTX-Runtime API creates a new runtime context. Each runtime context normally has its own process called OTX-Runner. Especially in safety-critical systems it might not be possible to create new processes. In this case the runtime context will be run inside a thread of the application and not inside a new runner process. This is called RAW transport layer.

Note: The RAW transport layer only works with C++ OTX-Runtime API.

Code Example with RAW Transport Layer

How the OTX-Runtime API can be used with with RAW Transport Layer can be used, is described in the following C++ example. The example connects to a started DiagManager and executes the main procedure of a PTX file.

Code snippet of the OTX-Runtime API Sample Program.

1 #include <RuntimeManagerFactory.h>
4 
5 #include <IRuntimeContext.h>
7 
8 #include <Project/IProject.h>
9 using OpenTestSystem::Otx::Runtime::Api::Otx::IProject;
10 
11 #include <Otx/IProcedure.h>
13 
14 #include <OtxDiagFactory.h>
16 using OpenTestSystem::Otx::DiagManager::Common::ICommandProcessor;
19 
20 #include <OpenTestSystem.Otx.Runtime2.Api/License/LicenseManager.h>
21 #include <OpenTestSystem.OtxDiagManager.OtxDiagApi/License/LicenseManager.h>
22 
23 typedef ICommandProcessor* (__cdecl* typeCreateCommandProcessor)(IDiagRuntimeSystem* diagRuntimeSystem);
24 typedef IDiagRuntimeSystem* (__cdecl* typeCreateDiagRuntimeSystem)(const char * projectName, const char * vehicleInfo);
25 
26 #include <iostream>
27 #include <Windows.h>
28 
29 int main(int argc, char **argv)
30 {
31  // ==================================
32  // Create Raw OtxDiagApi
33  // ==================================
34  const char * odxProject = ""; // declare OdxProject, it can be empty.
35  const char * odxVehicle = ""; // declare OdxVehicle, it can be empty.
36  const char * commandProcessorFilePath = "OpenTestSystem.Otx.DiagManager.CommandProcessor.dll";
37  const char * drsFilePath = "OpenTestSystem.Otx.DiagManager.DiagRuntimeSystem.dll";
38 
39  // Set license for OtxDiagApi
40  OpenTestSystem::Otx::DiagManager::OtxDiagApi::License::LicenseManager::SetLicenseKey("XXXXX-XXXXX-XXXXX-XXXXX-XXXXX");
41 
42  // Please note that:
43  // - VW_MCD_HOME, VW_MCD_CONFIG enviroment variables must be set
44  // - PATH enviroment variable contains VW_MCD_HOME value
45  HMODULE DRS_Module = ::LoadLibrary(drsFilePath); // Dynamically loading the DiagRuntimeSystem.dll
46  if (DRS_Module == NULL)
47  {
48  std::cout << drsFilePath << " not found!" << std::endl;
49  return 1;
50  }
51 
52  // Create an instance of function CreateDiagRuntimeSystem
53  typeCreateDiagRuntimeSystem createDRSFunction = reinterpret_cast<typeCreateDiagRuntimeSystem>(::GetProcAddress(DRS_Module, "CreateDiagRuntimeSystem"));
54  if (createDRSFunction == NULL)
55  {
56  std::cout << "function CreateDiagRuntimeSystem not found!" << std::endl;
57  return 1;
58  }
59 
60  // Dynamically loading the CommandProcessor.dll
61  HMODULE CP_Module = ::LoadLibrary(commandProcessorFilePath);
62  if (CP_Module == NULL)
63  {
64  std::cout << commandProcessorFilePath << " not found!" << std::endl;
65  return 1;
66  }
67 
68  // Create an instance of function CreateCommandProcessor
69  typeCreateCommandProcessor createCPFunction = reinterpret_cast<typeCreateCommandProcessor>(::GetProcAddress(CP_Module, "CreateCommandProcessor"));
70  if (createCPFunction == NULL)
71  {
72  std::cout << "function CreateCommandProcessor not found!" << std::endl;
73  return 1;
74  }
75 
76  // Call the function CreateDiagRuntimeSystem with project, vehicle parameters
77  IDiagRuntimeSystem * diagRuntimeSystem = createDRSFunction(odxProject, odxVehicle);
78 
79  // Call the function CreateCommandProcessor
80  ICommandProcessor * commandProcessor = createCPFunction(diagRuntimeSystem);
81 
82  OtxDiagFactory otxDiagFactory;
83  std::shared_ptr<IOtxDiag> rawOtxDiag = otxDiagFactory.CreateRawOtxDiag(commandProcessor);
84  // ==================================
85  // Create Raw OtxDiagApi done.
86  // ==================================
87 
88 
89  // ==================================
90  // Create Otx RuntimeManager and execute the main procedure.
91  // ==================================
92 
93  // Set license for Otx Runtime Api
95  // Create the RuntimeManager with raw DiagManager
96  std::shared_ptr<IRuntimeManager> runtimeManager = RuntimeManagerFactory::CreateRawRuntimeManager(rawOtxDiag);
97 
98  // Load PTX file
99  std::shared_ptr<IProject> project = runtimeManager->LoadPtx("DiagComSample.ptx");
100  std::shared_ptr<IProcedure> procedure = project->GetMainProcedure();
101 
102  // Executes the procedure synchronous
103  std::shared_ptr<IRuntimeContext> runtimeContext = runtimeManager->Execute(procedure);
104 
105  // ==================================
106  // Do somethings and exit.
107  // ==================================
108 }
Interface which a DiagRuntimeSystem must be implemented
Definition: IDiagRuntimeSystem.h:21
DiagManager, which contains methods to get access to the supported OTX extension classes
Definition: IOtxDiag.h:32
Factory class for creating the DiagOtxApi
Definition: OtxDiagFactory.h:37
Contains information of a Runner instance.
Definition: IRuntimeContext.h:30
Main class to load and execute an OTX project
Definition: IRuntimeManager.h:72
static void SetLicenseKey(const std::string &licenseKey)
Sets a valid license key to release the API.
Represents an OTX Procedure.
Definition: IProcedure.h:15
Factory class for creating runtime managers, see IRuntimeManager
Definition: RuntimeManagerFactory.h:17