public static int [ ] getBusIds ( ) throws IOException { Set < Integer > set = null ; for ( Path device : Files . newDirectoryStream ( Paths . get ( "/sys/bus/i2c/devices" ) , "*" ) ) { String [ ] tokens = device . toString ( ) . split ( "-" ) ; if ( tokens . length == 2 ) { if ( set == null ) { set = new HashSet < Integer > ( ) ; } set . add ( Integer . valueOf ( tokens [ 1 ] ) ) ; } } int [ ] result = null ; if ( set != null ) { int counter = 0 ; result = new int [ set . size ( ) ] ; for ( Integer value : set ) { result [ counter ] = value . intValue ( ) ; counter = counter + 1 ; } } return result ; }
Fetch all available I2C bus numbers from sysfs . Returns null if nothing was found .