All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lejos.remote.ev3.RemoteRequestI2CPort Maven / Gradle / Ivy

Go to download

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.I2CPort;

public class RemoteRequestI2CPort extends RemoteRequestIOPort implements I2CPort {
	private ObjectInputStream is;
	private ObjectOutputStream os;
	private int portNum;
	
	public RemoteRequestI2CPort(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_I2C_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 void i2cTransaction(int deviceAddress, byte[] writeBuf,
			int writeOffset, int writeLen, byte[] readBuf, int readOffset,
			int readLen) {
		EV3Request req = new EV3Request();
		req.request = EV3Request.Request.I2C_TRANSACTION;
		req.intValue2 = deviceAddress;
		req.intValue3 = writeOffset;
		req.intValue4 = writeLen;
		req.intValue5 = readLen;
		req.byteData = writeBuf;
		EV3Reply reply = sendRequest(req, true);
		for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy