RXTX Java库错误
我的英语不是很好,所以我会尽量让你明白。 我目前正在从事一个多项目项目。 我已经编写了一个Arduino控制程序,它允许我通过命令管理传感器网络。例如,我可以通过键入命令“add”等来添加传感器 我还为micro controller编写了一个用于传感器数据采集的Java API(它适用于各种类型的micro controller),它能够将命令文件发送到我的micro controller,以获取接收到的数据,并将它们以我选择的格式(JSON、XML、PostScript、字节码…)存储到文件中也可以以http头的形式将其发送到IP地址 我有以下问题: 当我从Java程序向微控制器发送命令时,Java程序有时无法接收命令执行响应,是什么导致它崩溃:RXTX Java库错误,java,arduino,rxtx,Java,Arduino,Rxtx,我的英语不是很好,所以我会尽量让你明白。 我目前正在从事一个多项目项目。 我已经编写了一个Arduino控制程序,它允许我通过命令管理传感器网络。例如,我可以通过键入命令“add”等来添加传感器 我还为micro controller编写了一个用于传感器数据采集的Java API(它适用于各种类型的micro controller),它能够将命令文件发送到我的micro controller,以获取接收到的数据,并将它们以我选择的格式(JSON、XML、PostScript、字节码…)存储到文件
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
Received line : I: Tab cleared.
Received line : I: Setup terminated
|MicroController.java->messageReceived|: recieved response : I: Setup terminated
Send : add t1 2 3
Received line : I:|Main loop| command received :add t1 2 3
Received line : I:|Main loop| command add t1 2 3 in execution ...
Received line : I:|Main loop| command add t1 2 3 executed.
Received line : I:|Main loop| return code 0 sent.
如您所见,微控制器发送了返回代码“0”,但Java没有收到它
我已经编写了自己的send()和receive()方法:
/**
* Send message.
*
* @param str String to send.
*
* @throws IOException IO error.
* @throws InterruptedException
*/
public void sendMessage(String str)
throws IOException, InterruptedException
{
System.out.println("Send : " + str);
// Send the command.
output.write(str.getBytes());
output.flush();
}
/**
* Handle input event on the serial port.
*
* @param oEvent Event receives.
*/
private synchronized void processReceivedEvent(SerialPortEvent oEvent)
{
if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE)
{
try
{
// Wait input to be ready (mandatory, exception o/w).
while (!input.ready())
{
Thread.sleep(1);
}
String inputLine = input.readLine();
System.out.println("Received line : " + inputLine);
// Notify listener.
if ((listener != null) && (inputLine != null))
listener.messageReceived(inputLine);
}
catch (Exception e)
{
if (port != null)
e.printStackTrace();
}
}
}
也许我有一些同步错误,这导致了一个串行读取错误,但我想知道我的发送和接收方法与串行库方法之间是否存在某种冲突
谢谢。您所说的“微控制器发送了返回码“0”,但Java没有收到”是什么意思,您正在从Java程序打印它。