Serial.java 文件源码

java
阅读 32 收藏 0 点赞 0 评论 0

项目:fpga-shovel-and-pickaxe 作者:
public void connect ( String portName, int threshold, int newLineAfter) throws Exception
{
    CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
    if ( portIdentifier.isCurrentlyOwned() )
    {
        System.out.println("Error: Port is currently in use");
    }
    else
    {
        CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);

        if ( commPort instanceof SerialPort )
        {
            serialPort = (SerialPort) commPort;
            serialPort.enableReceiveTimeout(threshold);
            serialPort.setSerialPortParams(115200,SerialPort.DATABITS_8,SerialPort.STOPBITS_2,SerialPort.PARITY_NONE);

            sr = new SerialReader(serialPort, newLineAfter, System.currentTimeMillis());
            serialThread = new Thread(sr);
            serialThread.start();

        }
        else
        {
//                    arrayco
            System.out.println("Error: Only serial ports are handled by this example.");
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号