Discovering available comm ports

From Rxtx

Revision as of 06:19, 24 September 2007 by WgiD93 (Talk | contribs)
Jump to: navigation, search

oregon 938 st john cose fare soldato decapitato in iraq responsabile controllo di gestione settore bancario (regione toscana) banner maker pro manifestazione a udine forssa coniglietto di playboy varenne mazonaki processori intel celeron 2 4 ghz 2 4 ram fujitsu siemens centrifuga a unikatili xerox toner phaser vaccari c sas di guido vaccari eptano gruppo le vibrazioni moja domovina mitsubishi space runner 4wd i cinque disertori hp c8728a indiana jones nella rete philips sensotec sting arabo ginnastica per la schiena paola rosa tutte le malattie mentali dogus panasonic kxtcd515 connettori multipolari yashica ez zoom 105 trappole half jacket chrysler voyager 25 crd cube ver3 testo calma e sangue freddo di luca di ris u8180 cellulari lg la poetica di svevo me ne voglio anna www gq it opcine aasiaat troia citta antica petlust com geo vogel david una ragazza e quattro mitra tft 6 tv widescreen 28 inno haka epson stylus cx6600 telefono fisso telecom dlink 514 simulazioni tv al plasma e lcd philips lezioni di impianti tecnici vol 2 utopia lingo squad porno veline belle e porcelline iomega nas 100d series tv plasma lg 32 perfekte well stampanti per fotografie palloni da basket foto di ragazzi drogati coaster clito viva la raza eddie guerrero rgb database hard matiz roma vorst la donna di picche penna stilografica parker palmari bluethoot uma casa hard disk otg internet controller billie burke giubbino di jeans rich jeans dvdfab serial krla asta bandiera thin lizzy at rockpalast scheda audio esterna usb creative espresso dvd antispam free rete wifi zion y lenon giochi super divertenti game boy gc thomson dvd recorder kvm switch 4 port lettori mp3 con hard disk libro psicologia sedona ristorante robiie williams echinopsis usb card reader sexo ao vivo decapitazione marine americano fujifilm mv 1 vescica materiale edilizia campeggio ferrino sabrok incestuos nickelback silver side up divertimenti in calabria freudenstadt i love rock testo canzone napoletana video musical de hector y tito baila more lon wavelenght midi alexia adsl splitter dc 212 nokia 6230 black macinacaffe giochi di cavalli sangiuseppese lercara friddi toner laserjet 2200 batteria casio np20 incontro assisi finanziamento vittorio veneto garniga www taglia42 it biglietti concerto vasco bologna www lapecoranera it trasformazione renault scenic socci dante srl top escort assicurazione castelfranco veneto lg lx em330 udeur meat market vcr lg hangoor www enel it cabina armadio foppapedretti rubber johnny by chris cunningham masterizzatore samsung usb trasportini gatti ferrar sandman la trampa lq570 lx300 ritornerai lauzi fiera saie monitor 21 eizo volkswagen golf 1 9 tdi tux gallery dlink wireless bridge hunday coupe philips lettore mp3 20 gb www impero romano it mercedes accessori per autoradio acquamarina passat 20 16v percorso tra kiev roma kaoma video lambada kingston data traveler 2 pallone da calcio carolina marconi calendario 2005 pentium 4 3 2 e ghz ht 800 mhz blero kthehu bosch kgp36360 primi sogni escandalo nike shox bianco celeste 40 zaini uomo kingston compact flash 1024 il caso justin business web site hosting rainbow wonderful lise hearns puma scarpe moda tiebreak il coltello nella piaga ati 9600 pro 256 mb giacca armani etimologia della parola informare oraziano stampante ip4200 canon johnny knoxville bar prefabbricato amstrad divx dx 3010 usher jay z ludacris liceo scientifico primo levi the sims ps2 videogiochi orologio lorenz mp3 rosa clay aiken hd dv 8000 excite bike 64 hallelujia sistema retributivo silent cristmas This code snippet shows how to iretrive the available comms ports on your computer. A CommPort is available if it is not being used by another application. Note the differrence between the two examples is that the version for JDK 5.0 up uses generics:

JDK <= 1.4

   /**
     * @return    A HashSet containing the CommPortIdentifier for all serial ports that are not currently being used.
     */
    public static HashSet getAvailableSerialPorts() {
        HashSet h = new HashSet();
        Enumeration thePorts = CommPortIdentifier.getPortIdentifiers();
        while (thePorts.hasMoreElements()) {
            CommPortIdentifier com = (CommPortIdentifier) thePorts.nextElement();
            switch (com.getPortType()) {
            case CommPortIdentifier.PORT_SERIAL:
                try {
                    CommPort thePort = com.open("CommUtil", 50);
                    thePort.close();
                    h.add(com);
                } catch (PortInUseException e) {
                    System.out.println("Port, "   com.getName()   ", is in use.");
                } catch (Exception e) {
                    System.err.println("Failed to open port "   com.getName());
                    e.printStackTrace();
                }
            }
        }
        return h;
    }

JDK >= 5.0

   /**
     * @return    A HashSet containing the CommPortIdentifier for all serial ports that are not currently being used.
     */
    public static HashSet<CommPortIdentifier> getAvailableSerialPorts() {
        HashSet<CommPortIdentifier> h = new HashSet<CommPortIdentifier>();
        Enumeration thePorts = CommPortIdentifier.getPortIdentifiers();
        while (thePorts.hasMoreElements()) {
            CommPortIdentifier com = (CommPortIdentifier) thePorts.nextElement();
            switch (com.getPortType()) {
            case CommPortIdentifier.PORT_SERIAL:
                try {
                    CommPort thePort = com.open("CommUtil", 50);
                    thePort.close();
                    h.add(com);
                } catch (PortInUseException e) {
                    System.out.println("Port, "   com.getName()   ", is in use.");
                } catch (Exception e) {
                    System.err.println("Failed to open port "   com.getName());
                    e.printStackTrace();
                }
            }
        }
        return h;
    }
Personal tools