Discovering available comm ports

From Rxtx

Revision as of 06:16, 20 July 2007 by IesIpw (Talk | contribs)
Jump to: navigation, search

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