Click here to Skip to main content
15,884,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

2020.2.2\lib\idea_rt.jar=51870:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.2\bin" -Dfile.encoding=UTF-8 -classpath D:\MisDesarrollos\Java\RS232-jssc\out\production\RS232-jssc;D:\MisDesarrollos\Java\RS232-jssc\lib\jssc-2.8.0.jar com.rdm.Main COM3
Opening port COM3 ...
#
# 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

What I have tried:

== MAIN.JAVA ====================================================================
Java
package com.rdm;
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);
        }

    }
}

== PORTREADER.JAVA ==============================================================
Java
package com.rdm;
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);
            }
        }
    }
}
Posted
Updated 13-Oct-20 22:14pm
v2
Comments
Richard MacCutchan 14-Oct-20 4:21am    
It may be that you do not have permission to access the COM3 port. However the information provided is not enough to do more than guess.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900