Discovering available comm ports

From Rxtx

Revision as of 08:58, 4 July 2007 by IesIpw (Talk | contribs)
Jump to: navigation, search

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