JRE crash in Java serial app with JSSC in W10 enviroment

1.3k views Asked by At

I'm new to Java and when trying to run the following code with jssc-2.8.0 library, at the "serialPort.openPort()" method the IntelliJ IDE crashes and reports:

A fatal error has been detected by the Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007110b5db, pid=11596, tid=5204

JRE version: Java(TM) SE Runtime Environment (14.0.2+12) (build 14.0.2+12-46) Java VM: Java HotSpot(TM) 64-Bit Server VM (14.0.2+12-46, mixed mode, sharing, tiered, compressed oops, g1 gc, windows-amd64) Problematic frame: C [jSSC-2.8_x86_64.dll+0xb5db]

No core dump will be written. Minidumps are not enabled by default on client versions of Windows

An error report file with more information is saved as: D:\MisDesarrollos\Java\RS232-jssc\hs_err_pid11596.log

If you would like to submit a bug report, please visit: https://bugreport.java.com/bugreport/crash.jsp The crash happened outside the Java Virtual Machine in native code. See problematic frame for where to report the bug.

Process finished with exit code 1

Source code follows:

import jssc.*;

public class Main {

    public static void main(String[] args) {

        // Pass port number thru argument
        String port = args[0];

        SerialPort serialPort = new SerialPort(port);
        try {
            System.out.println("Opening port " + port + " ...");
            serialPort.openPort();

            serialPort.setParams(SerialPort.BAUDRATE_9600,
                    SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);
            serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT);

            serialPort.writeString("COM3 opened !!!");

            PortReader portReader = new PortReader(serialPort);

            serialPort.addEventListener(portReader, SerialPort.MASK_RXCHAR);

            serialPort.closePort();
        } catch (Exception e) {
            System.out.println("There are an error on writing string to port т: " + e);
        }
    }
}


import jssc.*;

public class PortReader implements SerialPortEventListener {
    
    SerialPort serialPort;
    public PortReader(SerialPort serialPort) {
        this.serialPort = serialPort;
    }

    @Override
    public void serialEvent(SerialPortEvent event) {
        System.out.println("started");
        if (event.isRXCHAR() && event.getEventValue() > 0) {
            try {
                String receivedData = serialPort.readString(event.getEventValue());
                System.out.println("Received response: " + receivedData);
            } catch (SerialPortException ex) {
                System.out.println("Error in receiving string from COM-port: " + ex);
            }
        }
    }
}
0

There are 0 answers