当前位置: 首页 > 知识库问答 >
问题:

当Eclipse IDE与Arduino接口时,Java运行时环境::检测到一个致命错误

太叔炎彬
2023-03-14

我在Eclipse IDE与Arduino接口时遇到了麻烦。我已经完成了在Arduino和Eclipse IDE之间进行通信所必需的所有过程(例如安装rxtx.jar和构建路径,然后在Eclipse工作区文件夹中复制serial.dll和parallel.dll文件...)

我还检查了Arduino IDE和Eclipse代码中的Arduino COM端口配置。

    WARNING:  RXTX Version mismatch
    Jar version = RXTX-2.2pre1
    native lib Version = RXTX-2.2pre2
Started
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000180003990, pid=7556, tid=4696
#
# JRE version: Java(TM) SE Runtime Environment (9.0+11) (build 9.0.1+11)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (9.0.1+11, mixed mode, tiered, compressed oops, g1 gc, windows-amd64)
# Problematic frame:
# C  [rxtxSerial.dll+0x3990]
#
# 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:\Educational\Study\Softwares\JAVA\Eclipse EE Oxygen for Web Devlopers\workspace\RxTxDemo\hs_err_pid7556.log
#
# If you would like to submit a bug report, please visit:
#   http://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.
#
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import gnu.io.CommPortIdentifier; 
import gnu.io.SerialPort;
import gnu.io.SerialPortEvent; 
import gnu.io.SerialPortEventListener; 
import java.util.Enumeration;


public class SerialTest implements SerialPortEventListener {
    SerialPort serialPort;
        /** The port we're normally going to use. */
    private static final String PORT_NAMES[] = { 
            "/dev/tty.usbserial-A9007UX1", // Mac OS X
                        "/dev/ttyACM0", // Raspberry Pi
            "/dev/ttyUSB0", // Linux
            "COM5", // Windows
    };
    /**
    * A BufferedReader which will be fed by a InputStreamReader 
    * converting the bytes into characters 
    * making the displayed results codepage independent
    */
    private BufferedReader input;
    /** The output stream to the port */
    private 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() {
                // the next line is for Raspberry Pi and 
                // gets us into the while loop and was suggested here was suggested http://www.raspberrypi.org/phpBB3/viewtopic.php?f=81&t=32186
               // System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/ttyACM0");

        CommPortIdentifier portId = null;
        Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();

        //First, Find an instance of serial port as set in PORT_NAMES.
        while (portEnum.hasMoreElements()) {
            CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
            for (String portName : PORT_NAMES) {
                if (currPortId.getName().equals(portName)) {
                    portId = currPortId;
                    break;
                }
            }
        }
        if (portId == null) {
            System.out.println("Could not find COM port.");
            return;
        }

        try {
            // open serial port, and use class name for the appName.
            serialPort = (SerialPort) portId.open(this.getClass().getName(),
                    TIME_OUT);

            // set port parameters
            serialPort.setSerialPortParams(DATA_RATE,
                    SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);

            // open the streams
            input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
            output = serialPort.getOutputStream();

            // add event listeners
            serialPort.addEventListener(this);
            serialPort.notifyOnDataAvailable(true);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }

    /**
     * This should be called when you stop using the port.
     * This will prevent port locking on platforms like Linux.
     */
    public synchronized void close() {
        if (serialPort != null) {
            serialPort.removeEventListener();
            serialPort.close();
        }
    }

    /**
     * Handle an event on the serial port. Read the data and print it.
     */
    public synchronized void serialEvent(SerialPortEvent oEvent) {
        if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
            try {
                String inputLine=input.readLine();
                System.out.println(inputLine);
            } catch (Exception e) {
                System.err.println(e.toString());
            }
        }
        // Ignore all the other eventTypes, but you should consider the other ones.
    }

    public static void main(String[] args) throws Exception {
        SerialTest main = new SerialTest();
        main.initialize();
        Thread t=new Thread() {
            public void run() {
                //the following line will keep this app alive for 1000 seconds,
                //waiting for events to occur and responding to them (printing incoming messages to console).
                try {Thread.sleep(1000000);} catch (InterruptedException ie) {}
            }
        };
        t.start();
        System.out.println("Started");
  }
void setup(){
  Serial.begin(9600);
}

void loop(){
  Serial.println("Hello world");
  delay(1000);
}

共有1个答案

姬向明
2023-03-14

我用Java9也有同样的问题,当我改回Java8时,它可以工作。另一个解决方案,使用http://fazecast.github.io/jserialcomm/it works for me...

 类似资料:
  • 下面给出了我的代码。它是一个给数据库添加叶子的程序。我得到的是java运行时环境检测到的致命错误,我不明白为什么。我是Java新手,所以对此感到非常困惑。有人能告诉我为什么会这样吗?我也在安装错误文件。我也试图理解这一点,但找不到错误所在的位置。

  • 我在Netbeans中创建了一个Java项目,该项目在我的计算机上运行时没有问题(无论是在Netbeans中还是在运行jar文件时),但是当我试图在另一台计算机上运行该项目时,我会得到以下错误消息: Java运行时环境检测到一个致命错误: exception_access_visultion(0xC0000005)在PC=0x0000000062478337,PID=2860,TID=0x0000

  • 我可以找到这个错误,是由项目的一个类引起的,但我显然不知道问题专家在哪里。我希望有人能帮助我。 我真的很期待帮助。非常感谢。 Java运行时环境检测到一个致命错误: 通过这段代码,我基本上试图区分与我所处理的问题相关的情况。我意识到由于我删除了带有“Merkerzzf”的行,所以我不会导致错误。我不知道为什么。

  • 我试图在我的parrot home OS中安装ZAP代理,但我无法安装它,我在终端中收到的错误如下:

  • 下面给出了我的代码。这是一个把叶子添加到数据库的程序。我得到了致命的错误已经被Java运行时环境检测到了,我不明白为什么。我是新来Java的,所以我对此很困惑。有人能告诉我为什么会这样吗?我也在放错误文件。我也试着理解这一点,但找不到错误所在的位置。 这是错误文件 “demo”是数据库的名称,它有4列,即empid、Fname、Lname、designation。该程序的工作原理是,当我输入员工I

  • 我试图在我的Windows XP机器上摆脱旧版本的Java(因为我还有1.6和1.7)。卸载1.6时,我得到了一个关于Java运行时环境的错误。当我尝试启动Java控制面板时,它会给我以下错误: 系统找不到指定的注册表项: HKEY_LOCAL_MACHINE\软件\JavaSoft\Java运行时环境\1.7.0_05 我尝试过重新安装Java,但这一点也不起作用。而且我不能完全删除Java,因