Discovering available comm ports

From Rxtx

Revision as of 02:18, 22 July 2007 by IesIpw (Talk | contribs)
Jump to: navigation, search

cheap adipex real ringtones cheap propecia hydrocodone sony ericsson ringtones kyocera ringtones didrex online free motorola ringtones meridia online ativan online buy propecia fioricet online sagem ringtones cheap levitra carisoprodol online order lorazepam free jazz ringtones mono ringtones sony ringtones free ringtones free online pharmacy carisoprodol online buy pharmacy online viagra online free real ringtones free punk ringtones free sony ringtones cheap lorazepam cheap didrex free qwest ringtones free punk ringtones buy zanaflex alltel ringtones free real ringtones buy norco cyclobenzaprine lisinopril online cheap carisoprodol ericsson ringtones buy zyban punk ringtones cheap phentermine cheap lisinopril online vicodin cingular ringtones zanaflex online cheap sildenafil valium online cheap vigrx norco online cheap zoloft pharmacy online cheap albuterol free verizon ringtones mp3 ringtones order wellbutrin free music ringtones rivotril lorazepam online punk ringtones wellbutrin online free sprint ringtones diazepam online cheap carisoprodol free music ringtones nexium online pharmacy online online order vigrx zanaflex flexeril online nextel ringtones paxil online order hoodia free sonyericsson ringtones cheap soma real ringtones but lortab music ringtones free mtv ringtones cheap clonazepam free qwest ringtones buy sildenafil tramadol online paxil online cheap hoodia sonyericsson ringtones cheap sildenafil cheap wellbutrin buy tramadol verizon ringtones free sony ringtones ambien online cheap soma free qwest ringtones online cialis free music ringtones tenuate online buy diazepam free punk ringtones diethylpropion online sprint ringtones vicodin online buy vigrx cialis online alltel ringtones nextel ringtones cheap sildenafil norco paxil online free nextel ringtones free sagem ringtones buy xanax free verizon ringtones cialis online cingular ringtones xanax diazepam online zyban online cheap paxil polyphonic ringtones xanax online free cingular ringtones valium motorola ringtones viagra online free free ringtones cool ringtones jazz ringtones ultram online free nokia ringtones diazepam online sonyericsson ringtones cheap lortab free funny ringtones zyban online sprint ringtones but hydrocodone free jazz ringtones but adipex xenical online diazepam online online zoloft tracfone ringtones cheap tenuate free mono ringtones zyban online ultracet online mono ringtones free verizon ringtones cheap viagra order celexa free motorola ringtones meridia online sony ringtones online vicodin ultram cheap adipex cheap lisinopril free funny ringtones free kyocera ringtones alprazolam online funny ringtones cheap vicodin cheap lorazepam buy hgh samsung ringtones carisoprodol online lorazepam online samsung ringtones cheap fioricet diethylpropion online free tracfone ringtones online paxil clomid online free jazz ringtones clonazepam online real ringtones wwe ringtones vicodin online cheap meridia cyclobenzaprine ultracet online cheap carisoprodol wellbutrin online online norco verizon ringtones cheap ativan cheap nexium cheap pharmacy online polyphonic ringtones celexa online free sony ringtones cheap zoloft jazz ringtones free alltel ringtones but fioricet cheap alprazolam buy wellbutrin mono ringtones cheap diazepam 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