java - arduino 和 java 之间的串行通信“检测到致命错误”
问题描述
好的,伙计们——最近我的 java 项目和我的 arduino 之间的串行通信出现了一些问题。我正在尝试从我的 arduino 发送字符串并使用 jssc 在 java 中接收它们;但我不断得到
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007110b5db, pid=12580, tid=3400
#
# JRE version: Java(TM) SE Runtime Environment (16.0.1+9) (build 16.0.1+9-24)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (16.0.1+9-24, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, 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:
# C:\Users\charl\IdeaProjects\serialcommunicationtest1\hs_err_pid12580.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.
#
如果有人可以做任何事情,这是我的代码:
Arduino代码:
int timedelay;
int count;
void setup() {
Serial.begin(9600);
timedelay = 1000;
count = 0;
}
void loop() {
String s = "counter : " + String (count);
Serial.println(s);
count++;
delay(timedelay);
}
和Java代码:
import jssc.SerialPort;
import jssc.SerialPortEvent;
import jssc.SerialPortException;
import jssc.SerialPortList;
public class Main {
public void connect(String portname) {
// now we need to serialport
SerialPort port = new SerialPort(portname);
try {
port.openPort();
port.setParams(
SerialPort.BAUDRATE_9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE
);
port.addEventListener((SerialPortEvent event)->{
if(event.isRXCHAR()) {
try {
String s = port.readString();
System.out.print(s);
} catch (SerialPortException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
} catch (SerialPortException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// we need to array of string that hold all the ports
String portlist[] = SerialPortList.getPortNames();
for(int i =0; i<portlist.length;i++) {
System.out.println(portlist[i]);
}
Main obj = new Main();
obj.connect(portlist[0]);
}
}
感谢您的阅读,如果您能走到这一步,任何建议都将不胜感激:D
解决方案
我正在使用一个过时的库 - ty JockX
推荐阅读
- sql - 在 Pivot SQL 表中排序月份
- curl - 无法加载 ASN1 客户端证书、OpenSSL、OAuth2 重定向
- google-apps-script - 有没有办法防止电子表格在公式中将日期更新为今天的日期?
- r - dim(x) 的长度必须为正,但我看不到问题所在
- javascript - 如何使用 JavaScript AWS IAM SDK 3 处理节流?
- python - 输入形状的值为 4126,但接收到的输入形状为
- sql - 如何在插入更新或删除后自动更新表的内容
- c# - 无法弄清楚如何将数据添加到现有数据湖文件
- python - 更改 Pygame Surface 的颜色
- reporting-services - 在 SSRS 2017 中使用 REST API 创建报告/目录项