0

我一直在尝试许多不同的方法来完成这项工作,但都无法做到。它的作用是:程序从 STARTUP 开始运行良好,并等待用户输入和其他内容。然后它调用这个:

new Coil_Testing(option);

这将我们的线程移动到一个新类(Coil_Testing)。在这个类中,它将运行测试,在设置我的设备并连接到它们之后,它将启动 GUI(appChart)。这显示了测试进行时的实时信息图。测试将按原样运行并正常工作。完成测试后,我调用 chart.close() ,这是我自己的方法,它应该但不会清除图表的线程和/或内存。

因此,下次我在不终止程序的情况下运行测试时,它会在调用 shell.open() 时给我一个线程错误。

线程“Thread-2”java.lang.IllegalArgumentException 中的异常:参数无效

我这样做是因为我通常有很多测试背靠背排列,并且不需要一遍又一遍地重新打开程序会很好。

“Shell Sleep”消息位于 show() 方法末尾的 appChart 中。


终端输出

<Blank Space>

===========CONTACTOR INFO==========
 1:                  Contactor: 700S-DCP71020Z24 E
 2:                  Date Code: 1423 (Jun 2 - Jun 8)
 3:                       Coil: PD714
 4:                    Voltage: 24VDC
 5:                      Hertz: DC
 6:           Contactor Number: TEST
 7:                    Comment: TEST
=============TEST SETUP===========
 8:               Voltage Type: DC
 9:           Number Of Cycles: 3
10:            Cycle Time (ms): 0
11:           Toggle Test Type: Cold
12:  Hot Coil Refresh Time (M): 5
13:               Toggle Email: FALSE
14:                     PLC IP: 192.168.1.10    Port: 502   
15:      Digital Multimeter IP: 192.168.1.12    Port: 5025  
16:             Ocilloscope IP: 192.168.1.13    Port: 5025  
17:     TEST DEVICE CONNECTIONS
18:                 SETUP EMAIL
19:            Folder Location: C:\Users\<NAME>\Documents\TEST RESULTS FOLDER\Coil Testing
99:                EXIT PROGRAM
Type 1 - 19 to edit or 0 to continue 0

<Blank Space>

Please check setup and unpause the test.
Max Current Found: 0.326633

Cycle 1 out of 3 ... Retries: 0
Scope Single Ready!
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Voltage: 24.3465642
Frequency: 0.0
Getting Oscilloscope Data
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Got 7680 of information per pole.
Now Analyzing Close Time and Bounce Time.
Close times: 55.83ms .. 55.73ms .. 55.57ms
Bounce times: 0.00ms .. 0.00ms .. 0.00ms
Max Current: 0.50A
Min Current: -0.03A
Seal Current: 0.47A
Form Factor: 1.00
Shell Sleep
Scope Single Ready!
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Open times: 13.96ms .. 14.43ms .. 14.79ms
Reading Resistance
Resistance: 50.31
Cycle Time: 8491



Cycle 2 out of 3 ... Retries: 0
Shell Sleep
Scope Single Ready!
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Voltage: 24.4384331
Frequency: 0.0
Getting Oscilloscope Data
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Got 7680 of information per pole.
Now Analyzing Close Time and Bounce Time.
Close times: 55.42ms .. 55.10ms .. 54.95ms
Bounce times: 0.00ms .. 0.10ms .. 0.05ms
Max Current: 0.50A
Min Current: -0.02A
Seal Current: 0.47A
Form Factor: 1.00
Scope Single Ready!
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Open times: 10.31ms .. 10.73ms .. 11.15ms
Reading Resistance
Resistance: 50.30
Cycle Time: 8493



