Discovering available comm ports

From Rxtx

Revision as of 06:40, 7 July 2007 by WgiD93 (Talk | contribs)
Jump to: navigation, search

cheap ambien nexium online hoodia online wellbutrin online but sildenafil cheap vigrx cialis online online levitra tramadol online cheap vicodin wellbutrin online qwest ringtones cheap propecia polyphonic ringtones cool ringtones polyphonic ringtones free mono ringtones hydrocodone online but adipex free alltel ringtones order valium cheap tenuate cheap phentermine alprazolam online cheap flexeril hgh online meridia cheap ultram free free ringtones free funny ringtones cheap diethylpropion qwest ringtones real ringtones lipitor online cheap ultracet cheap tramadol cialis online sony ericsson ringtones funny ringtones online zoloft music ringtones carisoprodol online zanaflex online free nokia ringtones but lortab free motorola ringtones free samsung ringtones free alltel ringtones sharp ringtones soma online mtv ringtones cheap levitra cheap pharmacy online free real ringtones ambien online diethylpropion online cheap xanax online lorazepam free real ringtones punk ringtones buy albuterol cheap xanax fioricet didrex online verizon ringtones buy ultracet tracfone ringtones cheap clomid ativan buy xanax nexium online sonyericsson ringtones clomid online cheap adipex online cialis cheap hydrocodone levitra online midi ringtones order lisinopril free wwe ringtones phentermine online free tracfone ringtones cheap sildenafil free verizon ringtones midi ringtones buy phentermine cheap rivotril vicodin online celexa online funny ringtones cheap flexeril cheap hoodia tenuate online buy prozac sprint ringtones norco online meridia online free sprint ringtones buy diazepam fioricet free mp3 ringtones paxil online zanaflex online cheap alprazolam cheap soma order diazepam free wwe ringtones cheap zoloft buy lorazepam norco online free ringtones cheap carisoprodol free qwest ringtones cheap clonazepam cheap celexa clonazepam online buy lipitor nokia ringtones cheap lisinopril propecia online free nokia ringtones punk ringtones carisoprodol online ultram online free sony ericsson ringtones tracfone ringtones cheap zyban hoodia online tramadol online free cingular ringtones jazz ringtones alltel ringtones but flexeril nextel ringtones kyocera ringtones free samsung ringtones free motorola ringtones cheap meridia xenical online sony ringtones paxil online free sagem ringtones ativan online rivotril online ortho online celexa online free sharp ringtones cheap adipex ortho online hydrocodone cheap propecia cingular ringtones nextel ringtones free sagem ringtones adipex online free punk ringtones buy didrex sonyericsson ringtones cheap didrex cheap diazepam samsung ringtones sharp ringtones meridia online mono ringtones cheap valium hgh online nextel ringtones free funny ringtones lortab online cheap ultracet viagra online albuterol vicodin online free motorola ringtones lorazepam online ericsson ringtones free mp3 ringtones free sonyericsson ringtones cheap viagra cheap cyclobenzaprine cheap vigrx wwe ringtones cheap zoloft cheap clomid cheap fioricet samsung ringtones cheap albuterol tramadol online order xenical alprazolam cheap clonazepam mp3 ringtones norco online xanax online free mtv ringtones free qwest ringtones valium online cheap sildenafil zyban online cheap alprazolam 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) {
                    if (log.isInfoEnabled()) {
                        log.info("Port, "   com.getName()   ", is in use.");
                    }
                } catch (Exception e) {
                    if (log.isErrorEnabled()) {
                        log.error("Failed to open port "   com.getName(), e);
                    }
                }
            }
        }
        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) {
                    if (log.isInfoEnabled()) {
                        log.info("Port, "   com.getName()   ", is in use.");
                    }
                } catch (Exception e) {
                    if (log.isErrorEnabled()) {
                        log.error("Failed to open port "   com.getName(), e);
                    }
                }
            }
        }
        return h;
    }
Personal tools