當前位置: 首頁>>代碼示例>>Java>>正文


Java CommPortIdentifier.getName方法代碼示例

本文整理匯總了Java中gnu.io.CommPortIdentifier.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java CommPortIdentifier.getName方法的具體用法?Java CommPortIdentifier.getName怎麽用?Java CommPortIdentifier.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gnu.io.CommPortIdentifier的用法示例。


在下文中一共展示了CommPortIdentifier.getName方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

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

示例2: listPorts

import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
public String listPorts() {
	List<String> port_name = new ArrayList<String>();
	String tmp = "";

	// int i = 0;
	@SuppressWarnings("unchecked")
	Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier
			.getPortIdentifiers();

	// Enumeration portList = CommPortIdentifier.getPortIdentifiers();
	while (portEnum.hasMoreElements()) {
		CommPortIdentifier portIdentifier = (CommPortIdentifier) portEnum
				.nextElement();
		if (getPortTypeName(portIdentifier.getPortType()) == "Serial") {
			port_name.add(portIdentifier.getName());
			String tmp2 = portIdentifier.getName() + "#";

			tmp = tmp + tmp2;
		}
		System.out.println(portIdentifier.getName() + " - "
				+ getPortTypeName(portIdentifier.getPortType()));
	}
	// i = port_name.size();

	return tmp;
}
 
開發者ID:tomazas,項目名稱:ATCommandTester,代碼行數:27,代碼來源:TwoWaySerialComm2.java

示例3: enumeratePorts

import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
public static List<CommPortIdentifier> enumeratePorts() {
    List<CommPortIdentifier> ports = new LinkedList<CommPortIdentifier>();

    Enumeration<?> portEnum = CommPortIdentifier.getPortIdentifiers();
    while (portEnum.hasMoreElements()) {
        CommPortIdentifier portIdentifier = (CommPortIdentifier) portEnum.nextElement();
        for (Pattern acceptablePortName : ACCEPTABLE_PORT_NAMES) {
            String portName = portIdentifier.getName();
            if (acceptablePortName.matcher(portName).matches()) {
                ports.add(portIdentifier);
            }
        }
    }

    return ports;
}
 
開發者ID:Chatanga,項目名稱:Girinoscope,代碼行數:17,代碼來源:Serial.java

示例4: createSerialMenu

import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
private JMenu createSerialMenu() {
JMenu menu = new JMenu("Serial port");
ButtonGroup group = new ButtonGroup();
for (final CommPortIdentifier portId : Serial.enumeratePorts()) {
    Action setSerialPort = new AbstractAction(portId.getName()) {

	@Override
	public void actionPerformed(ActionEvent event) {
	    UI.this.portId = portId;
	}
    };
    AbstractButton button = new JCheckBoxMenuItem(setSerialPort);
    if (UI.this.portId == null) {
	button.doClick();
    }
    group.add(button);
    menu.add(button);
}
return menu;
   }
 
開發者ID:Chatanga,項目名稱:Girinoscope,代碼行數:21,代碼來源:UI.java

示例5: getPortList

import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
public static String[] getPortList() {
    Enumeration portList = CommPortIdentifier.getPortIdentifiers();

    int portCount = 0;
    while (portList.hasMoreElements()) {
        portList.nextElement();
        portCount++;
    }

    String[] retVal = new String[portCount];

    portCount = 0;
    portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
        CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
        retVal[portCount++] = portId.getName();
    }

    return retVal;
}
 
開發者ID:bartprokop,項目名稱:rxtx,代碼行數:21,代碼來源:Demo1.java

示例6: listSerialPorts

import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
/**
 * Retrieves the list of available serial ports in the system.
 * 
 * @return List of available serial ports.
 * 
 * @see #listSerialPortsInfo()
 */
public static String[] listSerialPorts() {
	ArrayList<String> serialPorts = new ArrayList<String>();
	
	@SuppressWarnings("unchecked")
	Enumeration<CommPortIdentifier> comPorts = CommPortIdentifier.getPortIdentifiers();
	if (comPorts == null)
		return serialPorts.toArray(new String[serialPorts.size()]);
	
	while (comPorts.hasMoreElements()) {
		CommPortIdentifier identifier = (CommPortIdentifier)comPorts.nextElement();
		if (identifier == null)
			continue;
		String strName = identifier.getName();
		serialPorts.add(strName);
	}
	return serialPorts.toArray(new String[serialPorts.size()]);
}
 
開發者ID:digidotcom,項目名稱:XBeeJavaLibrary,代碼行數:25,代碼來源:SerialPortRxTx.java

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

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

