本文整理汇总了Java中gnu.io.CommPortIdentifier.isCurrentlyOwned方法的典型用法代码示例。如果您正苦于以下问题:Java CommPortIdentifier.isCurrentlyOwned方法的具体用法?Java CommPortIdentifier.isCurrentlyOwned怎么用?Java CommPortIdentifier.isCurrentlyOwned使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.io.CommPortIdentifier
的用法示例。
在下文中一共展示了CommPortIdentifier.isCurrentlyOwned方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SerialComm
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* Constructor
*
* @param portName
* The name of the serial port
* @param listeners
* The listeners for incoming telegrams
* @throws Exception
*/
public SerialComm(String portName, ArrayList<EnoceanListener> listeners)
throws Exception {
this.listeners = listeners;
CommPortIdentifier portIdentifier = CommPortIdentifier
.getPortIdentifier(portName);
if (portIdentifier.isCurrentlyOwned()) {
throw new Exception("Port is currently in use");
}
CommPort commPort = portIdentifier
.open(this.getClass().getName(), 2000); // timeout 2 s.
if (!(commPort instanceof SerialPort)) {
throw new Exception("Only serial port is supported");
}
port = commPort;
SerialPort serialPort = (SerialPort) commPort;
// 57600 bit/s, 8 bits, stop bit length 1, no parity bit
serialPort.setSerialPortParams(57600, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
input = serialPort.getInputStream();
output = serialPort.getOutputStream();
}
示例2: connect
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
void connect(String destination) throws Exception {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(destination);
if (portIdentifier.isCurrentlyOwned()) {
log.warning("Error: Port for Dynamixel-Communication is currently in use");
} else {
CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
if (commPort instanceof SerialPort) {
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(57600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
in = serialPort.getInputStream();
out = serialPort.getOutputStream();
serialReader = new SerialReader(in);
serialPort.addEventListener(serialReader);
serialPort.notifyOnDataAvailable(true);
connected = true;
log.info("Connected to Dynamixel!");
} else {
log.warning("Error: Cannot connect to Dynamixel!");
}
}
}
示例3: connect
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
void connect(String destination) throws Exception {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(destination);
if (portIdentifier.isCurrentlyOwned()) {
log.warning("Error: Port for Pan-Tilt-Communication is currently in use");
} else {
CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
if (commPort instanceof SerialPort) {
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
in = serialPort.getInputStream();
out = serialPort.getOutputStream();
serialPort.addEventListener(new SerialReader(in));
serialPort.notifyOnDataAvailable(true);
connected = true;
log.info("Connected to Pan-Tilt-Unit!");
} else {
log.warning("Error: Cannot connect to Pan-Tilt-Unit!");
}
}
}
示例4: connect
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
void connect(String destination) throws Exception {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(destination);
if (portIdentifier.isCurrentlyOwned()) {
log.warning("Error: Port for Dynamixel-Communication is currently in use");
} else {
CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
if (commPort instanceof SerialPort) {
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(57142, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
in = serialPort.getInputStream();
out = serialPort.getOutputStream();
serialPort.addEventListener(new SerialReader(in));
serialPort.notifyOnDataAvailable(true);
log.info("Connected to Dynamixel!");
} else {
log.warning("Error: Cannot connect to Dynamixel!");
}
}
}
示例5: connect
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/** Method to connect to an available port */
@SuppressWarnings("static-access")
private void connect(String portName) throws Exception {
CommPortIdentifier commPortIdentifier = CommPortIdentifier.getPortIdentifier(portName);
if (commPortIdentifier.isCurrentlyOwned()) {
System.out.println("Error: Port is currently in use");
} else {
CommPort commPort = commPortIdentifier.open(this.getClass().getName(), 2000);
if (commPort instanceof SerialPort) {
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(References.BAUDRATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
this.inputStream = serialPort.getInputStream();
this.outputStream = serialPort.getOutputStream();
References.SERIAL_READER = new SerialReader(this.inputStream);
readThread = new Thread(References.SERIAL_READER);
readThread.start();
} else {
System.out.println("Error: Only serial ports allowed");
}
}
}
示例6: open
import gnu.io.CommPortIdentifier; //导入方法依赖的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();
}
}
示例7: getPort
import gnu.io.CommPortIdentifier; //导入方法依赖的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);
}
示例8: connect
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
public void connect(String portName) throws Exception {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
LOG.info("Found the " + portName + " port.");
if (portIdentifier.isCurrentlyOwned()) {
LOG.error("Port is currently in use");
} else {
CommPort commPort = portIdentifier.open(this.getClass().getName(), 2000);
LOG.info("Opened port " + portName);
if (commPort instanceof SerialPort) {
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.PARITY_EVEN, SerialPort.FLOWCONTROL_NONE);
printWriter = new PrintWriter(serialPort.getOutputStream());
bufferedReader = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
// For skipping AnA string
skipInput();
} else {
LOG.error("Only serial ports are handled by this example.");
}
}
}
示例9: connect
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
private void connect(String portName) throws Exception {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
if (portIdentifier.isCurrentlyOwned())
throw new PortInUseException();
CommPort commPort = portIdentifier.open(this.getClass().getName(), COMPORT_PORT);
if (commPort instanceof SerialPort) {
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(BAUD_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
InputStream in = serialPort.getInputStream();
OutputStream out = serialPort.getOutputStream();
new Thread(new SerialReader(in)).start();
new Thread(new SerialWriter(out)).start();
} else {
throw new PortUnreachableException("ERROR - Only serial ports are handled by this class");
}
}
示例10: handleEvent
import gnu.io.CommPortIdentifier; //导入方法依赖的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();
}
}
示例11: discoverSticks
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
protected void discoverSticks() {
if (discovering) {
logger.debug("Stick discovery not possible (already discovering)");
} else {
discovering = true;
@SuppressWarnings("unchecked")
Enumeration<CommPortIdentifier> portIdentifiers = CommPortIdentifier.getPortIdentifiers();
while (discovering && portIdentifiers.hasMoreElements()) {
CommPortIdentifier portIdentifier = portIdentifiers.nextElement();
if (portIdentifier.getPortType() == CommPortIdentifier.PORT_SERIAL
&& !portIdentifier.isCurrentlyOwned()) {
discoverStick(portIdentifier.getName());
}
}
discovering = false;
logger.debug("Finished discovering Sticks on serial ports");
}
}
示例12: openPort
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
private void openPort(String id) {
System.out.printf("opening port %s @ %d bauds\n", id, this.baudRate);
try {
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(id);
if (portId.isCurrentlyOwned()) {
System.err.printf("error: %s port currently in use\n", id);
return;
}
CommPort commPort = portId.open(this.getClass().getName(), 5000);
if (commPort instanceof SerialPort) {
this.port = (SerialPort) commPort;
this.port.setSerialPortParams(this.baudRate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
this.portOut = this.port.getOutputStream();
} else {
System.err.printf("error: port %s is not serial\n", id);
return;
}
} catch (Exception e) {
System.err.printf("error: cannot find/open port %s\n", id);
System.err.printf("%s\n", e.getMessage());
}
}
示例13: SerialRXTXComm
import gnu.io.CommPortIdentifier; //导入方法依赖的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);
}
示例14: connect
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
void connect(String portName, int speed) throws Exception {
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
if (portIdentifier.isCurrentlyOwned()) {
throw (new Exception("Error: Port is currently in use"));
} else {
CommPort commPort = portIdentifier.open("MEEPROMMER", 2000);
if (commPort instanceof SerialPort) {
serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(speed, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
in = serialPort.getInputStream();
out = serialPort.getOutputStream();
} else {
throw (new Exception("Error: Only serial ports are handled by this example."));
}
}
}
示例15: connect
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* Opening a connection to the specified Serial port, using the specified
* speed. After opening the port, messages can be sent using
* {@link #writeSerial(String)} and received data will be packed into
* packets (see {@link #divider}) and forwarded using
* {@link org.zu.ardulink.connection.ConnectionContact#parseInput(int, int, int[])}.
*
* @param portName
* The name of the port the connection should be opened to (see
* {@link #getPortList()}).
* @param speed
* The desired speed of the connection in bps.
* @return <b>true</b> if the connection has been opened successfully,
* <b>false</b> otherwise.
*/
public boolean connect(String portName, int speed) {
boolean retvalue = false;
CommPortIdentifier portIdentifier;
try {
portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
if (portIdentifier.isCurrentlyOwned()) {
writeLog("Error: Port is currently in use");
} else {
serialPort = (SerialPort) portIdentifier.open("RTBug_network",2000);
serialPort.setSerialPortParams(speed, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
setInputStream(serialPort.getInputStream());
setOutputStream(serialPort.getOutputStream());
startReader();
writeLog("connection on " + portName + " established");
getContact().connected(getId(), portName);
setConnected(true);
retvalue = true;
}
} catch (Exception e) {
writeLog("the connection could not be made " + e.getMessage());
e.printStackTrace();
}
return retvalue;
}