Devices Tutorial

NameLocation
Devices<Vortex Studio Installation Folder>\tutorials\MyDevicePlugin

Sample module and extension that can be used as a base for an extension implementing an IDevice

It shows the basic of having a module creating it own devices and adding them to the simulation.

It implements a device module that communicates through UDP. It reads/writes a double (8 bytes) every frame.


Python UDP Server

A Python UDP server capable of giving the User a way to test and confirm the UDP Connection to Vortex is provided and resides in the following location:

<vortex studio installaton folder>\tutorials\Device\DeviceServer.py

The server will generate a random Double value between 0 to 100 that is to be received in the Vortex Studio ControlInterface. The Double value will change and update every second. Any additional information can be found in the python file.


Note

To obtain clear results from the previous code, it is recommended to change the Output value of the Control Interface for something greater than 0.0000 (default value).
The following illustration displays an example of the recommendation:


Classes

2 Vortex objects are included in this plugin: a module and an extension.

MyDeviceModule

This Vortex Module demonstrates how to implement a module that communicates with a device.

It can be used as a template for the implementation of the interface ISimulatorModule.

It shows how to initialize a module with the callback onAddToApplication().

It shows how to clean up a module with the callback onRemoveFromApplication().


A single device is supported by this module, however, a module could certainly have support for multiple devices.

The module also spawns its own device, which is convenient but will only work in a single node simulator such as the editor.

To enable support on multiples nodes, the device must not be spawned by the module but added to the setup file.


It shows how to manage extensions; In this case, the module handles extensions of type MyDeviceExtension and processes them each frame.

During the pre-update segment, it reads a double from the UDP channel.

During the post-update segment, it writes a double in the UDP channel

MyDeviceExtension

A simple extension that is managed by the module MyDeviceModule.


MyDeviceExtension defines how the device is represented in the Vortex world.
It only serves as an interface with the UDP channel, providing 2 data fields

  1. An input that is sent to the device
  2. An output to be read from the device.

MyDeviceExtension tells Vortex that it is a device by having this extension derive from IDevice and can be used as a template for an implementation of the interface IDevice.

UPD

This namespace collection of a few methods to manage a UDP socket.


See Vortex Studio SDK - Device Mapping for more details about Devices

See Vortex Studio SDK - Customizing Vortex for information about making plugins and extensions.

See C++ Tutorial 1: Plugins for a detailed example of making a plugin.

Using the tutorial

  1. Open Tutorials solution
  2. Compile the project MyDevicePlugin
  3. Deploy the plugin
  4. Start the Vortex Editor
  5. Add the module MyDeviceModule the editor setup
    1. From the home page, click on Options
    2. Click on Setup
    3. In the Application Setup section, click on the Editor icon next to the editor.vxc file­­. This will open the setup document.
    4. In the toolbox, search for MyDeviceModule, and add the module to the setup.
    5. Configure the module IP address and port if necessary.
      (The default Device and Local IP address should be 127.0.0.1, and their port should be 5005 and 5006 respectively to match the script)
      1. The implementation only opens a socket to LocalAddress:LocalPort, Data will be read from that address.
      2. Data will be sent to the Device address and Device Port, but it must match the local ones for the send to work. The full implementation is left to the user but the script is given as an example.
    6. Save the setup file
  6. From the home menu, create a new control interface document.
    1. Add an input and an output of type double
    2. In the Explorer, right-click on the ControlInterface object and select "Add Device...".
    3. You should be able to add the My Device Extension device to the Control Interface
    4. Map it following the Control Interface documentation.
    5. save it.
  7. Launch from terminal or any IDE supporting Python, the Python UDP Server to confirm the UDP connection.
    1. Confirm that the terminal prints out the proper output values being sent and received from Vortex
      Example:
    2. Press "Ctrl + C" to terminate the program
  8. The interface can be added to a mechanism and be work normally.