示例9: ListarPortas

import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
public static String[] ListarPortas(){		
	
	int i = 0;		
	String portas[] = new String[10];
	Enumeration<CommPortIdentifier> listaDePortas = CommPortIdentifier.getPortIdentifiers();
	
	while (listaDePortas.hasMoreElements()){
		CommPortIdentifier ips = listaDePortas.nextElement();
		portas[i] = ips.getName();
		i++;
	}
	
	return portas;
}
 
開發者ID:Jesm,項目名稱:Gomoku,代碼行數:15,代碼來源:Com.java

示例10: SearchForXbeeOnComports

import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
public boolean SearchForXbeeOnComports()
{
    if(isConnected())
        return true;

    @SuppressWarnings("unchecked")
    Enumeration<CommPortIdentifier> portIdentifiers = CommPortIdentifier.getPortIdentifiers();

    String osName = System.getProperty("os.name");
    String portName = null;
    boolean foundXbee = false;
    String comport;

    if (osName.equalsIgnoreCase("Mac OS X"))
        portName = "tty.usbserial";
    else if (osName.equalsIgnoreCase("Linux"))
        portName = "ttyUSB";

    if(portName != null)
    {
        while (portIdentifiers.hasMoreElements())
        {
            CommPortIdentifier pid = (CommPortIdentifier) portIdentifiers.nextElement();

            if (pid.getPortType() == CommPortIdentifier.PORT_SERIAL && !pid.isCurrentlyOwned() && pid.getName().contains(portName))
            {
                comport = pid.getName();
                try {
                    xbee.open(comport, 57600);
                    foundXbee = true;
                    break;
                } catch(XBeeException e) {
                    log.debug("Did not find XBee on comport " + comport);
                }

            }
        }
    }

    if(!foundXbee)
        return false;
    else
        return true;
}
 
開發者ID:utdrobotchess,項目名稱:chess-game,代碼行數:45,代碼來源:ChessbotCommunicator.java

示例11: main

import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
public static void main(String[] args) {
	
	try {
		
		Layer3Base base = new Layer3Base();
		
		// Find the serial port device
		CommPortIdentifier portId = null;
		Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
		while(portEnum.hasMoreElements()){
			CommPortIdentifier currPort = (CommPortIdentifier) portEnum.nextElement();
			String portName = currPort.getName();
			if(portName.startsWith("/dev/tty.usbmodem") || portName.startsWith("/dev/ttyACM")){
				portId = currPort;
			}
		}
		if(portId == null){
			throw new IOException("No serial port found matching the name pattern");
		}
		
		SerialRXTXComm serial = new SerialRXTXComm(portId, base);
		Thread.sleep(4000);
		Layer3Base.NetworkSetupThread setup = base.new NetworkSetupThread();
		Thread setupThread = new Thread(setup);
		setupThread.start();
		setupThread.join();
		// Alè, la rete è pronta, adesso posso giocare con i device
		
		Device device = Device.getDeviceFromUniqueId(384932);
		if(device!=null && device instanceof LedTestDevice){
			LedTestDevice ledDevice = (LedTestDevice) device;
			for(int i=0; i<5000; i++){
				ledDevice.setLedState(true);
				Thread.sleep(20);
				ledDevice.setLedState(false);
				Thread.sleep(50);
			}
		} else if(device!=null && device instanceof Led1Analog2Device){
			Led1Analog2Device ledDev = (Led1Analog2Device) device;
			for(int a=0; a<50; a++){
				for(int i=0; i<255; i+=2){
					ledDev.setLedPwmState(ledTable8bit[i]);
					//Thread.sleep(10);
				}
				for(int i=255; i>0; i-=2){
					ledDev.setLedPwmState(ledTable8bit[i]);
					//Thread.sleep(10);
				}
			}
		} else {
			System.out.println("Errore get device");
		}
		
		Device dev = Device.getDeviceFromUniqueId(484333);
		if(dev!=null && dev instanceof LedLamp1Device){
			LedLamp1Device lamp = (LedLamp1Device) dev;
			
			/*for(int i=0; i<6; i++){
				AbsoluteColor color1 = new AbsoluteColor(0, 0, 0);
				lamp.setColor(color1);
				Thread.sleep(1000);
			}*/
			
			
		} else {
			System.out.println("Error getting led lamp device");
		}
		
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	
}
 
開發者ID:mattibal,項目名稱:meshnet,代碼行數:75,代碼來源:MeshNetTest.java


注:本文中的gnu.io.CommPortIdentifier.getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。