【问题标题】:Communicate over Comport on 14400 Baudrate in Java - Serial Communication在 Java 中以 14400 波特率通过 Com 端口进行通信 - 串行通信
【发布时间】: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


【解决方案1】:

这就是解决方案,

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

这是链接 - rxtx latest driveres

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

希望对你有帮助。

干杯!

【讨论】:

    猜你喜欢
    • 2014-12-22
    • 1970-01-01
    • 2013-10-24
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多