当前位置: 首页>>代码示例>>Java>>正文


Java SerialPort.disableReceiveTimeout方法代码示例

本文整理汇总了Java中gnu.io.SerialPort.disableReceiveTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java SerialPort.disableReceiveTimeout方法的具体用法?Java SerialPort.disableReceiveTimeout怎么用?Java SerialPort.disableReceiveTimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gnu.io.SerialPort的用法示例。


在下文中一共展示了SerialPort.disableReceiveTimeout方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public void connect() throws EpsonProjectorException {

	try {
		logger.debug("Open connection to serial port '{}'", serialPortName);
		CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);

		CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);

		serialPort = (SerialPort) commPort;
		serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
				SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
		serialPort.enableReceiveThreshold(1);
		serialPort.disableReceiveTimeout();

		in = serialPort.getInputStream();
		out = serialPort.getOutputStream();

		out.flush();
		if (in.markSupported()) {
			in.reset();
		}
		
		// RXTX serial port library causes high CPU load
		// Start event listener, which will just sleep and slow down event loop
		serialPort.addEventListener(this);
		serialPort.notifyOnDataAvailable(true);
	} catch (Exception e) {
		throw new EpsonProjectorException(e);
	}

}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:35,代码来源:EpsonProjectorSerialConnector.java

示例2: getPort

import gnu.io.SerialPort; //导入方法依赖的package包/类
public static FMilaSerialPort getPort(int speed, String port) throws IOException {
  SerialPort serialPort;

  try {

    CommPortIdentifier comm = CommPortIdentifier.getPortIdentifier(port);
    if (comm.isCurrentlyOwned()) {
      throw new IOException("StationInUseError");
    }
    serialPort = comm.open("4mila", 2000);

    serialPort.setSerialPortParams(speed, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
    serialPort.disableReceiveTimeout();
    serialPort.disableReceiveFraming();
    serialPort.disableReceiveThreshold();
    serialPort.notifyOnDataAvailable(true);
    serialPort.notifyOnOutputEmpty(true);
  }
  catch (PortInUseException | UnsupportedCommOperationException | NoSuchPortException e) {
    throw new IOException(e.getMessage(), e);
  }

  return new RXTXSerialPort(serialPort);
}
 
开发者ID:innovad,项目名称:4mila-1.0,代码行数:26,代码来源:RXTXUtility.java

示例3: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
@Override
public void connect(String device) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException {
	CommPortIdentifier portIdentifier = CommPortIdentifier
			.getPortIdentifier(device);

	CommPort commPort = portIdentifier
			.open(this.getClass().getName(), 2000);

	serialPort = (SerialPort) commPort;
	serialPort.setSerialPortParams(38400, SerialPort.DATABITS_8,
			SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
	serialPort.enableReceiveThreshold(1);
	serialPort.disableReceiveTimeout();
	
	in = serialPort.getInputStream();
	out = serialPort.getOutputStream();
	
	out.flush();
	if (in.markSupported()) {
		in.reset();
	}

	readerThread = new SerialReader(in);
	readerThread.start();
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:26,代码来源:RFXComSerialConnector.java

示例4: open

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 **/
public void open() {

	try {
		
		CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
		CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
		
		serialPort = (SerialPort) commPort;
		serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
		serialPort.enableReceiveThreshold(1);
		serialPort.disableReceiveTimeout();

		serialOutput = new OutputStreamWriter(serialPort.getOutputStream(), "US-ASCII");
           serialInput = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
           
           setSerialEventHandler(this);
           
           connected = true;
		
	} catch (NoSuchPortException noSuchPortException) {
		logger.error("open(): No Such Port Exception: ", noSuchPortException);
           connected = false;
	} catch (PortInUseException portInUseException) {
		logger.error("open(): Port in Use Exception: ", portInUseException);
           connected = false;
	} catch (UnsupportedCommOperationException unsupportedCommOperationException) {
		logger.error("open(): Unsupported Comm Operation Exception: ", unsupportedCommOperationException);
           connected = false;
	} catch (UnsupportedEncodingException unsupportedEncodingException) {
		logger.error("open(): Unsupported Encoding Exception: ", unsupportedEncodingException);
           connected = false;
	} catch (IOException ioException) {
		logger.error("open(): IO Exception: ", ioException);
           connected = false;
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:40,代码来源:SerialConnector.java

示例5: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
@Override
public void connect(String device)
        throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException {
    CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(device);

    CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);

    serialPort = (SerialPort) commPort;
    serialPort.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    serialPort.enableReceiveThreshold(1);
    serialPort.disableReceiveTimeout();

    in = serialPort.getInputStream();
    out = serialPort.getOutputStream();

    out.flush();
    if (in.markSupported()) {
        in.reset();
    }

    readerThread = new SerialReader(in);
    readerThread.start();
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:24,代码来源:RFXComSerialConnector.java

示例6: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void connect() throws EpsonProjectorException {

    try {
        logger.debug("Open connection to serial port '{}'", serialPortName);
        CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);

        CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);

        serialPort = (SerialPort) commPort;
        serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
        serialPort.enableReceiveThreshold(1);
        serialPort.disableReceiveTimeout();

        in = serialPort.getInputStream();
        out = serialPort.getOutputStream();

        out.flush();
        if (in.markSupported()) {
            in.reset();
        }

        // RXTX serial port library causes high CPU load
        // Start event listener, which will just sleep and slow down event loop
        serialPort.addEventListener(this);
        serialPort.notifyOnDataAvailable(true);
    } catch (Exception e) {
        throw new EpsonProjectorException(e);
    }

}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:35,代码来源:EpsonProjectorSerialConnector.java

示例7: open

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 **/
public void open() {

    try {

        CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
        CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);

        serialPort = (SerialPort) commPort;
        serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
        serialPort.enableReceiveThreshold(1);
        serialPort.disableReceiveTimeout();

        serialOutput = new OutputStreamWriter(serialPort.getOutputStream(), "US-ASCII");
        serialInput = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));

        setSerialEventHandler(this);

        connected = true;

    } catch (NoSuchPortException noSuchPortException) {
        logger.error("open(): No Such Port Exception: ", noSuchPortException);
        connected = false;
    } catch (PortInUseException portInUseException) {
        logger.error("open(): Port in Use Exception: ", portInUseException);
        connected = false;
    } catch (UnsupportedCommOperationException unsupportedCommOperationException) {
        logger.error("open(): Unsupported Comm Operation Exception: ", unsupportedCommOperationException);
        connected = false;
    } catch (UnsupportedEncodingException unsupportedEncodingException) {
        logger.error("open(): Unsupported Encoding Exception: ", unsupportedEncodingException);
        connected = false;
    } catch (IOException ioException) {
        logger.error("open(): IO Exception: ", ioException);
        connected = false;
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:40,代码来源:SerialConnector.java

示例8: connect

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public boolean connect(String serialPortName) {

    try {
        logger.debug("Open connection to serial port '{}'", serialPortName);
        CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);

        CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);

        serialPort = (SerialPort) commPort;
        serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
        serialPort.enableReceiveThreshold(1);
        serialPort.disableReceiveTimeout();

        in = serialPort.getInputStream();
        out = serialPort.getOutputStream();

        out.flush();
        if (in.markSupported()) {
            in.reset();
        }

        // RXTX serial port library causes high CPU load
        // Start event listener, which will just sleep and slow down event
        // loop
        serialPort.addEventListener(this);
        serialPort.notifyOnDataAvailable(true);
        return true;
    } catch (Exception e) {
        logger.error("serial port connect error", e);
        e.printStackTrace();
        return false;
    }

}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:38,代码来源:EiscpSerial.java

