Discovering available comm ports

From Rxtx

Revision as of 23:45, 26 September 2007 by WgiD93 (Talk | contribs)
Jump to: navigation, search

regione friuli asics scarpe moda manfrotto 055 pro gabriella labate pdp 2556 player gratuiti canon powershot s60 calvignasco fottuti stronzi ragazza straniera pioneer dvd 109 masterizzatore tiscali italia chopin bal 23 hely attac left outsdie alone ignis tuttigiorni antivirus worm hitler foto bodeo sakura wars vol 02 bandera del estado de texas videoregistratore hifi a 6 testine esibizionismo psichiatria apocalisse 23 testi raiz scegli me donne in cerca di sesso hetian camicie uomo versace asus p5nd2 deluxe sony cineprese video voli desenzano del garda marseillaise ytfh pc geo supermerca 2 mikkeli barba camicie fornitura caffe uffici jhon richmond 567 test drive offroad 3 a quattro zampe calderara di reno norme edilizie get down the night whats up mid il soffio papilon hotel costa sol frase d amore dedica lettera tama rw105 rhythm watch lettore mp3 scott associazione no profit proliant ml370 televisore plasma hitachi offerte lavoro ancona vitel tsm100 king of c coolpix 885 xxx small sexy girls occhiali ars adagio in italiano staccionate hch 38 cubis 2 fuga in paradiso dainese giubbini inter milan missione senza nome allevamento bovini agile warrior 2 k8n e deluxe nimo codec pack v5 0 build 9 beta 1 ferrovie del gargano produzione gazebo gregor salto frigorifero a altezza 160 screensaver macintosh provveditorato di forli rtl 102 5 febur pericolosamente vicini crystalbrite pentium m flash mario ellis george qtek 1010 gps golf generation 2002 tatu com ramazzotti barbara previsioni lotto gratis mascia fabiani quadri riproduzioni ricardo arjona www ginecology it canzone di vasco rossi diesel uomo dopewars multivision viaccess every breath you take ub40 mouse laser logitech mx 1000 finanziamento nice bruges vacanze super campeones jekaterinoslav x files stagione deborah secco nua kazaa resurrection registratori da vhs a dvd sms internet basi scugnizzi kingdom hearts 2 blink 182 the urethra chronicles film tragico inganno taormina sicilia hot party winter 2004 novaja zemlja dragostea din tea gostanza da libbiano filippa lagerback ibm 2391 matshita dvd ram uj 811 requisiti medico del lavoro medici dentisti volleybal www pianetaterra it chempions league web cam on the word porno amatoriale pompini universita salesiana case in affitto incontro oslo hemo 15 im iv 1 fl 100 ml brescia gay bisex palmari software annunci donne gratis geom marco costantini stalloni negri transenne vertigine samsung sm214t video amatoriali coppie le mani della notte banca di milano cicciolina e il suo cavallo sacrifice by lisa gerard and peter burke uova di garofano trasmettitore radio canali fta bci 6 y indaco dgli occhi del cielo cesto masterizzatori lacie This code snippet shows how to retrieve the available comms ports on your computer. A CommPort is available if it is not being used by another application. Note the difference 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