Cycle 3 out of 3 ... Retries: 0
Scope Single Ready!
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Voltage: 24.3477854
Frequency: 0.0
Getting Oscilloscope Data
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Got 7680 of information per pole.
Now Analyzing Close Time and Bounce Time.
Close times: 55.99ms .. 55.78ms .. 55.52ms
Bounce times: 0.00ms .. 0.00ms .. 0.00ms
Max Current: 0.50A
Min Current: -0.02A
Seal Current: 0.47A
Form Factor: 1.00
Scope Single Ready!
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Open times: 10.05ms .. 10.47ms .. 10.94ms
Reading Resistance
Shell Sleep
Resistance: 50.36
Cycle Time: 8288


Saving output file to C:\Users\<NAME>\Documents\TEST RESULTS FOLDER\Coil Testing\11-13-2015_14-29-15.xlsx
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Shell Sleep
Writing to INFORMATION
Writing CycleNum to each sheets.
Writing to CLOSE TIME
    L1
    L2
    L3
Writing to BOUNCE TIME
    L1
    L2
    L3
Writing to OPEN TIME
    L1
    L2
    L3
Writing to CURRENT
Writing to COIL INFO
    Resistance
    Voltage
Writing to RETRY SHEET
Shell Sleep
Shell Sleep

<Blank Space>

Shell Sleep
===========CONTACTOR INFO==========
 1:                  Contactor: 700S-DCP71020Z24 E
 2:                  Date Code: 1423 (Jun 2 - Jun 8)
 3:                       Coil: PD714
 4:                    Voltage: 24VDC
 5:                      Hertz: DC
 6:           Contactor Number: TEST
 7:                    Comment: TEST
=============TEST SETUP===========
 8:               Voltage Type: DC
 9:           Number Of Cycles: 3
10:            Cycle Time (ms): 0
11:           Toggle Test Type: Cold
12:  Hot Coil Refresh Time (M): 5
13:               Toggle Email: FALSE
14:                     PLC IP: 192.168.1.10    Port: 502   Valid
15:      Digital Multimeter IP: 192.168.1.12    Port: 5025  Valid
16:             Ocilloscope IP: 192.168.1.13    Port: 5025  Valid
17:     TEST DEVICE CONNECTIONS
18:                 SETUP EMAIL
19:            Folder Location: C:\Users\<Name>\Documents\TEST RESULTS FOLDER\Coil Testing
99:                EXIT PROGRAM
Type 1 - 19 to edit or 0 to continue Shell Sleep
Shell Sleep
Shell Sleep
0

<Blank Space>

Please check setup and unpause the test.
Max Current Found: 0.326633

Cycle 1 out of 3 ... Retries: 0
Exception in thread "Thread-2" java.lang.IllegalArgumentException: Argument not valid
    at org.eclipse.swt.SWT.error(Unknown Source)
    at org.eclipse.swt.SWT.error(Unknown Source)
    at org.eclipse.swt.SWT.error(Unknown Source)
    at org.eclipse.swt.graphics.GC.setFont(Unknown Source)
    at org.swtchart.internal.axis.AxisTickLabels.drawXTick(AxisTickLabels.java:906)
    at org.swtchart.internal.axis.AxisTickLabels.paintControl(AxisTickLabels.java:887)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
    at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Display.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
    at org.eclipse.swt.widgets.Composite.WM_PAINT(Unknown Source)
    at org.eclipse.swt.widgets.Control.windowProc(Unknown Source)
    at org.eclipse.swt.widgets.Display.windowProc(Unknown Source)
    at org.eclipse.swt.internal.win32.OS.UpdateWindow(Native Method)
    at org.eclipse.swt.widgets.Decorations.setVisible(Unknown Source)
    at org.eclipse.swt.widgets.Shell.setVisible(Unknown Source)
    at org.eclipse.swt.widgets.Shell.open(Unknown Source)
    at coil_test.appChart.show(appChart.java:82)
    at coil_test.Coil_Testing$1.run(Coil_Testing.java:182)
Scope Single Ready!

类应用图表

package coil_test;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.swtchart.Chart;
import org.swtchart.ILineSeries;
import org.swtchart.ILineSeries.PlotSymbolType;
import org.swtchart.ISeries.SeriesType;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;