示例9: connectSerial

import gnu.io.SerialPort; //导入方法依赖的package包/类
private void connectSerial() throws Exception {

		logger.debug("Initializing serial port {}", serialPortName);
		
		try {

			CommPortIdentifier portIdentifier = CommPortIdentifier
				.getPortIdentifier(serialPortName);
			
			CommPort commPort = portIdentifier
				.open(this.getClass().getName(), 2000);
			
			serialPort = (SerialPort) commPort;
	    
			try {
				serialPort.setSerialPortParams(4800, SerialPort.DATABITS_8,
							       SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

				serialPort.enableReceiveThreshold(1);
				serialPort.disableReceiveTimeout();
			} catch (UnsupportedCommOperationException unimportant) {
				// We might have a perfectly usable PTY even if above operations are unsupported
			};


			inStream = new DataInputStream(serialPort.getInputStream());
			outStream = serialPort.getOutputStream();

			outStream.flush();
			if (inStream.markSupported()) {
				inStream.reset();
			}
		
			logger.debug("Starting DataListener for {}", PrimareSerialConnector.this.toString());
			dataListener = new DataListener();
			dataListener.start();
			logger.debug("Starting DataListener for {}", PrimareSerialConnector.this.toString());

			sendInitMessages();

			
		} catch (NoSuchPortException e) {
			logger.error("No such port: {}",serialPortName);

			Enumeration portList = CommPortIdentifier.getPortIdentifiers();
			if (portList.hasMoreElements()) {
				StringBuilder sb = new StringBuilder();
				while(portList.hasMoreElements()){
					CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
					sb.append(String.format("%s ",portId.getName()));
				}
				logger.error("The following communications ports are available: {}",
					     sb.toString().trim());
			} else {
				logger.error("There are no communications ports available");
			}
			logger.error("You may consider OpenHAB startup parameter [ -Dgnu.io.rxtx.SerialPorts={} ]", 
				     serialPortName);
			throw e;
		}
	}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:62,代码来源:PrimareSerialConnector.java

示例10: openConnection

import gnu.io.SerialPort; //导入方法依赖的package包/类
@Override
public void openConnection() {

    try {
        logger.debug("openConnection(): Connecting to IT-100 ");

        CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
        CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);

        serialPort = (SerialPort) commPort;
        serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);
        serialPort.enableReceiveThreshold(1);
        serialPort.disableReceiveTimeout();

        serialOutput = new OutputStreamWriter(serialPort.getOutputStream(), "US-ASCII");
        serialInput = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));

        setSerialEventHandler(this);

        setConnected(true);

    } catch (NoSuchPortException noSuchPortException) {
        logger.error("openConnection(): No Such Port Exception: {}", noSuchPortException.getMessage());
        setConnected(false);
    } catch (PortInUseException portInUseException) {
        logger.error("openConnection(): Port in Use Exception: {}", portInUseException.getMessage());
        setConnected(false);
    } catch (UnsupportedCommOperationException unsupportedCommOperationException) {
        logger.error("openConnection(): Unsupported Comm Operation Exception: {}",
                unsupportedCommOperationException.getMessage());
        setConnected(false);
    } catch (UnsupportedEncodingException unsupportedEncodingException) {
        logger.error("openConnection(): Unsupported Encoding Exception: {}",
                unsupportedEncodingException.getMessage());
        setConnected(false);
    } catch (IOException ioException) {
        logger.error("openConnection(): IO Exception: {}", ioException.getMessage());
        setConnected(false);
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:42,代码来源:IT100BridgeHandler.java

示例11: connectSerial

import gnu.io.SerialPort; //导入方法依赖的package包/类
private void connectSerial() throws Exception {

        logger.debug("Initializing serial port {}", serialPortName);

        try {

            CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);

            CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);

            serialPort = (SerialPort) commPort;

            try {
                serialPort.setSerialPortParams(4800, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                        SerialPort.PARITY_NONE);

                serialPort.enableReceiveThreshold(1);
                serialPort.disableReceiveTimeout();
            } catch (UnsupportedCommOperationException unimportant) {
                // We might have a perfectly usable PTY even if above operations are unsupported
            }
            ;

            inStream = new DataInputStream(serialPort.getInputStream());
            outStream = serialPort.getOutputStream();

            outStream.flush();
            if (inStream.markSupported()) {
                inStream.reset();
            }

            logger.debug("Starting DataListener for {}", PrimareSerialConnector.this.toString());
            dataListener = new DataListener();
            dataListener.start();
            logger.debug("Starting DataListener for {}", PrimareSerialConnector.this.toString());

            sendInitMessages();

        } catch (NoSuchPortException e) {
            logger.error("No such port: {}", serialPortName);

            Enumeration portList = CommPortIdentifier.getPortIdentifiers();
            if (portList.hasMoreElements()) {
                StringBuilder sb = new StringBuilder();
                while (portList.hasMoreElements()) {
                    CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
                    sb.append(String.format("%s ", portId.getName()));
                }
                logger.error("The following communications ports are available: {}", sb.toString().trim());
            } else {
                logger.error("There are no communications ports available");
            }
            logger.error("You may consider OpenHAB startup parameter [ -Dgnu.io.rxtx.SerialPorts={} ]", serialPortName);
            throw e;
        }
    }
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:57,代码来源:PrimareSerialConnector.java

