lejos.remote.ev3.RemoteRequestUARTPort Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lejos-ev3-api Show documentation
Show all versions of lejos-ev3-api Show documentation
leJOS (pronounced like the Spanish word "lejos" for "far") is a tiny Java Virtual Machine. In 2013 it was ported to the LEGO EV3 brick.
The newest version!
package lejos.remote.ev3;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import lejos.hardware.port.UARTPort;
public class RemoteRequestUARTPort extends RemoteRequestIOPort implements UARTPort {
private ObjectInputStream is;
private ObjectOutputStream os;
private int portNum;
public RemoteRequestUARTPort(ObjectInputStream is, ObjectOutputStream os) {
this.is = is;
this.os = os;
}
@Override
public boolean open(int typ, int portNum,
RemoteRequestPort remoteRequestPort) {
boolean res = super.open(typ,portNum,remoteRequestPort);
this.portNum = portNum;
EV3Request req = new EV3Request();
req.request = EV3Request.Request.OPEN_UART_PORT;;
req.intValue2 = typ;
sendRequest(req, true);
return res;
}
@Override
public void close() {
EV3Request req = new EV3Request();
req.request = EV3Request.Request.CLOSE_SENSOR_PORT;
sendRequest(req, false);
}
@Override
public byte getByte() {
EV3Request req = new EV3Request();
req.request = EV3Request.Request.UART_GET_BYTE;
return (byte) sendRequest(req, true).reply;
}
@Override
public void getBytes(byte[] vals, int offset, int len) {
EV3Request req = new EV3Request();
req.request = EV3Request.Request.UART_GET_BYTES;
req.intValue2 = len;
EV3Reply reply = sendRequest(req,true);
for(int i=0;i