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.

Parameters

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:
"xi-net://192.168.0.1/00001234"
"xi-net://hostname.com/89ABCDEF"

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

For example:

"xi-udp://192.168.0.1:1818"
"xi-tcp://192.168.0.1:1820"

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:\Users\<user>\AppData\Roaming\XILab.conf/V_1"   # in Windows
"xi-emu:///home/<user>/.config/XILab.conf/V_1"               # 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\AppData\Roaming\XILab.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)
../../_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->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