示例12: open

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 **/
@Override
public void open() {
    logger.debug("open(): Opening Serial Connection");

    try {

        CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(serialPortName);
        CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);

        serialPort = (SerialPort) commPort;
        serialPort.setSerialPortParams(baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);
        serialPort.enableReceiveThreshold(1);
        serialPort.disableReceiveTimeout();

        setInput(serialPort.getInputStream());
        setOutput(serialPort.getOutputStream());

        getOutput().flush();
        if (getInput().markSupported()) {
            getInput().reset();
        }

        setReaderThread(new SerialReaderThread(getInput(), this));
        getReaderThread().start();

        setConnected(true);
    } catch (NoSuchPortException noSuchPortException) {
        logger.debug("open(): No Such Port Exception: {}", noSuchPortException.getMessage());
        setConnected(false);
    } catch (PortInUseException portInUseException) {
        logger.debug("open(): Port in Use Exception: {}", portInUseException.getMessage());
        setConnected(false);
    } catch (UnsupportedCommOperationException unsupportedCommOperationException) {
        logger.debug("open(): Unsupported Comm Operation Exception: {}",
                unsupportedCommOperationException.getMessage());
        setConnected(false);
    } catch (UnsupportedEncodingException unsupportedEncodingException) {
        logger.debug("open(): Unsupported Encoding Exception: {}", unsupportedEncodingException.getMessage());
        setConnected(false);
    } catch (IOException ioException) {
        logger.debug("open(): IO Exception: ", ioException.getMessage());
        setConnected(false);
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:49,代码来源:PowerMaxSerialConnector.java


注:本文中的gnu.io.SerialPort.disableReceiveTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。