Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Remote access from a NXT

Lawrie Griffiths

Remote access from a NXT


It is possible to run a responder on the EV3 which waits for a connection from a NXT or any other device using Bluetooth serial comms.

For example if the NXT is running the NXTConnect sample over Bluetooth with a raw connection:

NXTCommConnector connector = Bluetooth.getNXTCommConnector();

System.out.println("Waiting for connection ...");
NXTConnection con = connector.waitForConnection(0, NXTConnection.RAW);
System.out.println("Connected");

DataInputStream dis = con.openDataInputStream();
DataOutputStream dos = con.openDataOutputStream();

while(true) {
    int n;
    try {
        n = dis.readInt();
    } catch (EOFException e) {
        break;
    }
    System.out.println("Read " + n);
    dos.writeInt(-n);
    dos.flush();
}

Delay.msDelay(1000);

dis.close();
dos.close();
con.close();

This responder should also work with Android clients, or with a PC client running the NXT pccomms project.

It is also possible for the EV3 to emulate a NXT by running an LCP responder, although the LCP implementation is not yet very functional:

    static class Responder extends LCPResponder
    {
        Responder(NXTCommConnector con)
        {
            super(con);
        }

        protected void disconnect()
        {
            super.disconnect();
            super.shutdown();
        }
    }

    public static void main(String[] args) throws Exception
    {
        try {
            Responder resp = new Responder(Bluetooth.getNXTCommConnector());
            resp.start();
            resp.join();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Related

EV3 Wiki: Home