How To Talk To the X100
Why start programming?
We've designed the X100 to be simple to use even if you can't program. Many experiments can be done by using the software front-panel or example programs without any further modification. However, for users wishing to develop new experiments and applications, or to integrate the X100 with other instruments, our system is truly versatile.
Which programming languages can I use?
Xtralien has been designed to be simple to use and work with pretty much every programming language (at least anything that supports either serial coms or ethernet, which is pretty much everything commonly in use). Common languages that can be used to interface to it are:
- C / C++
We provide reference code showing basic functionality for LabVIEW™, Matlab® and Python and pseudo-code that can be translated into most other programming languages, so no matter what your favourite language is, you should be up and running quickly.
In order to make it as simple to program as possible we've made the X100 a "text-in text-out" system. You send it a command in a text string and it will send back the result in a text string. We've also made the commands as simple as possible so most of them should be self-explanatory (see the command list here).
Example command and data strings
If you want to send the most basic command to the X100 you can send the string "CLOI Hello" to the X100 and the X100 will then respond "Hello World". This is a useful command to check that the X100 is powered up and fully connected. For reference CLOI stands for Command Language for Open Instruments and is what handles all of the X100 communications (think of it as the X100's brain).
Text sent: "CLOI Hello"
Text received: "Hello World"
It doesn't matter what sentence case you use (e.g. "CLOI hello", "cloi hello" and CLoi HEllO"), they will all be understood as CLOI first converts everything to lower case.
If you want to collect some data, for example to do a sweep on the SMU1 output (source measure unit 1) between -1 and +1 volts in 0.1 volt increments, you should send X100 the text string:
"SMU1 sweep -1 +1 0.1"
The X100 will then perform the sweep and send the data back as a standard formatted text array such as:
OK, so this doesn't look particularly readable. However, if we understand how it is formatted it's actually very straightforward.
What the X100 is sending us are the readings it has taken from -1 volt to plus 1 V as an array. To represent an array as a string, the standard scientific-computing way to do this is to separate the columns using commas "," and to separate the rows by semicolons ";" while enclosing the whole array in square brackets to make it easy to identify.
Therefore, if we wanted to represent an array of two columns and n rows we could do this as below:
R1C1 R1C2 R2C1 R2C2 ... RnC1 RnC2
If we go back and look at the text that the X100 sent back we can see that it is actually just sending back a two column array - the first column is the voltage and the second is the current - so the data sent was:
|Voltage (V)||Current (A)|
All measurement data is returned in in scientific notation in volts or amps (rather than microvolts or milliamps) and for those who want specifics, the format specifier is a standard C notation of %8g.
Standard Format Specifier for Data: %8g
How do I send and receive text from the X100
In order to send or receive text from the X100, you need to open a connection to it called a "port" in computing terms. Think of a port as being like a phone line - you need to pick up the phone and dial a specific number before you can talk to someone. The same is true for ports; you need to open a port before you can send any data (text in our case).
You can connect to the X100 using either a USB cable or via ethernet (internet) with instructions on how to identify the ports. The exact method you use to open a port (dial up the X100) depends on the programming language, operating system and connection method, and we have put some examples below (see plugging in a switching on to see how to find out your ports on Windows).
|Operating System||Interface||Example Port Name|
i.e. IP adress 192.168.1.38 on port number 8888
The demo code for LabVIEW™, Matlab® and Python shows how to actually make a connection in these specific languages. For other languages standard communications should work fine, with the only thing you need to know is the IP address (for ethernet) and com port and settings for USB:
USB com port settings (note these are standard default settings) :
* Note that we see good communications from Python at 10 MBit, but typically connect from Matlab or LabVIEW at 920KBit.
8 bits, with one stop bit, no parity and auto baud rate up to 10 Mbits*
The below example represents a generic programming language to explain how you would communicate with Xtralien. For real code examples in LabVIEW, Matlab and Python see the relevant pages.
#Open a USB serial interface to the instrument (on COM1) at a baud rate
#of 115,200 and call that instrument interface X100.
#send a command to the instrument interface named X100. There are lots of
#commands available but one of the most simple and powerful is the sweep
#command. Let's tell the source-measure unit 1 (SMU1) to take a sweep between
# -1 V and 1 V in 0.01V increments as we might do for a photovoltaic device.
print(X100, "SMU1 sweep -1 1 0.1");
#Now read back a line from the instrument interface
#You now have your sweep data stored as an array of text in the
#variable called data_string. From here you could save it to disk as a csv file
#to open in a spreadsheet or email it to the far side of the world. However,
#often we'll want to plot it or do some maths on it so its often useful to
#convert it to an array of numbers (instead of text that represents numbers)
#but this is easy since X100 uses standard number and array formatting.
#Data comes back from the X100 in an array in the form
#voltage_1,current_1; voltage_2,current_2; ... voltage_n, current_n;
#Convert data_string into a matrix array by scanning it for pairs of regular
#formatted (%g) numbers separated by a comma. In the case here we have 21 data
#points (from -1 V to +1 V in 0.1 V steps) so we need to repeat this 21 times.
#and that's it. We can now plot the data or take a fourier transform or do
#anything we like - the possibilities are endless.
Where is the full list of available commands.
Click here to view the X100 command list and descriptions.
Open Source Components
All of the X100 demo software is open source and freely downloadable from the Xtralien website. Feel free to dive in and make your own modifications.