0

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);
            }
        }
    }
}
rmattos
  • 1
  • 2
  • can you paste the contents of D:\MisDesarrollos\Java\RS232-jssc\hs_err_pid11596.log – pradosh nair Oct 14 '20 at 01:28
  • By the way, why is `closePort()` done? So even if the crash doesn't happen, nothing works? However, in this article, it seems that the same process did not cause a crash. How about comparing if there are any differences? [how to read data frome serialport using jssc in java?](https://stackoverflow.com/q/36951451/9014308) – kunif Oct 14 '20 at 07:58
  • Does it crash if you run it outside IDE? – y.bedrov Oct 14 '20 at 11:16
  • @pradoshnair cannot append it to the body because of file size ... how can I send this log file to you? – rmattos Oct 15 '20 at 00:59
  • @kunif closeport() is not reached ... it crashes at its very begining at the SerialPort.openPort() line. I've also tried the example in that article and it also crashes – rmattos Oct 15 '20 at 01:01
  • 1
    It is said that the crash in JDK11 was fixed in the previous version, so it may crash in JDK14. Why not search for Issues, change the JDK version to 11, or change jssc to the latest version, 2.9.2? [java-native/jssc releases](https://github.com/java-native/jssc/releases) – kunif Oct 15 '20 at 01:14

0 Answers0