Skip to content
William Wood edited this page Feb 22, 2024 · 8 revisions

Tables

One of the most obvious ways to display data is in the form of a table. JISA provides the means of doing this in a GUI in the form of the Table GUI element.

Contents

Creating a Table

Top ↑

To create a Table element you need simply instantiate a Table object:

Java

Table table = new Table("Title");

Kotlin

val table = Table("Title")

Python

table = Table("Title")

If you were to show this table element now:

table.show();

you will see a blank box:

this is because the table has no contents

Adding Data to a Table

Top ↑

The Table element is designed to display the contents of a ResultTable object. Thus, after creating a table you can make it show this data by use of:

ResultTable results = new ResultList(...);
table.watchList(results);

or by specifying the ResultTable upon instantiation like so:


Java

ResultTable results = new ResultList(...);
Table       table   = new Table("Title", results);

Kotlin

val results = ResultList(...)
val table   = Table("Title", results)

Python

results = ResultList(...)
table   = Table("Title", results)

this will result in the table's columns now being visible:

Now the Table will show the live contents of the ResultTable object, automatically updating every time new data is added.

For example:


Java

ResultTable tData = new ResultList("X", "Y");
Table       table = new Table("Example", tData);

table.show();

for (double x : Range.linear(0, 10)) {
    tData.addData(x, 10.0*x);
}

Kotlin

val tData = ResultList("X", "Y")
val table = Table("Example", tData)

table.show()

for (x in Range.linear(0, 10)) {
    tData.addData(x, 10.0*x)
}

Python

tData = ResultList("X", "Y")
table = Table("Example", tData)

table.show()

for x in Range.linear(0, 10):
    tData.addData(x, 10.0*x)

will result in:

Full Example

Top ↑

Java

import jisa.gui.GUI;
import jisa.gui.Table;
import jisa.results.*;
import jisa.addresses.USBTMCAddress;
import jisa.devices.smu.K2450;
import jisa.maths.Range;
import jisa.Util;
import java.lang.Exception;

public class Main {

    public static void main(String[] args) {

        Column<Double> V = Column.ofDoubles("Voltage", "V");
        Column<Double> I = Column.ofDoubles("Current", "A");
        Column<Double> P = Column.ofDoubles("Power", "W");
        Column<Double> R = Column.ofDoubles("Resistance", "Ohm");

        ResultList results = new ResultList(V, I, P, R);
        Table      table   = new Table("Results", results);

        table.setExitOnClose(true);
        table.show();

        try {
            
            K2450 smu = new K2450(new USBTMCAddress(0x05E6, 0x2450, "57463"));

            smu.turnOn();
            
            for (double v : Range.linear(0, 60)) {

                smu.setVoltage(v);

                Util.sleep(500);

                results.addRow(() -> {
                    row.set(V, smu.getVoltage());
                    row.set(I, smu.getCurrent());
                    row.set(P, smu.getVoltage() * smu.getCurrent());
                    row.set(R, smu.getVoltage() / smu.getCurrent());
                });

            }
            
            smu.turnOff();

        } catch (Exception e) {

            GUI.showException(e);
            System.exit(0);

        }


    }

}

Kotlin

import jisa.gui.GUI
import jisa.gui.Table
import jisa.results.*
import jisa.addresses.USBTMCAddress
import jisa.devices.smu.K2450
import jisa.maths.Range
import jisa.Util
import java.lang.Exception

fun main() {

    val V = Column.ofDoubles("Voltage", "V")
    val I = Column.ofDoubles("Current", "A")
    val P = Column.ofDoubles("Power", "W")
    val R = Column.ofDoubles("Resistance", "Ohm")

    val results = new ResultList(V, I, P, R)
    val table   = new Table("Results", results)

    table.setExitOnClose(true)
    table.show()

    try {
            
        val smu = K2450(USBTMCAddress(0x05E6, 0x2450, "57463"))

        smu.turnOn()
        
        for (v in Range.linear(0, 60)) {

            smu.voltage = v

            Util.sleep(500)

            results.addRow {
                it[V] = smu.voltage,
                it[I] = smu.current,
                it[P] = smu.voltage * smu.current,
                it[R] = smu.voltage / smu.current
            }

        }
        
        smu.turnOff()

    } catch (e: Exception) {

        GUI.showException(e)
        exitProcess(0)

    }

}

Python

import pyjisa; pyjisa.load();

from jisa.gui import GUI, Table
from jisa.results import ResultList, Column
from jisa.addresses import USBTMCAddress
from jisa.devices.smu import K2450
from jisa.maths import Range
from jisa import Util
from java.lang import Exception

def main():
    
    V = Column.ofDoubles("Voltage", "V")
    I = Column.ofDoubles("Current", "A")
    P = Column.ofDoubles("Power", "W")
    R = Column.ofDoubles("Resistance", "Ohm")

    results = ResultList(V, I, P, R)
    table   = Table("Results", results)

    table.setExitOnClose(True)
    table.show()

    try:
            
        smu = K2450(USBTMCAddress(0x05E6, 0x2450, "57463"))

        smu.turnOn()
        
        for v in Range.linear(0, 60):

            smu.setVoltage(v)

            Util.sleep(500)

            results.mapRow({
                V: smu.getVoltage(),
                I: smu.getCurrent(),
                P: smu.getVoltage() * smu.getCurrent(),
                R: smu.getVoltage() / smu.getCurrent()
            })

        
        smu.turnOff()

    except Exception as e:

        GUI.showException(e)
        exit()



main()
GUI.waitForExit()

Which results in the following:

Clone this wiki locally