gpt4 book ai didi

java - Java 中以 14400 波特率通过 Comport 进行通信 - 串行通信

转载 作者:行者123 更新时间:2023-12-01 04:33:14 24 4
gpt4 key购买 nike

希望在这里找到解决方案。

我有一个 Controller ,它使用 UART 上的应用程序特定协议(protocol),并且该协议(protocol)仅在 14400 bps 下工作。

我必须使用 java 代码通过串行端口与该 Controller 进行通信。

但是我发现我使用的 API 不支持 14400 波特率,尽管他们称其为标准!!。

我尝试使用 javax.comm 和 rxtx jar。没有真正的帮助,因为它们都不支持这个波特率。

任何人都可以在这方面帮助我,这将非常有帮助。

谢谢!

好的,这是代码片段

        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;

}

最佳答案

这是解决方案,

我将低级 dll 从 javax.comm 替换为 rxtx。

这是链接 - rxtx latest driveres

最好的部分是它支持 x32 和 x64 jre!。将代码从 javax.comm 移植到 rxtx 只需 5 分钟的工作。

希望对您有所帮助。

干杯!

关于java - Java 中以 14400 波特率通过 Comport 进行通信 - 串行通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17696364/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com