Tower and RCX communication issue

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

Moderator: roger

Tower and RCX communication issue

Postby deshan » Fri Apr 10, 2009 4:56 pm

I'm completely new to this forum, So Hi to all :D

I want to read byte data which comes from RCX by a java program run on PC. I am using LeJOS at PC and NQC at RCX.

My java program run on PC
Code: Select all
import josx.rcxcomm.*;
import java.io.*;

public class ReadData extends Thread
{

    private RCXPort port = null;
    private DataInputStream din = null;

   //-- getters and setters

    public RCXPort getPort()
    {
        return port;
    }

    public void setPort(RCXPort port)
    {
        this.port = port;
    }

    public DataInputStream getDin()
    {
        return din;
    }

    public void setDin(DataInputStream din)
    {
        this.din = din;
    }

    //-- thread override run method
    public void run()
    {
        while (true)
        {
            try
            {
                System.out.println("waiting....");
                //--- read byte data
                System.out.println("read:"+din.readByte());
                ReadData.sleep(30);
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
            }
        }
    }

    public static void main(String[] args)
    {
        ReadData data = new ReadData();

        try
        {
            data.setPort(new RCXPort());
            data.setDin(new DataInputStream(data.getPort().getInputStream()));
            data.start();
        }
        catch (Exception ioe)
        {
            ioe.printStackTrace();
        }
    }
}


NQC program run on RCX
Code: Select all
task main()
{
SetTxPower(TX_POWER_HI);
 while(1)
 {
  SendMessage(3);
 }
}


When I start the program RCX Display indicates that program runs continuously and green light on tower continuously lights indicating that it tries to read. But java program does not output any.

Please help me
deshan
New User
 
Posts: 3
Joined: Fri Apr 10, 2009 4:41 pm
Location: SriLanka

Postby lawrie » Fri Apr 10, 2009 9:06 pm

RCXPort implements its own protocol to send Java stream data to leJOS on the RCX and will not talk to NQC.

If I remember correctly (it is more than 5 years since I used the RCX), the NQC SendMessage function sends an F7 op code message. you might be able to read that by changing RCXPort to RCXF7Port. If that does not work, try the Tower class and the receive method to receive the F7 packet.
lawrie
leJOS Team Member
 
Posts: 677
Joined: Mon Feb 05, 2007 1:27 pm

Postby deshan » Sun Apr 12, 2009 7:51 am

the NQC SendMessage function sends an F7 op code message. you might be able to read that by changing RCXPort to RCXF7Port.


Thank You now it works. Here is the new code


Code: Select all
public static void main(String[] args) throws IOException
    {
        RCXF7Port port = new RCXF7Port();
        InputStream in = port.getInputStream();
        int b = in.read();
        System.out.println("Read: " + b);
    }


NQC
Code: Select all
task main()
{
SetTxPower(TX_POWER_HI);

  SendMessage(123);
}


I hope now I am correct. Thanx again.
deshan
New User
 
Posts: 3
Joined: Fri Apr 10, 2009 4:41 pm
Location: SriLanka


Return to RCX Software

Who is online

Users browsing this forum: No registered users and 0 guests

more stuff