本文整理汇总了Java中gnu.io.CommPortIdentifier.getPortType方法的典型用法代码示例。如果您正苦于以下问题:Java CommPortIdentifier.getPortType方法的具体用法?Java CommPortIdentifier.getPortType怎么用?Java CommPortIdentifier.getPortType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.io.CommPortIdentifier
的用法示例。
在下文中一共展示了CommPortIdentifier.getPortType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
public void initialize() {
System.setProperty("gnu.io.rxtx.SerialPorts", getComPortName());
CommPortIdentifier portId = null;
Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
while (portEnum.hasMoreElements()) {
CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
if(currPortId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (currPortId.getName().equals(txtComPortName.getText())) {
System.out.println(txtComPortName.getText());
portId = currPortId;
break;
}
}
}
if (portId == null) {
JOptionPane.showMessageDialog(null," Portuna bağlı cihaz yok!","Hata",JOptionPane.ERROR_MESSAGE);
System.out.println("Porta bağlı cihaz yok!");
return;
}
System.out.println(portId);
try {
serialPort = (SerialPort) portId.open(this.getClass().getName(), TIME_OUT);
serialPort.setSerialPortParams(DATA_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
output = serialPort.getOutputStream();
serialPort.addEventListener((SerialPortEventListener) this);
serialPort.notifyOnDataAvailable(true);
} catch (Exception e) {
System.err.println(e.toString());
}
}
示例2: getPortNames
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* gets a list of all available serial port names
*
* @return a platform dependent list of strings representing all the
* available serial ports -- it is the application's responsibility
* to identify the right port to which the device is actually connected
*/
public String[] getPortNames()
{
ArrayList<String> ret= new ArrayList<String>();
Enumeration<CommPortIdentifier> portsEnum= CommPortIdentifier.getPortIdentifiers();
while(portsEnum.hasMoreElements())
{
CommPortIdentifier pid= portsEnum.nextElement();
if (pid.getPortType() == CommPortIdentifier.PORT_SERIAL) {
ret.add(pid.getName());
}
}
return ret.toArray(new String[ret.size()]);
}
示例3: findSerialPort
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
public static CommPortIdentifier findSerialPort() throws Exception {
CommPortIdentifier serialPort = null;
@SuppressWarnings("unchecked")
java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
while ( portEnum.hasMoreElements() )
{
CommPortIdentifier portIdentifier = portEnum.nextElement();
if (CommPortIdentifier.PORT_SERIAL==portIdentifier.getPortType()) {
if (serialPort==null)
serialPort = portIdentifier;
else
throw new Exception("More than one serial port found! "+serialPort.getName()+" and "+portIdentifier.getName());
}
}
return serialPort;
}
示例4: getPortList
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* This method is used to get a list of all the available Serial ports
* (note: only Serial ports are considered). Any one of the elements
* contained in the returned {@link List} can be used as a parameter in
* {@link #connect(String)} or {@link #connect(String, int)} to open a
* Serial connection.
*
* @return A {@link List} containing {@link String}s showing all available
* Serial ports.
*/
public List<String> getPortList() {
List<String> ports = new ArrayList<String>();
Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
ports.add(portId.getName());
}
}
writeLog("found the following ports:");
for (String port : ports) {
writeLog(" " + port);
}
return ports;
}
示例5: enumerateSerialPorts
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* Get a vector of all the ports identified on this computer
*
* @return
*/
public static Vector enumerateSerialPorts() {
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
Vector portStrings = new Vector();
while(ports.hasMoreElements()) {
CommPortIdentifier currentPort = (CommPortIdentifier)ports.nextElement();
if(currentPort.getPortType() != CommPortIdentifier.PORT_SERIAL)
continue;
portStrings.add(new String(currentPort.getName()));
}
return portStrings;
}
示例6: setComs
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
public void setComs() {
ArrayList<String> comList = new ArrayList<String>();
Enumeration<CommPortIdentifier> comm = CommPortUtils.getComPorts();
while (comm.hasMoreElements()) {
CommPortIdentifier port_identifier = (CommPortIdentifier) comm
.nextElement();
if (port_identifier.getPortType() == CommPortIdentifier.PORT_SERIAL) {
// if (!comOldList.contains(port_identifier.getName()))
comList.add(port_identifier.getName());
}
}
if (comList.isEmpty()) {
addCom("N�o h� portas dispon�veis");
} else {
addCom(comList);
}
}
示例7: findPort
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
public CommPortIdentifier findPort(String port) {
// parse ports and if the default port is found, initialized the reader
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
//System.out.println("Found port: " + portId.getName());
if (portId.getName().equals(port)) {
//System.out.println("Using Port: " + portId.getName());
return portId;
}
}
}
throw new RuntimeException("Port not found " + port);
}
示例8: 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");
}
}
示例9: findSerialPortIdentifier
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private CommPortIdentifier findSerialPortIdentifier() throws PlugwiseInitializationException {
Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier identifier = portList.nextElement();
if (identifier.getPortType() == CommPortIdentifier.PORT_SERIAL
&& identifier.getName().equals(configuration.getSerialPort())) {
logger.debug("Serial port '{}' has been found", configuration.getSerialPort());
return identifier;
}
}
// Build exception message when port not found
StringBuilder sb = new StringBuilder();
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier id = portList.nextElement();
if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
sb.append(String.format("%s%n", id.getName()));
}
}
throw new PlugwiseInitializationException(String.format(
"Serial port '%s' could not be found. Available ports are:%n%s", configuration.getSerialPort(), sb));
}
示例10: listSerialPorts
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* @return List all serial ports
*/
public static Vector<String> listSerialPorts()
{
Vector<String> ports = new Vector<String>();
if (KKMulticopterFlashTool.ENABLE_PORT_CHECK) {
java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
while ( portEnum.hasMoreElements() )
{
CommPortIdentifier portIdentifier = portEnum.nextElement();
if (portIdentifier.getPortType()==CommPortIdentifier.PORT_SERIAL){
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
if (portIdentifier.getName().contains("cu")){
ports.add(portIdentifier.getName());
}
} else {
ports.add(portIdentifier.getName());
}
}
}
}
return ports;
}
示例11: getPortNames
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* Get a list of the available serial ports.
*
* @return the names of the available serial ports, alphabetically sorted.
*/
public static String[] getPortNames()
{
if (!serialPortLibLoaded)
loadSerialPortLib();
final Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
final Vector<String> portNames = new Vector<String>(20);
while (portList.hasMoreElements())
{
CommPortIdentifier portIdent = (CommPortIdentifier) portList.nextElement();
if (portIdent.getPortType() == CommPortIdentifier.PORT_SERIAL)
portNames.add(portIdent.getName());
}
final String[] result = new String[portNames.size()];
portNames.toArray(result);
Arrays.sort(result);
return result;
}
示例12: getSerialPortIdentifiers
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static Enumeration<String> getSerialPortIdentifiers() {
synchronized(vPortIDs) {
if(vPortIDs.isEmpty()) {
for (Enumeration<CommPortIdentifier> e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements(); ) {
CommPortIdentifier portID = e.nextElement();
if (portID.getPortType() == CommPortIdentifier.PORT_SERIAL) {
vPortIDs.add(portID.getName());
}
}
}
return vPortIDs.elements();
}
}
示例13: createPortList
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* Populate the serial port drop-down list
*/
private void createPortList() {
try {
Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
String name = portId.getName();
// ignore /dev/tty to prevent duplicate serial port listings (/dev/tty and /dev/cu)
//if (!name.startsWith("/dev/tty.")) {
serialPorts.addItem(name);
//}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例14: checkPortList
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/**
* Check if the serial port list has changed
*/
private void checkPortList() {
serialPortCount = 0;
try {
Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
String name = portId.getName();
if (!name.startsWith("/dev/tty.")) {
serialPortCount++;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (serialPortCount != serialPorts.getItemCount()) {
// an I/O board was added or removed so update the list
updatePortList();
}
}
示例15: DynamixelDirect
import gnu.io.CommPortIdentifier; //导入方法依赖的package包/类
/** Creates new form DynamixelController */
public DynamixelDirect() {
initComponents();
Enumeration pList = CommPortIdentifier.getPortIdentifiers();
while (pList.hasMoreElements()) {
CommPortIdentifier cpi = (CommPortIdentifier) pList.nextElement();
if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) {
cbxPort.addItem(cpi.getName());
}
}
cbxPort.setSelectedIndex(-1);
}