The Target Model class is the gateway into the target program for the host application to interface with. Once the host application’s target controller has either started a local target or connected to a remote target, the framework manages the Target Model to keep it in sync with the target. One way that the host application interacts with the target application is through so-called variable binding, where any statically linked (non-stack/non-allocated) variable in the target is synchronized with a corresponding variable in the C# target model class at runtime. Once the target application is compiled and built, the Virtuoso framework uses the target-specific plugin to analyze the target build and extract all information about it, including functions and statically linked variables. The user then uses Virtuoso to configure the Target Model with application-specific variable bindings based on the user’s needs. After every time the target is built, the Virtuoso framework analyzes and extracts information about the target in the background, including all functions and statically linked variables. The user can then use the “Target Model Builder” built into Virtuoso to configure the runtime model for the target.
In the above case, there could be hundreds or thousands of variables in the application, but let’s say we are only interested in interacting with MyInt and MyFloat. We would then specify the MyInt and MyFloat variables as variables that we want to expose to our Target Model (a C# class in this case), and the Target Model Builder tool then “renders” TargetModel.cs, meaning that the Target Model Builder creates or updates the TargetModel.cs source file based on the target hosting settings. Thus, Virtuoso is completely responsible for managing all contents of the TargetModel.cs file. When the host runs, it then launches the target(s) being hosted and creates a Target Model class instance that is available to the host application (again, in this case a C#/.NET WPF desktop application), with properties which stay in sync with their corresponding target variables at runtime. If one of the variables is updated in the target application, the corresponding property on the Target Model gets updated automatically. Conversely, if the host application writes a new value to one of the Target Model properties in C#, the corresponding variable gets updated in the target, at runtime, instantaneously and automatically. Keep in mind that the target application doesn’t need to have any kind of special structure for the binding to work. As far as the target application knows, it’s simply working with a normal variable or buffer in memory.
Virtuoso comes with standard type binding, meaning that an “int” in the target C application can be exposed as an “int” in the C# Target Model as well. However any user-defined data type or structure can be used and exposed as a byte array on the C# Target Model, and then the host application can retype the binding in any way needed.
“Begin by creating a new host application to host the target. Run Virtuoso by clicking the Virtuoso symbol on the desktop, and you will see the Virtuoso Project Browser. Select the New Project tab, select the Visual Studio version you prefer, then specify the folder and host name. We will create a “Hello World” host project on the desktop. Click “Create Project” and your Virtuoso host, with corresponding C# application, will be created.”