当前位置: 首页>>代码示例>>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;未经允许,请勿转载。