static public Enumeration < CommPortIdentifier > getPortIdentifiers ( ) { LOGGER . fine ( "static CommPortIdentifier:getPortIdentifiers()" ) ; //Do not allow anybody get any ports while we are re-initializing //because the CommPortIndex points to invalid instances during that time synchronized ( Sync ) { //Remember old ports in order to restore them for ownership events later HashMap oldPorts = new HashMap ( ) ; CommPortIdentifier p = CommPortIndex ; while ( p != null ) { oldPorts . put ( p . portName , p ) ; p = p . next ; } CommPortIndex = null ; try { //Initialize RXTX: This leads to detecting all ports //and writing them into our CommPortIndex through our method //{@link #addPortName(java.lang.String, int, gnu.io.CommDriver)} //This works while lock on Sync is held CommDriver RXTXDriver = ( CommDriver ) Class . forName ( "gnu.io.RXTXCommDriver" ) . newInstance ( ) ; RXTXDriver . initialize ( ) ; //Restore old CommPortIdentifier objects where possible, //in order to support proper ownership event handling. //Clients might still have references to old identifiers! CommPortIdentifier curPort = CommPortIndex ; CommPortIdentifier prevPort = null ; while ( curPort != null ) { CommPortIdentifier matchingOldPort = ( CommPortIdentifier ) oldPorts . get ( curPort . portName ) ; if ( matchingOldPort != null && matchingOldPort . portType == curPort . portType ) { //replace new port by old one matchingOldPort . RXTXDriver = curPort . RXTXDriver ; matchingOldPort . next = curPort . next ; if ( prevPort == null ) { CommPortIndex = matchingOldPort ; } else { prevPort . next = matchingOldPort ; } prevPort = matchingOldPort ; } else { prevPort = curPort ; } curPort = curPort . next ; } } catch ( Throwable e ) { System . err . println ( e + " thrown while loading " + "gnu.io.RXTXCommDriver" ) ; System . err . flush ( ) ; } } return new CommPortEnumerator ( ) ; }
Returns an enumeration of port identifiers which represent the communication ports currently available on the system .