Beispiel #1
0
  public static void main(String[] args) throws InterruptedException {

    PropertyConfigurator.configure(
        testArduinoBridge.class.getResourceAsStream("/config/log4j.properties"));
    ultroTest test = new ultroTest();
    SensorUltrasonic sensorUltrasonic = new SensorUltrasonic();
    String serialName = SystemProperty.getProperty("ArduinoBridge.serialComName");
    int serialRate = Integer.parseInt(SystemProperty.getProperty("ArduinoBridge.serialComRate"));
    ArduinoBridge arduinoBridge = new ArduinoBridgeImpl(serialName, serialRate);
    arduinoBridge.registerMessageListener(SensorEvent.SENSOR_ULTRASONIC_TYPE, sensorUltrasonic);
    sensorUltrasonic.addSenserListener(test);
    while (true) {}
  }
/** @author jack */
public class testArduinoBridge {

  public static Log logger = LogFactory.getLog(testArduinoBridge.class);
  String serialName = SystemProperty.getProperty("ArduinoBridge.serialComName");
  int serialRate = Integer.parseInt(SystemProperty.getProperty("ArduinoBridge.serialComRate"));
  ArduinoBridge arduinoBridge = new ArduinoBridgeImpl(serialName, serialRate);

  public testArduinoBridge() {
    arduinoBridge.registerMessageListener(
        ArduinoBridge.HALL_MSG_TYPE,
        new SensorListener() {

          @Override
          public void SensorEventProcess(SensorEvent e) {
            logger.info("Receive msg from serial : type hall");
          }
        });
  }

  /** @param args the command line arguments */
  public static void main(String[] args) throws IOException {
    PropertyConfigurator.configure(
        testArduinoBridge.class.getResourceAsStream("/config/log4j.properties"));
    testArduinoBridge tArduinoBridge = new testArduinoBridge();

    for (int i = 0; i < 200; i++) {
      byte[] data = new byte[3];
      data[0] = 'R';
      data[1] = (byte) i;
      data[2] = '\n';
      System.err.println(Byte.toString((byte) i));
      ArduinoBridgeImpl.sendMessagge(data);
      Utils.delay(50);
    }
  }
}