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


Java CommPortIdentifier.getPortType方法代码示例

本文整理汇总了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());
        }
    }
 
开发者ID:altnokburcu,项目名称:uyariSistemi,代码行数:38,代码来源:UI_uyari.java

示例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()]);
 }
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:23,代码来源:StreamCommand.java

示例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;
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:17,代码来源:ArduinoController.java

示例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;
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:27,代码来源:SerialConnection.java

示例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;
}
 
开发者ID:ltrr-arizona-edu,项目名称:tellervo,代码行数:22,代码来源:AbstractSerialMeasuringDevice.java

示例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);
	}

}
 
开发者ID:BrinoOficial,项目名称:Brino,代码行数:19,代码来源:MenuBar.java

示例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);
}
 
开发者ID:andrewrapp,项目名称:arduino-remote-uploader,代码行数:22,代码来源:SerialSketchUploader.java

示例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");
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:22,代码来源:PlugwiseStickDiscoveryService.java

示例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));
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:25,代码来源:PlugwiseCommunicationContext.java

示例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;
    }
 
开发者ID:lazyzero,项目名称:kkMulticopterFlashTool,代码行数:25,代码来源:PortScanner.java

示例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;
}
 
开发者ID:selfbus,项目名称:tools-libraries,代码行数:28,代码来源:SerialPortUtil.java

示例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();
    }
}
 
开发者ID:home-climate-control,项目名称:dz,代码行数:21,代码来源:SerialService.java

示例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();
}
}
 
开发者ID:juanurgiles,项目名称:breakserverosc,代码行数:22,代码来源:BreakoutServer.java

示例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();
}

}
 
开发者ID:juanurgiles,项目名称:breakserverosc,代码行数:29,代码来源:BreakoutServer.java

示例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);
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:14,代码来源:DynamixelDirect.java


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