import java.util.Enumeration; import java.io.*; import com.dalsemi.onewire.OneWireAccessProvider; import com.dalsemi.onewire.container.OneWireContainer; import com.dalsemi.onewire.adapter.DSPortAdapter; import com.dalsemi.onewire.OneWireException; import com.dalsemi.system.BitPort; class Access { public static void main(String[] args) throws IOException, FileNotFoundException, InterruptedException { System.out.println("Reading File"); //For our loops int i; //To hold our file -- A list of valid keys //and what port to pulse when they are found String[] validKeys = new String[32]; // Read the valid keys from file RandomAccessFile keysFile = new RandomAccessFile("validKeys.dat", "r"); for (i = 0; i <= 31; i++) { validKeys[i] = keysFile.readLine(); } //In case someone's watching System.out.println("Valid Keys:"); for (i = 0; i <= 31; i++) { if (validKeys[i] != null) { System.out.println(validKeys[i]); } } //Here we go! try { //Setup the OneWire DSPortAdapter adapter = OneWireAccessProvider.getDefaultAdapter(); //Only look for the boring ROM iButtons adapter.targetFamily(1); //Setup three bit ports BitPort bp1 = new BitPort(BitPort.Port5Bit0); BitPort bp2 = new BitPort(BitPort.Port5Bit1); BitPort bp3 = new BitPort(BitPort.Port5Bit4); BitPort bp4 = new BitPort(BitPort.Port5Bit5); bp1.clear(); bp2.clear(); bp3.clear(); bp4.clear(); //More status System.out.println("1-Wire net addresses:"); //Sit and wait for an iButton to show up for (;;) { Enumeration e = adapter.getAllDeviceContainers(); while (e.hasMoreElements()){ String currentAddress = ((OneWireContainer)e.nextElement()).getAddressAsString(); System.out.println(currentAddress); // For each iButton see if it matches a valid key for (i = 0; i <= 3; i++) { if (validKeys[i] != null) { if (currentAddress.equals(validKeys[i].substring(0, 16))) { System.out.println("Pulsing Port5Bit" + validKeys[i].charAt(17)); //System.out.println("Actual Port is next"); if (validKeys[i].charAt(17) == '1') { bp1.set(); } if (validKeys[i].charAt(17) == '2') { bp2.set(); } if (validKeys[i].charAt(17) == '3') { bp3.set(); } if (validKeys[i].charAt(17) == '4') { bp4.set(); } Thread.sleep(50); bp1.clear(); bp2.clear(); bp3.clear(); bp4.clear(); //Sleep a bit Thread.sleep(7*500); } } } } } } catch (OneWireException owe) { owe.printStackTrace(); } } }