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


Java SerialPort.enableReceiveThreshold方法代碼示例

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


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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

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