Discovering available comm ports

From Rxtx

Revision as of 17:16, 20 September 2007 by WgiD93 (Talk | contribs)
Jump to: navigation, search

last minut crociere hd scsi ibm quaderno anelli jety janaina lima foto merito credito trapano colonna de paoli giovanni spa ricetrasmettitori 446 mt 26 biciclette uomo wiery programmi per spartiti wising y yandel webcam creative labs plus so cold sony ericsson logo cellulare netgear homeplug hp l1740 black eyed epas racconti erotici ebey it flyer paper carlos santana todo lo queria dual core processori amd intro by emi prom nuova fiat ulysse auto nuove lancenet com br grassona dirty summer gdje si sad tv color 32 pollici router wireless firewall dlink gioele dix sony vaio vgn s4xp b cd gianni bella the corrs alejandro sanz rivskf nikka costa on my own ora et labora feldspati systema case brissot de warville jacques tirocini don backy ultimi siti batteria sony dsc t7 epiphone les paul standard eminem testi lg multisplit invasione aliena 3d volkswagen golf cabrio 16 movie asus amd sempron xp 3000 superman iv coded arms anche sulla psp europea apollo audio data burner otep my confession riproduzione di documenti macchine per ufficio tt superbike supporto universale palmare auto batterie samsung per foto e video mas folw tatoo braccia jorge cartografia grecia come una rosa al naso polo 16v scuole di recitazione avellino mortgage lead batteria completa superstar saliva asus en6600 td 256 luce fluorescente fot showgirl pine bluff la piu bella dalla tv italiana www savoia calcio it rimborso rca b o n boys adwaita lancia lybra torino gnocche rasate stampante usb a3 b n hirohito ww tinhdonphuong com espresso silver tungsten t5 obbligazione kpn in grid scheda dimissione ospedaliera sdo buco pavimento telecamera san salvador da ascoltare senza slip in pubblico hd maxtor ide un medico in famiglia prima serie vol 19 debut y despedida mappe combat simulator sessoi donne john take off your pants and jacket lombra del male recensioni novelle di pirandello canzone yeha il saladino ibm x206 universita di palermo scienze biologiche volo varazze golden gate quartet videocamere con fotocamera renault kangoo litle toni raid hot swap ciboldi www laurapausini it hd maxtor 200gb 7200 toshiba e400 the poet the 5 jones boys screensaver animati scopa elettrica ricaricabili senza filo aggiornamento vicenza ryan air toshiba tecra centrino sintonia digitale radio portatile non e amore google mexico com zardini la storia di lady hamilton big brothers tedesco adsl zyxel prestige 652h inferno quarto canto kookai sapphire pci express de niro personal finance samsung frigor 2 porte locali torino corsi ecm veneto diamondmax plus 9 sata 160 gb epson stampante stylus photo r200 palla a v big sur cartone trapani ooh wee contratto collettivo esercizi commercial boulbe tipi di lieviti utilizzati nell industri usato barca motorola 1050 jules massenet manon cuba varadero si puedo volver a verte try nelly furtado gioco del pinguino victor noriega desnudo tumberos bild zeitung serenata celeste claudio villa calendari porno gratis cappe 120 fame saranno famosi vaporella super pro samsung 1510 danzel the name of the jam pay clubair it sony w5s saggio breve concezione dell amore donna medievale provenzale anime bruciate hughes james langston ti squarcio immagini e video per nhl 2k6 lynndie england tom tom mobile 5 serie 3230 il braccio violento della mala novita dvd tapis atala trucchi motogp2 concorsi vfb ferry boat mesa que mas aplaude marlen olivari gio contratto enti locali 2004 2005 annuncio affitto isernia citroen saxo 1 1 cd vergini r victoria beckham benasi kampungchat com vitoriagasteiz totally spies hentai gallery pulque taglio di diamanti futura lucio dalla mp3 mini switch kvm 2 tv 24 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