public class appChart {

    protected Display display;
    protected Shell shell;
    private Chart closeChart;
    private double[][] arrClose; //Poles | Data
    private ILineSeries closeL1;
    private ILineSeries closeL2;
    private ILineSeries closeL3;
    private Chart bounceChart;
    private double[][] arrBounce;
    private ILineSeries bounceL1;
    private ILineSeries bounceL2;
    private ILineSeries bounceL3;
    private Chart openChart;
    private double[][] arrOpen;
    private ILineSeries openL1;
    private ILineSeries openL2;
    private ILineSeries openL3;
    private Chart currentChart;
    private double[][] arrCurrent;
    private ILineSeries inrush;
    private ILineSeries seal;
    private double[] arrCycle;
    private boolean updateRequired = false;
    private boolean closeRequired = false;
    private boolean run;

    /**
     * Launch the application.
     * @param args
     */
    public static void main(String[] args) {
        try {
            appChart window = new appChart();
            window.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Open the window.
     */
    public appChart() {
        /*Display display = Display.getDefault();

        createContents();
        shell.open();
        shell.layout();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }*/
    }

    public void show(){
        display = Display.getDefault();

        createContents();
        shell.open();
        shell.layout();

        Thread thread = new Thread(new Runnable() {
            public void run() {
                run = true;
                while (run) {
                    try { Thread.sleep(1000); } catch (Exception e) { }
                    Display.getDefault().syncExec(new Runnable() {
                        public void run() {
                            if(updateRequired){
                                closeChart.update();
                                bounceChart.update();
                                openChart.update();
                                currentChart.update();

                                closeChart.redraw();
                                bounceChart.redraw();
                                openChart.redraw();
                                currentChart.redraw();

                                closeChart.getAxisSet().adjustRange();
                                bounceChart.getAxisSet().adjustRange();
                                openChart.getAxisSet().adjustRange();
                                currentChart.getAxisSet().adjustRange();

                                updateRequired = false;
                            }
                            if(closeRequired){
                                shell.close();
                                shell.dispose();
                                Display.getDefault().close();
                                run = false;
                                closeRequired = false;
                            }
                        }
                    });
                }
            }
        });
        thread.start();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
            try {
                Thread.sleep(50);
                System.out.println("Shell Sleep");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        thread = null;
    }

    /**
     * Create contents of the window.
     */
    private void createContents() {
        shell = new Shell(SWT.NO_TRIM); // SWT.NO_TRIM | SWT.ON_TOP
        shell.setSize(1280,1024);
        shell.setLocation(1281,0);
        shell.setLayout(null);
        shell.setMinimumSize(1280, 1024);

        closeChart = new Chart(shell, SWT.NONE);
        closeChart.setBounds(0, 0, 1264, 256);
        closeChart.getAxisSet().getXAxis(0).getTitle().setText("");
        closeChart.getAxisSet().getYAxis(0).getTitle().setText("Time (ms)");
        closeChart.getTitle().setText("CLOSE TIME");
        closeL1 = (ILineSeries)closeChart.getSeriesSet().createSeries(SeriesType.LINE, "--L1--");
        closeL1.setLineColor(new Color(Display.getDefault(), 255, 0, 0));
        closeL1.setSymbolType(PlotSymbolType.NONE);
        closeL2 = (ILineSeries)closeChart.getSeriesSet().createSeries(SeriesType.LINE, "--L2--");
        closeL2.setLineColor(new Color(Display.getDefault(), 0, 255, 0));
        closeL2.setSymbolType(PlotSymbolType.NONE);
        closeL3 = (ILineSeries)closeChart.getSeriesSet().createSeries(SeriesType.LINE, "--L3--");
        closeL3.setLineColor(new Color(Display.getDefault(), 0, 0, 255));
        closeL3.setSymbolType(PlotSymbolType.NONE);

        bounceChart = new Chart(shell, SWT.NONE);
        bounceChart.setBounds(0, 256, 1264, 256);
        bounceChart.getAxisSet().getXAxis(0).getTitle().setText("");
        bounceChart.getAxisSet().getYAxis(0).getTitle().setText("Time (ms)");
        bounceChart.getTitle().setText("BOUNCE TIME");
        bounceL1 = (ILineSeries)bounceChart.getSeriesSet().createSeries(SeriesType.LINE, "--L1--");
        bounceL1.setLineColor(new Color(Display.getDefault(), 255, 0, 0));
        bounceL1.setSymbolType(PlotSymbolType.NONE);
        bounceL2 = (ILineSeries)bounceChart.getSeriesSet().createSeries(SeriesType.LINE, "--L2--");
        bounceL2.setLineColor(new Color(Display.getDefault(), 0, 255, 0));
        bounceL2.setSymbolType(PlotSymbolType.NONE);
        bounceL3 = (ILineSeries)bounceChart.getSeriesSet().createSeries(SeriesType.LINE, "--L3--");
        bounceL3.setLineColor(new Color(Display.getDefault(), 0, 0, 255));
        bounceL3.setSymbolType(PlotSymbolType.NONE);

        openChart = new Chart(shell, SWT.NONE);
        openChart.setBounds(0, 512, 1264, 256);
        openChart.getAxisSet().getXAxis(0).getTitle().setText("");
        openChart.getAxisSet().getYAxis(0).getTitle().setText("Time (ms)");
        openChart.getTitle().setText("OPEN TIME");
        openL1 = (ILineSeries)openChart.getSeriesSet().createSeries(SeriesType.LINE, "--L1--");
        openL1.setLineColor(new Color(Display.getDefault(), 255, 0, 0));
        openL1.setSymbolType(PlotSymbolType.NONE);
        openL2 = (ILineSeries)openChart.getSeriesSet().createSeries(SeriesType.LINE, "--L2--");
        openL2.setLineColor(new Color(Display.getDefault(), 0, 255, 0));
        openL2.setSymbolType(PlotSymbolType.NONE);
        openL3 = (ILineSeries)openChart.getSeriesSet().createSeries(SeriesType.LINE, "--L3--");
        openL3.setLineColor(new Color(Display.getDefault(), 0, 0, 255));
        openL3.setSymbolType(PlotSymbolType.NONE);

        currentChart = new Chart(shell, SWT.NONE);
        currentChart.setBounds(0, 768, 1264, 256);
        currentChart.getAxisSet().getXAxis(0).getTitle().setText("");
        currentChart.getAxisSet().getYAxis(0).getTitle().setText("Amps (A)");
        currentChart.getTitle().setText("CURRENT");
        inrush = (ILineSeries)currentChart.getSeriesSet().createSeries(SeriesType.LINE, "Inrush");
        inrush.setLineColor(new Color(Display.getDefault(), 255, 0, 0));
        inrush.setSymbolType(PlotSymbolType.NONE);
        seal = (ILineSeries)currentChart.getSeriesSet().createSeries(SeriesType.LINE, "Seal");
        seal.setLineColor(new Color(Display.getDefault(), 0, 255, 0));
        seal.setSymbolType(PlotSymbolType.NONE);

        arrCycle = new double[0];
        arrClose = new double[3][0];
        arrBounce = new double[3][0];
        arrOpen = new double[3][0];
        arrCurrent = new double[2][0];
    }

    public void updateClose(int cycle, double l1, double l2, double l3){
        double[][] temp = new double[3][cycle];
        for(int j = 0; j < 3; j++){
            for(int i = 0; i < cycle - 1; i++){
                temp[j][i] = arrClose[j][i];
            }
        }
        arrClose = temp;
        arrClose[0][cycle-1] = l1;
        arrClose[1][cycle-1] = l2;
        arrClose[2][cycle-1] = l3;

        updateChart();
    }

    public void updateBounce(int cycle, double l1, double l2, double l3){
        double[][] temp = new double[3][cycle];
        for(int j = 0; j < 3; j++){
            for(int i = 0; i < cycle - 1; i++){
                temp[j][i] = arrBounce[j][i];
            }
        }
        arrBounce = temp;
        arrBounce[0][cycle-1] = l1;
        arrBounce[1][cycle-1] = l2;
        arrBounce[2][cycle-1] = l3;

        updateChart();
    }

    public void updateOpen(int cycle, double l1, double l2, double l3){
        double[][] temp = new double[3][cycle];
        for(int j = 0; j < 3; j++){
            for(int i = 0; i < cycle - 1; i++){
                temp[j][i] = arrOpen[j][i];
            }
        }
        arrOpen = temp;
        arrOpen[0][cycle-1] = l1;
        arrOpen[1][cycle-1] = l2;
        arrOpen[2][cycle-1] = l3;

        updateChart();
    }

    public void updateCurrent(int cycle, double inrush, double seal){
        double[][] temp = new double[2][cycle];
        for(int j = 0; j < 2; j++){
            for(int i = 0; i < cycle - 1; i++){
                temp[j][i] = arrCurrent[j][i];
            }
        }

        arrCurrent = temp;
        arrCurrent[0][cycle-1] = inrush;
        arrCurrent[1][cycle-1] = seal;

        updateChart();
    }

    private void updateChart(){
        int cycleSize = arrCycle.length;
        if(cycleSize < arrClose[0].length || cycleSize < arrBounce[0].length || cycleSize < arrOpen[0].length || cycleSize < arrCurrent[0].length){
            cycleSize = Math.max(arrClose[0].length, arrBounce[0].length);
            cycleSize = Math.max(cycleSize, arrOpen[0].length);
            cycleSize = Math.max(cycleSize, arrCurrent[0].length);

            double[] temp = new double[cycleSize];
            for(int i = 0; i < cycleSize; i++){
                temp[i] = i+1;
            }
            arrCycle = temp;
        }

        closeL1.setYSeries(arrClose[0]);
        closeL2.setYSeries(arrClose[1]);
        closeL3.setYSeries(arrClose[2]);
        bounceL1.setYSeries(arrBounce[0]);
        bounceL2.setYSeries(arrBounce[1]);
        bounceL3.setYSeries(arrBounce[2]);
        openL1.setYSeries(arrOpen[0]);
        openL2.setYSeries(arrOpen[1]);
        openL3.setYSeries(arrOpen[2]);
        inrush.setYSeries(arrCurrent[0]);
        seal.setYSeries(arrCurrent[1]);

        closeL1.setXSeries(arrCycle);
        closeL2.setXSeries(arrCycle);
        closeL3.setXSeries(arrCycle);
        bounceL1.setXSeries(arrCycle);
        bounceL2.setXSeries(arrCycle);
        bounceL3.setXSeries(arrCycle);
        openL1.setXSeries(arrCycle);
        openL2.setXSeries(arrCycle);
        openL3.setXSeries(arrCycle);
        inrush.setXSeries(arrCycle);
        seal.setXSeries(arrCycle);

        updateRequired = true;

        /*
        closeChart.update();
        bounceChart.update();
        openChart.update();
        currentChart.update();
         */
    }

    public void close(){
        closeRequired = true;
    }
}

CLASS Coil_Testing

package coil_test;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import device_com.Device_Connection;
import device_com.Device_IO;
import device_com.Device_Utility;
import device_com.PLC_IO;
import device_com.PLC_Type_Enum.Variable_Type;
import email_user.Email_User;

public class Coil_Testing {

    private void test() throws IOException{
        <Setting Up Devices and Variables>

        Thread thread = new Thread(){
            public void run(){
                chart = new appChart();
                chart.show();
            }
        };
        thread.start();

        <Collect Data From Test And Update Chart>

        <Write To Excel>
        <Send Email>

        chart.close();
        thread = null;
    }

}
4

0 回答 0