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


Java NoSuchPortException類代碼示例

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


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

示例1: connect

import gnu.io.NoSuchPortException; //導入依賴的package包/類
@PostConstruct
public void connect() throws TooManyListenersException, NoSuchPortException {
    log.info("Connection PostConstruct callback: connecting ...");

    serial = new NRSerialPort(serialPortProperties.getPortName(), serialPortProperties.getBaudRate());
    serial.connect();

    if (serial.isConnected()) {
        log.info("Connection opened!");
    } else {
        throw new RuntimeException("Is not possible to open connection in " + serialPortProperties.getPortName() + " port");
    }
    serial.addEventListener(this);
    serial.notifyOnDataAvailable(true);
    input = new BufferedReader(new InputStreamReader(serial.getInputStream()));
}
 
開發者ID:diegosep,項目名稱:spring-serial-port-connector,代碼行數:17,代碼來源:AbstractSpringSerialPortConnector.java

示例2: open

import gnu.io.NoSuchPortException; //導入依賴的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

示例3: getPort

import gnu.io.NoSuchPortException; //導入依賴的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

示例4: newLink

import gnu.io.NoSuchPortException; //導入依賴的package包/類
@Override
public LinkDelegate newLink(SerialLinkConfig config)
		throws NoSuchPortException, PortInUseException,
		UnsupportedCommOperationException, IOException {
	CommPortIdentifier portIdentifier = CommPortIdentifier
			.getPortIdentifier(config.getPort());
	checkState(!portIdentifier.isCurrentlyOwned(),
			"Port %s is currently in use", config.getPort());
	final SerialPort serialPort = serialPort(config, portIdentifier);

	StreamConnection connection = new StreamConnection(
			serialPort.getInputStream(), serialPort.getOutputStream(),
			config.getProto());

	ConnectionBasedLink connectionBasedLink = new ConnectionBasedLink(
			connection, config.getProto());
	@SuppressWarnings("resource")
	Link link = config.isQos() ? new QosLink(connectionBasedLink)
			: connectionBasedLink;

	waitForArdulink(config, connectionBasedLink);
	return new LinkDelegate(link) {
		@Override
		public void close() throws IOException {
			super.close();
			serialPort.close();
		}
	};
}
 
開發者ID:Ardulink,項目名稱:Ardulink-2,代碼行數:30,代碼來源:SerialLinkFactory.java

示例5: openPort

import gnu.io.NoSuchPortException; //導入依賴的package包/類
@Override
synchronized protected void openPort() throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException {
	if (port != null)
		return;
	log.info("Opening port: " + portName);
	CommPortIdentifier ident = CommPortIdentifier.getPortIdentifier(portName);
	port = ident.open("ModbusRtuClient on " + portName, 2000);
	port.setOutputBufferSize(buffer.length);
	port.setInputBufferSize(buffer.length);
	try {
		port.setSerialPortParams(baudRate, dataBits, stopBits, parity);				
		port.enableReceiveTimeout(timeout);
		port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
	} catch (UnsupportedCommOperationException e) {
		close();
		throw e;
	}
	log.info("Port opened: " + port.getName());
}
 
開發者ID:sp20,項目名稱:modbus-mini,代碼行數:20,代碼來源:RtuTransportRxtx.java

示例6: connect

import gnu.io.NoSuchPortException; //導入依賴的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

示例7: open

import gnu.io.NoSuchPortException; //導入依賴的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

示例8: getSerialPort

