當前位置: 首頁>>代碼示例>>Java>>正文


Java SerialPort.enableReceiveTimeout方法代碼示例

本文整理匯總了Java中gnu.io.SerialPort.enableReceiveTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java SerialPort.enableReceiveTimeout方法的具體用法?Java SerialPort.enableReceiveTimeout怎麽用?Java SerialPort.enableReceiveTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gnu.io.SerialPort的用法示例。


在下文中一共展示了SerialPort.enableReceiveTimeout方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: open

import gnu.io.SerialPort; //導入方法依賴的package包/類
@Override
public void open() {
	try{
		CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
        if (portIdentifier.isCurrentlyOwned())
            System.out.println("Error: Port is currently in use");
        else {
            CommPort port = portIdentifier.open(this.getClass().getName(), getTimeout());//for now class name
            
            if (port instanceof SerialPort){
            	serial = (SerialPort) port;
            	serial.setSerialPortParams(baudrate, SerialPort.DATABITS_8 
                		, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                
            	serial.enableReceiveTimeout(timeout);
            	
                this.in = serial.getInputStream();
                this.out = serial.getOutputStream();
                isOpened = true;
            }
            else
                System.out.println("Error: Only serial ports are handled");
        }   
	}
	catch (PortInUseException | UnsupportedCommOperationException | NoSuchPortException | IOException e) {
		if(serial != null)
			serial.close();
		serial = null;
		e.printStackTrace();
	}
}
 
開發者ID:Flash3388,項目名稱:FlashLib,代碼行數:32,代碼來源:RXTXCommInterface.java

示例2: open

import gnu.io.SerialPort; //導入方法依賴的package包/類
public void open() throws PortInUseException, UnsupportedCommOperationException, TooManyListenersException, IOException
{
	if (open)
	{
		log.info(commId.getName() + " already open, skipping");
		return;
	}

	log.info("Opening port " + commId.getName());
	buffer = new ByteBuffer();

	port = (SerialPort)commId.open("TimerInterface-"+commId.getName(), 30000);
	port.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
	port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);

	port.addEventListener(this);
	port.notifyOnDataAvailable(true);
	port.enableReceiveTimeout(30);

	os = port.getOutputStream();
	is = port.getInputStream();
	open = true;
   }
 
開發者ID:drytoastman,項目名稱:scorekeeperfrontend,代碼行數:24,代碼來源:SerialDataInterface.java

示例3: connect

import gnu.io.SerialPort; //導入方法依賴的package包/類
public void connect(String portname, int baudrate, char flowControl) throws Exception {
	Log.debug(this.getClass(), "connecting device "+portname+", "+baudrate+" baud");
       boolean isCommonPortname = portname.contains("ttyS") || portname.contains("COM");
	if ( ! isCommonPortname ) {
           System.setProperty("gnu.io.rxtx.SerialPorts", portname);
       }
	System.setProperty("gnu.io.rxtx.NoVersionOutput", "true");
	CommPortIdentifier commPortIdentifier = CommPortIdentifier.getPortIdentifier(portname);
	CommPort commPort = commPortIdentifier.open("tc65sh", 2000);
	serialPort = (SerialPort) commPort;
	serialPort.setSerialPortParams(baudrate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
	serialPort.enableReceiveTimeout(2000);
	if ( flowControl == FLOWCONTROL_NONE ) {
		serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
	} else if ( flowControl == FLOWCONTROL_RTSCTS) {
		serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_OUT | SerialPort.FLOWCONTROL_RTSCTS_IN);
	} else if ( flowControl == FLOWCONTROL_XONXOFF) {
		serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_XONXOFF_OUT | SerialPort.FLOWCONTROL_XONXOFF_IN);
	} else {
		throw new RuntimeException("invalid flowControl "+flowControl);
	}
	serialIn = serialPort.getInputStream();
	serialOut = serialPort.getOutputStream();
}
 
開發者ID:zhuravskiy,項目名稱:tc65sh,代碼行數:25,代碼來源:Device.java

示例4: connect

import gnu.io.SerialPort; //導入方法依賴的package包/類
private void connect (String portName, int threshold) throws Exception
{
    CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
    if ( portIdentifier.isCurrentlyOwned() )
    {
        appender.append("Error: Port is currently in use");
    }
    else
    {
        //from RXTX examples
        CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);

        if (commPort instanceof SerialPort)
        {
            //set up serial port
            serialPort = (SerialPort) commPort;
            serialPort.enableReceiveTimeout(threshold);
            serialPort.setSerialPortParams(115200,SerialPort.DATABITS_8,SerialPort.STOPBITS_2,SerialPort.PARITY_NONE);

            //start async reader
            sr = new SerialReader(serialPort, server);
            serailThread = new Thread(sr);
            serailThread.start();
        }
        else
        {
            appender.append("Error: Only serial ports are handled by this example.");
        }
    }     
}
 
開發者ID:ZenoFuturista,項目名稱:fpga-shovel-and-pickaxe,代碼行數:31,代碼來源:FpgaSerial.java

示例5: connect

import gnu.io.SerialPort; //導入方法依賴的package包/類
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.");
        }
    }
}
 
開發者ID:ZenoFuturista,項目名稱:fpga-shovel-and-pickaxe,代碼行數:30,代碼來源:Serial.java


注:本文中的gnu.io.SerialPort.enableReceiveTimeout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。