使用JAVA在Linux进行串口开发的问题

    使用JAVA进行串口,实在是没啥难度,而且网上已经说的够多的了,因此我也不想多废话。不过其中有个问题实在是诡异(在Linux下)。
    虽然代码看上去没啥问题,但每当执行setSerialPortParams就抛出异常。
Detected: /dev/ttyM0 java.io.IOException: Not all params are supported by kernel
        at com.sun.comm.LinuxSerial.nativeSetSerialPortParams(Native Method)
    本以为是我 哪里搞错了,到网上一看才发现不少人遇到了和和同样的问题。问题的解决方案也是千奇百怪。有人说调用setSerialPortParams这个函数前要先sleep(10),有人说要先println。我加了print依旧失败,再往下看,有人说将setSerialPortParams这个函数放到try模块里就可以。加完try后再测试还真的好了。目前暂时只能将这个问题定义为“诡异”了。

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">