Skip to main content
FW version: Stable

SXapi

tip

TLDR: It is possible to write programs that run on your PC / in the web browser and directly talk to a connected siliXcon device. Using sxapi you can e.g. write your own GUI for siliXcon products.

SXapi is an interface module used to manipulate the device in real-time. Through the SXAPI, you can connect, set parameters, query states, send commands, and monitor responses. SXapi is suited for system integration and R&D processes around our products.

The SXapi is introduced in two flavors:

  • SXapi / Python
  • SXapi / Server (HTTP REST)

SXapi / Python

In this case, SXapi is provided as a custom Python module. A Python code must be run as a plug-in, inside the emGUI tool: emGUI contains a built-in Python 3.8 interpreter.

If you save the code to a file with .sxp extension, you can run it by double-clicking on the file. The file will be opened in emGui and executed within the built-in interpreter. This method will hide the emGUI window by default (unless un-hidden from inside the script).

The other method is, once the emGUI is brought up manually, to navigate to the file through the plugin item in the file menu (the exclusive option disallows running multiple plugins at the same time):

  1. Start emGui
  2. Open the Python plugin from the context menu
  3. Select your python file:

open_plugin

Example

Example of Python code with sxapi. The code connects to the controller with address 0 and, reads and writes some variables.

# First of all, you have to perform a search if it has not been done before.
if sxapi.search() < 0:
sxapi.print("Search failed")
exit()
# Create a node object for a device with address 0
node = sxapi.node(0)

# Get the variable object
try:
var_temp = node.variable("/driver/temp")
var_iref = node.variable("/driver/iref")

except sxapi.error as e:
sxapi.print(str(e))

# Read the value of the variable
sxapi.print("Driver temp:")
sxapi.print(str(var_temp.get()))

# Set the value of the variable
sxapi.print("Iref before:")
sxapi.print(str(var_iref.get()))
var_iref.set(0.5)
sxapi.print("Iref after:")
sxapi.print(str(var_iref.get()))

Output of this example will look like this:

output

A more complex example: siliWatch

This plugin displays a user-friendly overview window for any siliXcon ESCx controller. It was written using sxapi and the customtkinter Python package.

To try it out, navigate to: C:\silixcon\plugins\siliWatchESCxVECTOR.sxp

siliwatch

info

More plugins and examples come with SWTools installation package and can be found in the folder: C:\silixcon\plugins\

Yet more, developer-related examples and unit tests can be found in our GitHub repository.

SXapi / Server (HTTP REST)

SXapi is provided by emGUI through HTTP RESTful API on localhost:28945. In this case, a web application (for example) can access the SXapi from a web browser.

Upon an empty query, the server returns a simple web page with the API description:

siliwatch