ねえ、シリアルデータを読み込んでグラフに表示するプログラムをやっています。Java プロジェクトには 2 つのファイルがあります。1 つはグラフ表示を処理し、もう 1 つはシリアル処理専用です。このプログラムの要件の 1 つは、arduino の送信データを切断し、グラフにメッセージを表示し、arduino を再接続してから、そのメッセージを消し、ユーザーの操作なしでデータを再送信することです。下にシリアルファイルがあります。それを編集して PC から切断されたことを確認し、人間の介入なしに再接続する方法がわかりません。ありがとう
public class SerialTest implements SerialPortEventListener {
SerialPort serialPort;
private static final String PORT_NAMES[] = { 
        "COM11", // Windows
};
String turnon = "X";
String inputLine;
String temp;
String temp1;
String thirdDC;
static boolean deviceConn;
int value = 0;
int count;
String stop = "STOP";
String y = "Y";
String z = "Z";
String pop;
Double x;
int n;
int working;
private BufferedReader input;
/** The output stream to the port */
OutputStream output;
/** Milliseconds to block while waiting for port open */
private static final int TIME_OUT = 2000;
/** Default bits per second for COM port. */
private static final int DATA_RATE = 9600;
public void initialize() {
    working = 1;
    CommPortIdentifier portId = null;
    Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
    while (portEnum.hasMoreElements()) {
        CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
        for (String portName : PORT_NAMES) {
            if (currPortId.getName().equals(portName)) {
                portId = currPortId;
                break;
            }
        }
    }
    if (portId == null) {
        thirdDC = "Could not find COM Port. Error";
        System.out.println(thirdDC);
        return;
    }
    try {
        serialPort = (SerialPort) portId.open(this.getClass().getName(),
                TIME_OUT);
        serialPort.setSerialPortParams(DATA_RATE,
                SerialPort.DATABITS_8,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);
        input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
        output = serialPort.getOutputStream();
        serialPort.addEventListener(this);
        serialPort.notifyOnDataAvailable(true);
    } catch (Exception e) {
        System.err.println(e.toString() + "BLAHHHHH");
    }
}
public synchronized void close() {
    if (serialPort != null) {
        serialPort.removeEventListener();
        serialPort.close();
    }
}
public synchronized void serialEvent(SerialPortEvent oEvent) {
    String stop = "ERROR";
    if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
        deviceConn = true;
        try {
            inputLine=input.readLine();
            if (inputLine.equals(y)){
                System.out.println(y);
                temp1 = "OFF";
                value = 0;
            }
            if (inputLine.equals(z)){
                System.out.println(z);
                temp1 = "ON";
                value = 0;
            }
            if (inputLine.equals(stop)){
                System.out.println(stop);
                temp = "ERROR";
                value = 1;  
            }
            x = Double.parseDouble(inputLine);
            if (x > 0){
            temp = inputLine;
            System.out.println(x);
            value = 0;
            }
        } catch (Exception e) {                             
        }
    }           
    }
public static void main(String[] args) throws Exception {
    Thread t=new Thread() {
        public void run() {
            try {
                Thread.sleep(1000);
        } 
            catch (InterruptedException ie) {}
        }
    };
    t.start();
    System.out.println("Started");
}
}