【发布时间】:2015-09-23 06:59:46
【问题描述】:
我有一个要通过串行端口发送的字节流。发送完所有字节后,我应该再次通过输入流接收字节流。
输出字节数组
byte[] command={(byte) 0xAA,0x55,0x05,0x00,0x55,(byte) 0xAA};
预期响应
**Serial command received
Admin Mode - IR Learn
In IR Learner Mode
Press IR Key...**
实际反应
**Serial command received
Admin Mode - IR Learn
In IR e - IR**
输入流
public void serialEvent(SerialPortEvent event) {
try {
Thread.sleep(100);
} catch (InterruptedException e2) {
e2.printStackTrace();
}
StringBuilder sb = new StringBuilder();
try {
int length = inputStream.available();
readBuffer = new byte[length];
Thread.sleep(110);
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
for (byte b : readBuffer) {
sb.append(new String(new byte[]{b}));
}
}
System.out.println(sb.toString());
JOptionPane.showMessageDialog(contentPane, "Learned code : " + sb.toString(), "Code", JOptionPane.INFORMATION_MESSAGE);
} catch (IOException e4) {
e4.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
readBuffer = null;
}
输出流
for (int i = 0; i < command.length; i++) {
outputStream.write(command, 0, command.length);
outputStream.flush();
}
如何在不重复和JOptionPane的情况下获取值?
请帮忙
【问题讨论】:
标签: java