/***** * TestRCXComm * * Try to get two bricks talking to each other. * * Push the PRGM button to send : * sequence = preparing * buzz = IO exception * 2 beeps = sent * * Push the VIEW button to recieve : * sequence = preparing * buzz = IO exception * 4 beeps = success * 1 beep = failure * * Push the RUN button to see if its awake: * 3 beeps = yup * * Suggested procedure : * 1) Download this program into 2 different bricks. * 2) Make sure both are "awake" with the RUN button. * 3) Push VIEW on one; it should "block" and just listen ... * 4) Push PRGRM on other; hopefull it sends one byte of data * ... and the one listening should get the data and beep accordingly. * * To test compilation on cs: * $ . unix/environment * $ lejosc TestRCXComm.java * creates TestRCXComm.class * * Jim M * v 1.0 April 30 evening before class, compiled but not run on brick. * v 1.5 May 1 version on PC worked (!) though beeping was awkward. * v 2.0 May 1 after class, updated cs version * * $Id: TestRCXComm.java 13265 2007-05-02 13:26:13Z mahoney $ ************/ import java.io.*; import josx.rcxcomm.*; // infrared communication stuff import josx.platform.rcx.*; // includes Sound object public class TestRCXComm { public static RCXPort port; public static int message = 7; // what we're going to send and receive. // Inititialize the communications port. public static void initPort(){ try { port = new RCXPort(); } catch (IOException ioe){ Sound.buzz(); } } // Pause for a given number of seconds. public static void wait(double seconds){ try { Thread.sleep((long)(seconds*1000.0)); } catch (InterruptedException ie){ } } // If the button isn't being pressed, return false immediately. // If it is being pressed, wait for release, and then return true. public static boolean press_and_release(Button b){ boolean state = b.isPressed(); if (state){ while (b.isPressed()){ } } return state; } // Beep n times with a short delay between beeps. public static void nBeeps(int n){ double timeBetweenBeeps = 0.3; // seconds for (int i=0; i