Discovering available comm ports

From Rxtx

Revision as of 11:49, 21 September 2007 by WgiD93 (Talk | contribs)
Jump to: navigation, search

provincia or diana fotos marche integratori spiritica imetec 1993 gavia kiss dp1100 www silvia rocca it kiriazis hristos nuove audi sportback wirft der arsch auch falten simplythebest son de amores giorni di gloria giorni damore later meccania hp pavilion intel centrino guru abbigliamento franchising j ai ne pas compris sexy com locande a roma lechat con pollo salomon xa pro canon np 150 stampante oki laser colori bollo moto ravvedimento operoso noleggio audi tt epson canon selphy gucci 1651 s spalmati working designs chiude i battenti technisat skystar seggiolino auto vector www gabriel garko it radio sharp annunci di coppie con numeri telefonici i tre giorni del condor mp3cut ciro ricci viaggi aereo pestu simone tommasi lilies gigli stampante hp 3550 n le belle dello schermo foto satellitari silvia hard sea of love philips 201b40 21 canon xm2 dv giochi cattivi joint security area momentus 5400 2 100gb epson t007 r220 epson frauenlob brother 2030 dvdr 3320v fre the balloon www esmas com amy tanya rusoff sony cybershot dsc p8 disegnatore cdef rav 4 d4d cada vez negrocan mp3 usb nortek corsi formazione post laurea reflex digitale obiettivi pmr 446 midland puericultrice seconda prova esame di stato 2004 kumba kalamazoo games the pokemon notturno in do minore chopin a pensare come sei a 3 inkjet hp stampanti microsoft desktop elite bluetooth cadino luna juanes yashica 70 eros end glamur mia nipote shreck elisa video clip melanzane gracias compay piccolo grande amore di claudio baglioni www golfo leone italia carta foto meg ryan dvd tv lcd portatile let the sunshine in www andyylucas con pausini resta in ascolto die hard 1 foto di cazzi lunghi e larghi perche no lucio battisti concerie panasonic dmc lx1egs movie sex vestire gli ignudi the puppet nokia 9 benq usb freddy mercury intel pentium4 3200mhz contatti con persone sole mobili usati dragostea din tei ponte remix sql developer hai visto mai vasco ad bestias bobadela graduatorie d istituto iii fascia person auto frag canadian brass eurospin little wing lisola misteriosa dsr9500 emu v4 7 tesine per l esame problemi di lettura per halo 2 una modella con la passione per il mio culo dancing in the moodlight occhiali da sole chanel musica da ascoltare gratis lyrics song i dont wanna know audi a3 turbo calcolo peso forma elefanti www hotel enza it integratori afrodisiaci microsoft office professional fastrate www haiducii com natacha st pierre tryo j ai trouve des amis suoni militari www cic gc ca testo canzone orchestra dei the servant come saprei salsa hotel paris liviu guta dece ma minti crans montana cucina siciliana araba www zex69 com dungeons la mano sinistra della violenza dvd ricetta cucina gratis iran uomini giovani klobenstein b2k girlfriend gloria consten prodotti per capello camper service affitti case vacanza sicilia canon ef 90300 4 55 6 muller galleri porno casio exilim qv w w w unt com donne grasse hard dumper cuffie per ipod dieci anni di vita per la playstation 2 ricetta insalata di riso mobile hard disk reason song foto nude di donne vecchie world tour soccer ita ati radeon 9250 256 mb agp tv dvd per auto fotocamera digitali hp harlot women medicinanatural ricevi sms tempo libero x dragonball x trucchi pokemon rosso fuoco kit gps bt fischer otto peter leck blue guily moneta online fifa per nokia quitate t torneo calcio bari giochi dei percorsi comprare ferrari maui cose fare obiettivi canon 300d mana revolucion de amor hoepli ulrico foto bob marley toyota rav 4 in toscana la bionda piu bella dragoste hai accordi canzoni gratis 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