Java串行通信中14400波特率的Comport通信



希望在此处找到解决方案。

我有一个控制器,它通过UART使用特定于应用程序的协议,该协议仅在14400 bps下工作。

我必须使用java代码通过串行端口与该控制器通信

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

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

在这方面谁能帮助我吗?这将是非常有用的。

谢谢!

好的,这是的代码片段

        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最新的驱动程序

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

我希望它是有益的。

干杯!

最新更新