# Xtralien Scientific Python: Taking Measurements Using The X100

There are several ways of performing measurements using the the Xtralien X100 Source Measure Unit. In Xtralien Scientific Python, we use four basic commands: `measurei`, `measurev`,`measure` and `oneshot`.

## Example Code

This example code demonstrates the use of all four measurement commands:

``````from xtralien import *### 1. Connect  ###
with X100.USB('COM12') as Dev1: # Connect to the Device via USB

### 2. Turn on SMU (X200 only) ###
Dev1.smu1.set.enabled(1, response=0) # Turn SMU on

### 3. Measure Current ###
measuredi = Dev1.smu1.measurei() # Take a current measurement
print('Measured Current is ',measuredi,' A')

### 4. Measure Voltage ###
measuredv = Dev1.smu1.measurev() # Take a Voltage measurement
print('Measured Voltage is ',measuredv,' V')

### 5. Measure Voltage and Current ###
vandi = Dev1.smu1.measure() # Take a measurement of both voltage and current
print('Measured Voltage and Current are ',vandi, ' and ',vandi)

### 6. Set Voltage, Measure Voltage and Current ###
vandi = Dev1.smu1.oneshot(2) # Take a measurement of both voltage and current
print('Measured Voltage and Current are ',vandi, ' and ',vandi)
``````

This code prints the result:

``````Measured Current is  1.57e-06  A
Measured Voltage is  0.00  V
Measured Voltage and Current are  0.00  and  1.64e-06
Measured Voltage and Current are  2.00  and  1.49e-06
``````

## Code Breakdown

### 1. Connect

``````with X100.USB('COM1') as Dev1: # Connect to the Device via USB
``````

Here we connect to an Xtralien X100 over USB, using `COM` port 1. This process is covered in our tutorial on Communicating With The X100.

### 2. Turn on SMU (X200 Only)

``Dev1.smu1.set.enabled(1, response=0)``

Our latest Source Measure Unit (the X200) allows the user to turn the SMUs on and off. This means that we need to turn the SMU on before we can take measurements.

• `Dev1` is the name that we gave to the X100 in section 1.
• `smu1` determines which of the two on-board source measure units (SMUs) we want to measure.

### 3. `measurei` (Measure Current)

``````    current = Dev1.smu1.measurei() # Take a current measurement
print('Measured Current is ',current,' A')
``````
• `measurei` tells the board to take a current measurement and return a string in the scientific notation format. This string is within a list with only one entry.
• We use `` to change the number from a list format to a double.

We create a variable named `current` and assign the measured value to it. We then use the `print` command to display it along with some text

### 4. `measurev` (Measure Voltage)

``````    voltage = Dev1.smu1.measurev() # Take a Voltage measurement
print('Measured Voltage is ',voltage,' V')
``````

This is similar process to the measurei `command`, only this time we are measuring voltage using the `measurev` command.

### 5. `measure` (Measure Voltage and Current)

``````    vandi = Dev1.smu1.measure() # Take a measurement of both current and voltage
print('Measured Voltage and Current are ',vandi, ' and ',vandi)
``````

Here we use the `measure` command without specifying i or v. This will take a measurement of both and return them in a list. To split the voltage and current values, we index the list using `` for the first value and `` for the second. For more information on lists, see our python list tutorial.

### 6. `oneshot` (Set Voltage, Measure Voltage and Current)

``````    vandi = Dev1.smu1.oneshot(2) # Take a measurement of both voltage and current
print('Measured Voltage and Current are ',vandi, ' and ',vandi)
``````

The `oneshot` command works in a similar way to the `measure` command, wherein both the voltage and current are returned. This command allows you to set a voltage at which to perform a measurement. The `oneshot(2)` command tells the X100 to output 2 V and measure the voltage and current. We then split these values from the returned list as explained in the section above.