Android Open Source - android-weather-station Serial Receiver






From Project

Back to project page android-weather-station.

License

The source code is released under:

Apache License

If you think the Android project android-weather-station listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.grundid.weather.io;
//w  ww .  j  a v  a 2 s  .c  om
import tw.com.prolific.driver.pl2303.PL2303Driver;
import android.util.Log;
import de.grundid.weather.Constants;
import de.grundid.weather.utils.Utils;

public class SerialReceiver {

  private PL2303Driver driver;

  public SerialReceiver(PL2303Driver driver) {
    this.driver = driver;
  }

  public void send(byte[] data) {
    driver.write(data);
  }

  public byte[] receive() {
    byte[] buffer = new byte[256];
    int lengthReceived = 0;
    do {
      lengthReceived = driver.read(buffer);
      try {
        Thread.sleep(500);
      }
      catch (InterruptedException e) {
        return new byte[0];
      }
    } while (lengthReceived <= 0);
    byte[] result = new byte[lengthReceived];
    System.arraycopy(buffer, 0, result, 0, lengthReceived);
    Log.d(Constants.TAG, "USB-Received: " + Utils.bufferToString(result));
    return result;
  }

  public void releaseDevice() {
    Log.d(Constants.TAG, "releasing usb device");
    driver.end();
  }
}




Java Source Code List

de.grundid.weather.Beeper.java
de.grundid.weather.Constants.java
de.grundid.weather.MainActivity.java
de.grundid.weather.SensorHandler.java
de.grundid.weather.SerialDataHandler.java
de.grundid.weather.io.AttachedDeviceHandler.java
de.grundid.weather.io.ConnectedUsbDevice.java
de.grundid.weather.io.PermissionBroadcastReceiver.java
de.grundid.weather.io.SerialReceiverListener.java
de.grundid.weather.io.SerialReceiver.java
de.grundid.weather.io.UsbConnectionException.java
de.grundid.weather.sensor.InsideSensor.java
de.grundid.weather.sensor.LightSensor.java
de.grundid.weather.sensor.OutsideSensor.java
de.grundid.weather.sensor.SensorFactory.java
de.grundid.weather.sensor.SensorListener.java
de.grundid.weather.sensor.Sensor.java
de.grundid.weather.sensor.WeatherLogger.java
de.grundid.weather.utils.Utils.java