View Single Post
  #5   Spotlight this post!  
Unread 11-03-2015, 09:16
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 327
fovea1959 will become famous soon enough
Re: Programmatically Determine Which Rio Code is on

We've done this with a 'name' field in a WPILIB Preferences object, we've done it with a jumper on the bot (like Alan), and we have worked off the network MAC address.

In our experience, Alan's is the best/easiest way if you have the spare DIO (you don't need a programmer around if you move roboRIO XXXX from the test chassis to the competition chassis). We made sure the competition robot required NO jumpers, we used jumpers to disable stuff on the test/practice robots. Murphy says you will lose the jumper if you need it at competition.

If you want to go from the MAC address (yes, there is a typo in one of the MACs):

Code:
public boolean havePneumatics = false;

    public void checkForPneumatics() {
        havePneumatics = false;
        try {
            for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
                NetworkInterface network = e.nextElement();
                System.out.println("network " + network);
                byte[] mac = network.getHardwareAddress();
                if (mac != null) {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < mac.length; i++) {
                        sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
                    }
    // Mule Board (wegscheid) MAC: "00-80-2F-17-EA-A4"
                    // MAC: "00-80-2F-17-EA-A5"
                    //Test bot (3630KOP) MAC: "00-80-2F-17-93-IE"
                    //Prototype (3620 Spare) MAC: "00-80-2F-17-EB-09"
                    // MAC: "00-80-2F-17-EB-08"
                    String macString = sb.toString();
                    System.out.println(" looking at MAC:" + macString);
                    if (macString.equals("00-80-2F-17-EB-09") || macString.equals("00-80-2F-17-EA-A4")) {
                        havePneumatics = true;
                        break;
                    }
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
        System.out.println ("We have " + (havePneumatics ? "" : "no ") + "pneumatics");
                
    }
Reply With Quote