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


Java CommPortIdentifier.getPortIdentifiers方法代碼示例

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


在下文中一共展示了CommPortIdentifier.getPortIdentifiers方法的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: getSerialPort

import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
private CommPortIdentifier getSerialPort() {
	
	if (port != null) {
		try {
			return CommPortIdentifier.getPortIdentifier(port);
		} catch (NoSuchPortException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	Enumeration<?> portEnum = CommPortIdentifier.getPortIdentifiers();
	while (portEnum.hasMoreElements()) {
		CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
		for (String portName : PORT_NAMES) {
			if (currPortId.getName().equals(portName)) {
				return currPortId;
			}
		}
	}
	return null;
}
 
開發者ID:claudiotrindade,項目名稱:contexttoolkit,代碼行數:23,代碼來源:SerialConnection.java

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

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

示例9: oeffneSerialPort

import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
/**
 * Versucht den seriellen Port zu �ffnen. Klappt nur, wenn er noch nicht von einer anderen Anwendung benutzt wird. Der jeweilige
 * Port wird mit �bergeben. UNter Windows ist die Schreibweise "COM8" zum Beispeil unter Linux "dev/tts0"
 * @param portName
 * @return
 * @throws PortInUseException
 * @throws IOException
 * @throws UnsupportedCommOperationException
 */
public boolean oeffneSerialPort(String portName) throws PortInUseException, IOException, UnsupportedCommOperationException
{
	Boolean foundPort = false;
	if (serialPortGeoeffnet != false) {
		System.out.println("Serialport bereits ge�ffnet");
		schliesseSerialPort();
		return false;
	}
	System.out.println("�ffne Serialport");
	enumComm = CommPortIdentifier.getPortIdentifiers();
	while(enumComm.hasMoreElements()) {
		serialPortId = (CommPortIdentifier) enumComm.nextElement();
		System.out.println("SerialportIDs:" + serialPortId.getName());
		if (portName.contentEquals(serialPortId.getName())) {
			foundPort = true;
			break;
		}
	}
	if (foundPort != true) {
		System.out.println("Serialport nicht gefunden: " + portName);
		return false;
	}
	    serialPort = (SerialPort) serialPortId.open("�ffnen und Senden", 500);
		outputStream = serialPort.getOutputStream();
		inputStream = serialPort.getInputStream();
	
	serialPort.notifyOnDataAvailable(true);
		serialPort.setSerialPortParams(baudrate, dataBits, stopBits, parity);
	
	
	serialPortGeoeffnet = true;
	return true;
}
 
開發者ID:SecUSo,項目名稱:EasyVote,代碼行數:43,代碼來源:VCDSerialPort.java

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

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

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

示例13: initialize

import gnu.io.CommPortIdentifier; //導入方法依賴的package包/類
public void initialize(testEngine tee) {
	te=tee;
    CommPortIdentifier portId = null;
    Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
    // iterate through, looking for the port
    while (portEnum.hasMoreElements()) {
        CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
        for (String portName : PORT_NAMES) {
            if (currPortId.getName().equals(portName)) {
                portId = currPortId;
                break;
            }
        }
    }
    if (portId == null) {
        te.log("Could not find COM port.");
        return;
    }else{
        te.log("Found your Port");
    }
    try {
        // open serial port, and use class name for the appName.
        serialPort = (SerialPort) portId.open(this.getClass().getName(),TIME_OUT);
        // set port parameters
        serialPort.setSerialPortParams(DATA_RATE,
                SerialPort.DATABITS_8,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);
        // open the streams
        input = serialPort.getInputStream();
        output = serialPort.getOutputStream();
        // add event listeners
        serialPort.addEventListener(this);
        serialPort.notifyOnDataAvailable(true);
    } catch (Exception e) {
        System.err.println(e.toString());
    }
}
 
開發者ID:agbishara,項目名稱:V2R,代碼行數:39,代碼來源:comm.java

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

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


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