【发布时间】:2013-07-17 09:42:09
【问题描述】:
希望在这里找到解决方案。
我有一个控制器,它通过 UART 使用特定于应用程序的协议,该协议仅在 14400 bps 下工作。
我必须使用 java 代码通过串口与这个控制器通信。
但我发现我正在使用的 API 不支持 14400 波特率,尽管他们称之为标准!!。
我尝试使用 javax.comm 和 rxtx jar。没有真正的hel,因为它们都不支持这种波特率。
哪位大神可以帮帮我,真的很有帮助。
谢谢!
好的,这里是代码sn-p
selectedPort = (SerialPort) portID.open("FlashProgramming",
TIMEOUT);
System.out.println("port " + selectedPort + " is opened");
try {
selectedPort.setSerialPortParams(14400,
SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
//这里尝试设置波特率为14400,但是回滚到9600,不支持默认为14400!!
}
// no handshaking or other flow control
try {
selectedPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
} catch (UnsupportedCommOperationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// timer on any read of the serial port
try {
selectedPort.enableReceiveTimeout(TIMEOUT);
} catch (UnsupportedCommOperationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("Comport Configeration is done");
try {
Serialdriver.in = selectedPort.getInputStream();
Serialdriver.out = selectedPort.getOutputStream();
System.out.println("i/p & o/p's are initialized");
Serialdriver.handlerParamselScreen.displaystatus("Seleted Com port "
+ selectedPort + " is Successfully opened");
}
selectedPort.addEventListener(Serialdriver);
selectedPort.notifyOnDataAvailable(true);
return selectedPort;
}
【问题讨论】:
-
没有人确定答案??来吧伙计们!
-
你的问题不够清楚。您正在使用哪个 API?您遇到什么异常?您使用的是哪个 IDE?也贴出你写的代码
-
它在Linux上的已知问题:stackoverflow.com/questions/3192478/…
-
你找到解决办法了吗?
-
是的,将低级 dll 从 javax.comm 更改为 RXTX,这是链接 - link 和最好的部分,x32 和 x64 位 Os/java 支持相同的代码。干杯!
标签: java serial-port rxtx baud-rate javax.comm