用户界面通过rxtx库和SerialPortEvent接收JAVA中的数据,并在jTextArea中显示字符串文本
现在这就是问题所在,我有一个Arduino uno r3,它通过串行端口发送数据,我有一个java gui代码来接收字节[]数组中的数据,将其转换并存储在字符串st中,并在jTextArea中显示。 问题是jtextArea不显示任何内容,可能考虑到字符串st值为空,但如果我使用著名的系统。出来打印(st)结果在控制台中正确显示。 我不知道出了什么问题,我在下面发布了一段负责从串口获取数据的代码,synchronized serialEvent方法,任何帮助都将不胜感激,请帮助我:) 请注意,jTextArea1在同一类中声明为private,字符串st在同一类中声明为public 非常感谢
public synchronized void serialEvent(SerialPortEvent oEvent) {
if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
try {
int available = input.available();
byte[] chunk = new byte[available];
input.read(chunk, 0, available);
st = new String(chunk);
jTextArea1.append(st);
}catch (IOException e) {System.out.println("IO Error Occurred: " + e.toString());}
共 (0) 个答案