8.6. Virtual controller as in XILab Software

You can use the virtual controller in your programs. To do this, use the function:

device_t XIMC_API open_device (const char *uri)

Open a device with OS uri and return identifier of the device which can be used in calls.

Parameters
uri- Device uri has form “xi-com:port” or “xi-net://host/serial” or “xi-emu:///file”.
In case of USB-COM port the “port” is the OS device uri.

For example: “xi-com:.COM3” in Windows or “xi-com:/dev/tty.s123” in Linux/Mac.

In case of network device the “host” is an IPv4 address or fully qualified domain uri (FQDN), “serial” is the device serial number in hexadecimal system.

For example: “xi-net://192.168.0.1/00001234” or “xi-net://hostname.com/89ABCDEF”.

Important

To open network device you must first call set_bindy_key

In case of virtual device the “file” is the full filename with device memory state, if it doesn’t exist then it is initialized with default values.
For example: “xi-emu:///C:/dir/file.bin” in Windows or “xi-emu:///home/user/file.bin” in Linux/Mac.

You can also use a virtual controller from XILab with a loaded profile. To do this, select and open the virtual controller in XILab.
After loading the required profile (”Settings” -> “Restore from file…” button) or just set the necessary parameters and click “Apply”. Then the file will be saved to the directory C:Users”user”AppDataRoamingXILab.conf/V_x, where x - is the number of the virtual controller.

In your program you can open this virtual controller by specifying the full path to the file.
For example:

dev_name = "xi-emu:///C:\Users\"user"\AppData\Roaming\XILab.conf/V_1";
device = open_device(dev_name);
../../_images/virtual_device.png

Virtual controller operation example

Attention

The profile loading function is only implemented in the xilab interface. If you need to change the stage settings during code execution, you can use an alternative option. You can upload the profile to the controller flash memory. (open XILab->Settings->Restore from file->choose your profile->OK->Apply->Save to flash). Then you can change the settings in your program. As soon as you want to return all the default settings, execute the Command READ