[SOLVED]HELP! Control NXJ from PC through IR Tower?

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

[SOLVED]HELP! Control NXJ from PC through IR Tower?

Postby DHS1 » Tue Oct 25, 2011 4:48 pm

Hello all,

I know there is a rcxcomm.jar package but I need help on how to use it. I need to be able to write to the RCX (I'm using RCX, NXJ would be the same) while it is listening for input, and once it gets the input (a 1, 2, or a 3), it will know how to process it (ie: move forward, move backward, write "Hello World" to the LCD) with "if" commands.

From the sample code given in the lejos download, I am given that this is how to write:

Code: Select all
import josx.rcxcomm.*;
import java.io.*;

public class Write {

   public static void main(String [] args) {

      try {
         RCXPort port = new RCXPort();

         OutputStream os = port.getOutputStream();

         os.write(123);
         os.flush();
      }
      catch (IOException ioe) {
      }
   }
}


And this is how to read:

Code: Select all
import java.io.*;
import josx.rcxcomm.*;
import josx.platform.rcx.*;

/** Very simple example of using RCXInputStream on the RCX
 * Communicates with Write.java on the PC
 * For 2-way communication use RCXPort
 */
public class Read {
  public static void main (String [] args) throws IOException {
    RCXInputStream in = new RCXInputStream();
    LCD.showNumber(in.read());
    try {
      Thread.sleep(1000);
    }
    catch (InterruptedException e) {}
  }
}


So I compile and run/download the Read program onto the RCX robot (I'm using RCX but I'm sure the method is the same for NXJ), and press "Run" on the robot so it should be reading (waiting for input), then I try downloading the Write program, while the Read is running on the robot, but the RCX unit is unresponsive, probably because it's running another program. How do I send things to the RCX device on command?

Please any help would be GREATLY!!! appreciated.
Last edited by DHS1 on Wed Oct 26, 2011 6:43 am, edited 1 time in total.
DHS1
New User
 
Posts: 5
Joined: Tue Oct 25, 2011 2:02 pm

Re: HELP! Control NXJ from PC through IR Tower?

Postby DHS1 » Tue Oct 25, 2011 6:45 pm

EDIT:

I found C:\lejos\samples\comms\remotectl\RemoteControlTest.java. I compiled it and put it on my RCX unit, ran it, and it says "Ready". How can I now control it via my IR Tower? I think I might be on the right track here with communicating with the robot.
DHS1
New User
 
Posts: 5
Joined: Tue Oct 25, 2011 2:02 pm

Re: HELP! Control NXJ from PC through IR Tower?

Postby DHS1 » Wed Oct 26, 2011 6:43 am

I figured it out.

For future people who find this thread, I hope this info is helpful:

I had to make this a leJOS RCX Project:
Code: Select all
import java.io.*;
import josx.rcxcomm.*;
import josx.platform.rcx.*;

/** Very simple example of using RCXInputStream on the RCX
 * Communicates with Write.java on the PC
 * For 2-way communication use RCXPort
 */
public class Read {
   public static void main (String [] args) throws IOException {
      RCXInputStream in = new RCXInputStream();
      while(true){
         if(in.read() == 1){
            Motor.A.forward();
            Motor.C.forward();
         }
      }
   }
}


And I had to make this a leJOS Client Project
Code: Select all
import josx.rcxcomm.*;
import java.io.*;
import java.util.Scanner;

/** For use on the PC for sending a byte to the RCX Read.java example
 * Compile using javac with pcrcxcomm.jar on the CLASSPATH
 */
public class Write {
   public static void main(String [] args) throws IOException {
      try {
         RCXPort port = new RCXPort("usb");
         OutputStream out = port.getOutputStream();
         Scanner sc = new Scanner(System.in);

         while(true){
            System.out.print("Enter a number: ");
            int i = Integer.parseInt(sc.nextLine());
            System.out.println();
            out.write(i);
         }
      } catch(Exception exc) {
         exc.printStackTrace();
      }
   }
}


I put the Read program on the RCX, then pressed "Run" so it was listening, then I ran the Write application as a Java Application, put in 1, and my machine moved the moment I pressed enter. PERFECT!
DHS1
New User
 
Posts: 5
Joined: Tue Oct 25, 2011 2:02 pm


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 4 guests

more stuff