import gnu.io.NoSuchPortException; //導入依賴的package包/類
private CommPortIdentifier getSerialPort() {
	
	if (port != null) {
		try {
			return CommPortIdentifier.getPortIdentifier(port);
		} catch (NoSuchPortException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	Enumeration<?> portEnum = CommPortIdentifier.getPortIdentifiers();
	while (portEnum.hasMoreElements()) {
		CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
		for (String portName : PORT_NAMES) {
			if (currPortId.getName().equals(portName)) {
				return currPortId;
			}
		}
	}
	return null;
}
 
開發者ID:claudiotrindade,項目名稱:contexttoolkit,代碼行數:23,代碼來源:SerialConnection.java

示例9: connect

import gnu.io.NoSuchPortException; //導入依賴的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

示例10: open

import gnu.io.NoSuchPortException; //導入依賴的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

示例11: SerialRXTXComm

import gnu.io.NoSuchPortException; //導入依賴的package包/類
public SerialRXTXComm(CommPortIdentifier portIdentifier, Layer3Base layer3) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException, IOException, TooManyListenersException{

		if (portIdentifier.isCurrentlyOwned()) {
			throw new IOException("Port is currently in use");
		} else {
			CommPort commPort = portIdentifier.open(this.getClass().getName(),
					TIME_OUT);

			if (commPort instanceof SerialPort) {
				SerialPort serialPort = (SerialPort) commPort;
				serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
						SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

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

				new SerialReceiver().start();

				/*serialPort.addEventListener(this);
				serialPort.notifyOnDataAvailable(true);*/

			} else {
				throw new IOException("This is not a serial port!.");
			}
		}
		
		this.layer2 = new Layer2Serial(this, layer3);
	}
 
開發者ID:mattibal,項目名稱:meshnet,代碼行數:29,代碼來源:SerialRXTXComm.java

示例12: connect

import gnu.io.NoSuchPortException; //導入依賴的package包/類
public void connect(String portName) throws NoSuchPortException {
	CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(portName);
	
	try {
		// open serial port, and use class name for the appName.
		serialPort = (SerialPort) portId.open(this.getClass().getName(), TIME_OUT);

		// set port parameters
		serialPort.setSerialPortParams(DATA_RATE,
				SerialPort.DATABITS_8,
				SerialPort.STOPBITS_1,
				SerialPort.PARITY_NONE);

		// open the streams
		input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
		output = serialPort.getOutputStream();

		// add event listeners
		serialPort.addEventListener(this);
		serialPort.notifyOnDataAvailable(true);
	} catch (Exception e) {
		System.err.println(e.toString());
	}
}
 
開發者ID:mikand,項目名稱:Dirigino,代碼行數:25,代碼來源:SerialInterface.java

示例13: SerialTransport

import gnu.io.NoSuchPortException; //導入依賴的package包/類
public SerialTransport(String serialPortName) throws NoSuchPortException, PortInUseException, UnsupportedCommOperationException
{
	CommPortIdentifier usablePort = CommPortIdentifier.getPortIdentifier(serialPortName);
	commPort = (SerialPort)usablePort.open("SerialTransport", 0);
	commPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
	commPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
	commPort.setDTR(true);
	commPort.setRTS(true);
	commPort.setEndOfInputChar((byte)0x0D);
}
 
開發者ID:cicavey,項目名稱:jzwave,代碼行數:11,代碼來源:SerialTransport.java

示例14: openPort

import gnu.io.NoSuchPortException; //導入依賴的package包/類
/**
 * 打開串口
 * 
 * @param portName
 *            端口名稱
 * @param baudrate
 *            波特率
 * @return 串口對象
 * @throws SerialPortParameterFailure
 *             設置串口參數失敗
 * @throws NotASerialPort
 *             端口指向設備不是串口類型
 * @throws NoSuchPort
 *             沒有該端口對應的串口設備
 * @throws PortInUse
 *             端口已被占用
 */
public static final SerialPort openPort(String portName, int baudrate)
		throws SerialPortParameterFailure, NotASerialPort, NoSuchPort,
		PortInUse {
	try {
		// 通過端口名識別端口
		CommPortIdentifier portIdentifier = CommPortIdentifier
				.getPortIdentifier(portName);
		// 打開端口,並給端口名字和一個timeout(打開操作的超時時間)
		CommPort commPort = portIdentifier.open(portName, 2000);
		// 判斷是不是串口
		if (commPort instanceof SerialPort) {
			SerialPort serialPort = (SerialPort) commPort;
			try {
				// 設置一下串口的波特率等參數
				serialPort.setSerialPortParams(baudrate,
						SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
						SerialPort.PARITY_NONE);
			} catch (UnsupportedCommOperationException e) {
				throw new SerialPortParameterFailure();
			}
			return serialPort;
		} else {
			// 不是串口
			throw new NotASerialPort();
		}
	} catch (NoSuchPortException e1) {
		throw new NoSuchPort();
	} catch (PortInUseException e2) {
		throw new PortInUse();
	}
}
 
開發者ID:alidili,項目名稱:SerialPortDemo,代碼行數:49,代碼來源:SerialPortManager.java

示例15: connect

import gnu.io.NoSuchPortException; //導入依賴的package包/類
public void connect(String port, int baudRate, int timeout) throws IOException {
    scan();
    try {
        connect(CommPortIdentifier.getPortIdentifier(port), baudRate, timeout);
    } catch (NoSuchPortException e) {
        throw new IOException("No such port", e);
    }
}
 
開發者ID:MatzeS,項目名稱:blackbird,代碼行數:9,代碼來源:RXTXSerialPort.java


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