element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Test & Tools
  • Technologies
  • More
Test & Tools
Blog Programmable Electronic Load - Java GUI Part 2: Support for Current Mode, Input On/Off, Error Log
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Test & Tools to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 6 Jul 2019 1:47 PM Date Created
  • Views 1800 views
  • Likes 6 likes
  • Comments 7 comments
  • swing
  • scpi
  • cross_platform
  • dc_load
  • java
Related
Recommended

Programmable Electronic Load - Java GUI Part 2: Support for Current Mode, Input On/Off, Error Log

Jan Cumps
Jan Cumps
6 Jul 2019

I'm building a GUI for the electronic load we made here on element14.

The development will be in a few incremental steps. This is the second iteration:

  • add error logging
  • make the LCD display emulation work
  • a few dedicated controls to set current and enable / disable input

image

 

Retrieve Instrument Status: Multiple SCPI Commands Combined

 

The screen refreshes the GUI controls based on the instrument status.

  • LCD display displays mode, set current, measured current and voltage, input on/off status.
  • "Load Active" checkbox reflects the current status of the input (you can also change the status with it.
  • Errors button shows the number of errors captured by the instrument. If there are unretrieved errors, it shows the count and turns red.

 

There are a number of SCPI commands required to get that info.

To avoid many back-and forths, and to minimise the time that the instrument is locked for other SCPI commands, all queries are combined in a composite SCPI statement.

INP?;FUNC?;CURR?;:MEAS:CURR:DC?;:MEAS:VOLT:DC?;:SYST:ERR:COUNT?

 

    //Handle timer event.
    @Override
    public void actionPerformed(ActionEvent e) {

        // get info - as much as we can together
        String s;
        s = ("INP?;FUNC?;CURR?;:MEAS:CURR:DC?;:MEAS:VOLT:DC?;:SYST:ERR:COUNT?\n");
        synchronized (instrument) {
            instrument.write(s);
            s = instrument.read();
        }

        // parse
        StringTokenizer tokenizer = new StringTokenizer(s, ";");

        // input
        if (tokenizer.hasMoreTokens()) {

 

Each command is separated by a semicolon, as specified by the SCPI standard. The eLoad understands this and can handle it.

Then I use a tokeniser to split the reply in its components.

The result string also separates the data by semicolon. A tokeniser is a convenient way to break these up into individual values.

 

All values are then gathered in a dedicated object to capture latest status

 

public class RefreshData {
    public boolean bActive;
    public String sMode;
    public String sSetValue;
    public String sI;
    public String sV;
    public String sW;
    public String sR;
    public String sErrCount;
}

 

 

       // input
        if (tokenizer.hasMoreTokens()) {
            refreshData.bActive = tokenizer.nextToken().startsWith("1");
        }
        // mode
        if (tokenizer.hasMoreTokens()) {
            refreshData.sMode = tokenizer.nextToken().replace("\"", "");
        }
        // set value
        if (tokenizer.hasMoreTokens()) {
            refreshData.sSetValue = tokenizer.nextToken().replace("\n", "");
        }
        // measured current
        if (tokenizer.hasMoreTokens()) {
            refreshData.sI = tokenizer.nextToken().replace("\n", "");
        }
        // measured voltage
        if (tokenizer.hasMoreTokens()) {
            refreshData.sV = tokenizer.nextToken().replace("\n", "");
        }
        // set error count
        if (tokenizer.hasMoreTokens()) {
            refreshData.sErrCount = tokenizer.nextToken().replace("\n", "");
        }

 

Then the GUI components are updated.

 

        // update LCD display
        jTextAreaLCD.setText("mode: "
                + (String) (refreshData.sMode.startsWith("CURRent") ? "I" : "*ERROR*")
                + " "
                + refreshData.sSetValue
                + "\nI: " + refreshData.sI + "\nV: " + refreshData.sV
                + "\nInput: O"
                + (String) (refreshData.bActive ? "n " : "ff"));


        // update Input Active control
        jCheckBoxInputActive.setSelected(refreshData.bActive);


        // update error count
        jButtonSCPIErrorClear.setText("Errors: " + refreshData.sErrCount);
        if (refreshData.sErrCount.startsWith("0")) {
            jButtonSCPIErrorClear.setBackground(Color.green);
        } else {
            jButtonSCPIErrorClear.setBackground(Color.red);
        }

 

Timed Status Refresh

 

I use a Swing timer to retrieve the values and update the controls. If a timed action updates graphic portions, it's preferred to use the Swing timer.

It works well with the Swing threading model.

 

The timer uses the main application frame as its parent. For that, the frame's declaration needs to be modified to flag that it implement's the interface that the timer uses to wake it up.

 

public class MainFrame extends javax.swing.JFrame implements ActionListener {

// ....

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
        initTimer();
    }

    private void initTimer() {
        timer = new Timer(100, this);
        timer.setInitialDelay(900);
        timer.start();
    }

 

When the timer kicks in, it'll call our frame's actionPerformed method (the one shown in the previous section)

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Switch Load Input On and Off

 

There's a checkbox that you can use to enable and disable the load.

In the first section you saw that it shows the current state of the device.

But it's an active control. By checking and unchecking it, you control the instrument's output.

You'll also see this reflected in the LCD display (after the next timer event).

 

    private void jCheckBoxInputActiveActionPerformed(java.awt.event.ActionEvent evt) {                                                     
        String s;
        s = "INP " + (jCheckBoxInputActive.isSelected() ? "ON\n" : "OFF\n");
        synchronized (instrument) {
            instrument.write(s);
        }
    }

 

Error Handling

 

Each refresh, the timer checks if there are errors logged on the instrument.

If not, it colours the Error button green and labels it with "Errors: 0".

If there are errors, the button colours red and the number of errors are shown.

image

You can click the red button to retrieve the error messages into the log.

image

Upon that action, the button turns green again and shows "Errors: 0".

That's because the action of retrieving an error removes it from the instrument.

We retrieve all errors, so the backlog is clean.

Clicking that green button clears the error log on screen.

 

How can you get errors when using the GUI:

  • enter an invalid value for the constant current (a character, an under/overflow)
  • enter a wrong or unsupported SCPI command in the SCPI tab (the log shows different messages for wrong vs. unsupported)

 

TAB for Constant Current Controls and SCPI Command Prompt

 

To avoid clutter, and to present a simple interface by default, I used a TAB control where you can switch between Constant Current and SCPI control.

 

image

You can mix and match the two ways of controlling. The instrument doesn't know whether you used a button or typed a command .

Neither does the interface, once you did the action.

So there are no side effects (except when you use the debug level :DEVELOP: SCPI commands to directly control the DACs).

 

Minor improvement: when you press enter in an edit box, it performs the same task as the Send button next to it.

It avoids that you have to switch between keyboard and mouse.

I've used this application extensively today and it does the job. That was the objective set at the start.

NetBeans project is attached. The code is also on GitHub: https://github.com/jancumps/eLoadGui.

You need to use the latest firmware for the eload, available on the project start page.

 

There's also a distro attached, ready to run with dependencies included. It has a batch file for Linux and Windows.

You need to adjust the COM port to the one the instrument is using. For Linux, make the batch file executable.

 

 

Related Blog
Programmable Electronic Load
Programmable Electronic Load - Java GUI Part 1: Basic Functionality
Programmable Electronic Load - Java GUI Part 2: Support for Current Mode, Input On/Off, Error Log
Attachments:
eLoad_20190706.zip
distro.zip
  • Sign in to reply

Top Comments

  • DAB
    DAB over 5 years ago +2
    Nice update. DAB
  • Andrew J
    Andrew J over 5 years ago +2
    Looking good, following with interest
  • genebren
    genebren over 5 years ago +2
    Jan, Nice update. I really like the command strings that you are using ( INP?;FUNC?;CURR?;:MEAS:CURR:DC?;:MEAS:VOLT:DC?;:SYST:ERR:COUNT? ). This really brings me back to the mid 70's when I first starting…
  • Jan Cumps
    Jan Cumps over 5 years ago

    I've uploaded the project to github: https://github.com/jancumps/eLoadGui

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • weiwei2
    weiwei2 over 5 years ago

    I am also following with interest image

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago in reply to genebren

    Yes, what we do for testing hasn't changed a lot. How it's done has.

    We're still setting up the device, provide stimulation input, simulate some modules or functions and validate the outputs.

     

    Tools with workflow support, like LabVIEW, have made the process easier (in my opinion. many people think it didn't).

    Standardised or industry accepted languages and test engines have helped change some mindsets.

    I tried to make the load testable from various angles.

    • The firmware software is test friendly. All modules (ADC, DAC, Display, control engine) are modular, called via API and can be replaced by a simulator.
    • SCPI commands provided to validate and control the lowest levels of the firmware.
    • The GUI can be tested either by a JUnit test bench or via a serial communication emulating test bed.

     

    I have a legacy for this in my professional life as developer.

    I created this open source project in the early 00's: Home | JUnit PDF Report  and delivered automated testing for our ERP reporting modules and e-commerce interfaces.

     

     

    (edit: and this module to verify Oracle Financials Apps custom developments: Home | Apps Unit  - 2006. getting old.)

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 5 years ago

    I've attached a ready-to-run distro with dependency libs and batch files included for Linux and Window.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 5 years ago

    Jan,

     

    Nice update.  I really like the command strings that you are using (INP?;FUNC?;CURR?;:MEAS:CURR:DC?;:MEAS:VOLT:DC?;:SYST:ERR:COUNT?). This really brings me back to the mid 70's when I first starting working with automated test equipment (ATE) systems.  We used a language (ATLAS) that was written in natural language that could be run by a test system or by a technician, using statements like "Measure Voltage, DC signal, ...".  The parsing of the language was not too difficult, as there were a limited number of verb (measure), nouns (voltage) and adjectives (DC signal). 

     

    Keep up the good work!

    Gene

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube