8.7. 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.


uri- a device uri. Device uri has form:

"xi-com:port"               - # Serial port
"xi-net://host/serial"      - # XiNet connection
"xi-udp://<ip/host>:<port>" - # Raw UDP connection
"xi-tcp://<ip/host>:<port>" - # Raw TCP connection
"xi-emu:///file"            - # Virtual device

For example:

"xi-com:\\.\COM3        # in Windows
"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:

In case of UDP/TCP protocol, use “xi-udp://<ip/host>:<port>” “xi-tcp://<ip/host>:<port>”.

For example:


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
"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” -> “Load setting 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:

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

Virtual controller operation example


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->Load setting from file…->choose your profile->OK->Apply->Save settings 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