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


Java SerialPort.close方法代码示例

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


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

示例1: stop

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * <p>stop</p>
 */
public void stop() {
	
	for( Pipe pipe : m_loggingPorts.values() )
	{
		pipe.stop();
	}
	
	m_loggingPorts.clear();
	
	System.out.print( "Closing " + m_openPorts.size() + " open comm ports... ");
	
	for( SerialPort port : m_openPorts.values() )
	{
		removeListener( port );
		port.close();
	}
	
	m_openPorts.clear();
	
	System.out.println("done.");
	
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:26,代码来源:RxtxCommands.java

示例2: closePort

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * 关闭串口
 * 
 * @param serialport
 *            待关闭的串口对象
 */
public static void closePort(SerialPort serialPort) {
	if (serialPort != null) {
		serialPort.close();
		serialPort = null;
	}
}
 
开发者ID:alidili,项目名称:SerialPortDemo,代码行数:13,代码来源:SerialPortManager.java

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

示例4: newLink

import gnu.io.SerialPort; //导入方法依赖的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: handleEvent

import gnu.io.SerialPort; //导入方法依赖的package包/类
public void handleEvent() {
	try {
		CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(SerialConf.WINDOWS_PORT);
		
		if (portId.isCurrentlyOwned()) {
			System.out.println("Port busy!");
		} else {
			CommPort commPort = portId.open("whatever it's name", SerialConf.TIME_OUT);
			if (commPort instanceof SerialPort) {
				serialPort = (SerialPort) commPort;
				serialPort.setSerialPortParams(SerialConf.BAUD, 
												SerialPort.DATABITS_8, 
												SerialPort.STOPBITS_1, 
												SerialPort.PARITY_EVEN);
				in = serialPort.getInputStream();
				serialPort.notifyOnDataAvailable(true);
				serialPort.addEventListener(this);
			} else {
				commPort.close();
				System.out.println("the port is not serial!");
			}
		}
	} catch (Exception e) {
		serialPort.close();
		System.out.println("Error: SerialOpen!!!");
		e.printStackTrace();
	}
}
 
开发者ID:lishiyun19,项目名称:Serial,代码行数:29,代码来源:SerialEvent.java

示例6: write

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * Write contents of stream inputStream to serial port
 * 
 * @param stream
 * @throws IOException
 * @throws UnsupportedCommOperationException
 * @throws PortInUseException
 */
public void write(InputStream inputStream) throws IOException,
		UnsupportedCommOperationException, PortInUseException {
	SerialPort serialPort = initSerialPort(getPortIdentifier(deviceName));
	OutputStream serialOut = serialPort.getOutputStream();
	writeTo(inputStream, serialOut);
	serialOut.close();
	serialPort.close();
}
 
开发者ID:Twissi,项目名称:Animator,代码行数:17,代码来源:FlashExporter.java

示例7: close

import gnu.io.SerialPort; //导入方法依赖的package包/类
@Override
synchronized public void close() {
	SerialPort t = port;
	port = null;
	if (t != null) {
		log.info("Closing port: " + t.getName());
		t.close();
		log.info("Port closed: " + portName);
	}
}
 
开发者ID:sp20,项目名称:modbus-mini,代码行数:11,代码来源:RtuTransportRxtx.java

示例8: _rxtxClose

import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
 * <p>_rxtxClose</p>
 *
 * @param intp a {@link org.eclipse.osgi.framework.console.CommandInterpreter} object.
 * @return a {@link java.lang.Object} object.
 */
public Object _rxtxClose(CommandInterpreter intp) {
	
	try
	{

		String id = intp.nextArgument();

		assertNotNull( id , "usage: rxtxClose <id>");
		assertOpenPort( id );
		
		Pipe pipe = m_loggingPorts.remove( id );
		
		if( pipe != null )
		{
			pipe.stop();
		}

		SerialPort port = m_openPorts.remove( id );

		intp.print("Closing port " + port.getName() + " with id " + id + "..." );

		port.close();

		intp.println("done.");


	}
	catch( IllegalArgumentException e) {
		intp.println( e.getMessage() );
	}

	return null;
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:40,代码来源:RxtxCommands.java


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