本文整理汇总了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.");
}
示例2: closePort
import gnu.io.SerialPort; //导入方法依赖的package包/类
/**
* 关闭串口
*
* @param serialport
* 待关闭的串口对象
*/
public static void closePort(SerialPort serialPort) {
if (serialPort != null) {
serialPort.close();
serialPort = null;
}
}
示例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();
}
}
示例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();
}
};
}
示例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();
}
}
示例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();
}
示例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);
}
}
示例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;
}