To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.javaOpen lugnet.robotics.rcx.java in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / Java / 218
217  |  219
Subject: 
RCX <-> PC communication, more details
Newsgroups: 
lugnet.robotics.rcx.java
Date: 
Mon, 16 Sep 2002 12:34:07 GMT
Viewed: 
4563 times
  
Thanks for the three of you (Francois, Roger and Lawrence) who have answered
to my questions. I was asked to state some more details, which I'll do here:

I am working under linux (SuSE 7.3) and since the linux version of java does
not yet support USB very well I work with a serial tower (altough I would
have an USB tower available as well).

I was asked to post my test programs, they follow below.

I also post the output of those programs, for the PC side only, since on the
RCX I cannot have as verbose output as the PC. But have a look at the test
programs to see how I implemented documentation on the RCX. The results
actually confirm that LLC is about twice as fast as F7, but in my case not
reliable, i.e. packets do not get through to the RCX with the correct value.

I also found out, that the reason, why LNP does not get all packets through
to the RCX, is possibly swamping. I'll test that hypothesis and will try to
slow the PC down when sending. I'll inform you here about my results as soon
as I am done. At least, with LNP, I did not get "wrong" integers transmitted
as it was the case with LLC.

Kaspar

--------------
Test programs:
--------------

/*
* A simple test program to check the speed of transmission between PC and
* RCX. This is the PC part (chose mode & port at startup).
*/

import josx.rcxcomm.*;
import java.io.*;

public class TestSpeed_PC {

private static final short SEND =  0;
private static final short RECV =  1;
private static final short UDEF = -1;

private RCXAbstractPort port;
private DataOutputStream out;
private DataInputStream in;

public TestSpeed_PC(RCXAbstractPort port) {
  this.port = port;
  port.reset();
  out = new DataOutputStream(port.getOutputStream());
  in = new DataInputStream(port.getInputStream());
}

public void test(int mode) {
  long start_t=0, end_t;
  float total_t;

  try {
   if (mode == SEND) {
    // send extra trigger data ahead, then start timing
    out.writeInt(0);
    out.flush();
    start_t = System.currentTimeMillis();

    // send 20 odd ints
    for (int i=0; i<20; i++) {
     out.writeInt(i*2+1);
     out.flush();
     System.out.print(" "+(i*2+1));
    }
   }
   else if (mode == RECV) {
    // wait for trigger data, then start timing
    in.readInt();
    start_t = System.currentTimeMillis();

    for (int i=0; i<20; i++) {
     System.out.print(" "+in.readInt());
    }
   }
   else {
    System.out.println("Unknown mode.");
    System.exit(1);
   }
  }
  catch (IOException e) {
   System.out.println("Got an I/O exception: "+e.getMessage());
   System.exit(1);
  }

  end_t = System.currentTimeMillis();
  total_t = (end_t-start_t)/(float)1000;
  System.out.print("\n---\n"+((mode == SEND)?"Sent":"Received"));
  System.out.println(" 20 integers in "+total_t+" secs (="
   +total_t/20+" secs/int)");
}

public static void main(String[] args) throws Exception {
  if (args.length < 2) usage();
  else {
   RCXAbstractPort port = null;
   int mode = UDEF;

   String p = args[0].toLowerCase();
   String m = args[1].toLowerCase();

   if (p.equals("llc")) port = new RCXPort();
   else if (p.equals("lnp")) port = new RCXLNPPort();
   else if (p.equals("f7")) port = new RCXF7Port();

   if (m.equals("send")) mode = SEND;
   else if (m.equals("recv")) mode = RECV;

   if (port == null || mode == UDEF) usage();
   else {
    System.out.println("> Running PC with "+m+"/"+p+".");
    (new TestSpeed_PC(port)).test(mode);
   }
  }
}

public static void usage() {
  System.out.println("java TestSpeed_PC <port-type> <mode>, where"
   +"port-type = {llc, f7, lnp} and mode = {send, recv}");
}
}

-----------

/*
* A simple test program to check the speed of transmission between PC and
* RCX. This is the RCX part; chose mode and port with PRGM and VIEW button
* respectively, start program with RUN button, end with ON/OFF.
* After running a successful Test with port or mode x, the RCX should be
* switched off and on again, to free memory for the next run (otherwise will
* crash because of limited mem).
*/

import josx.rcxcomm.*;
import josx.platform.rcx.*;
import java.io.*;

public class TestSpeed_RCX implements ButtonListener {

public static final short SEND = 0;
public static final short RECV = 1;
public static final short RUN  = 2;
public static final short UDEF = 3;

public static final short LLC = 0;
public static final short F7  = 1;
public static final short LNP = 2;

private char[][] PORT_CHARS = {{'L','L','C'}, {'F','7'}, {'L','N','P'}};
private char[][] MODE_CHARS = {{'S','N','D'}, {'R','C','V'}, {'R','U','N'}};

private short currMode_;
private short currPort_;

/* Initialization, default is F7-PORT and RECV. */
public TestSpeed_RCX() {
  // set default values
  currMode_ = RECV;
  currPort_ = F7;

  // set listener
  Button.RUN.addButtonListener(this);
  Button.VIEW.addButtonListener(this);
  Button.PRGM.addButtonListener(this);

  // signal defaults on lcd
  TextLCD.print(PORT_CHARS[currPort_]);
  try { Thread.sleep(1000); } catch (InterruptedException interrupted) {}
  TextLCD.print(MODE_CHARS[currMode_]);
  Sound.twoBeeps();
}

/* Executed if RUN is pressed. */
public void test() {
  int start_t=0, end_t=0, total_t=0, val=0;
  short i;
  RCXAbstractPort port = null;
  DataInputStream in = null;
  DataOutputStream out = null;

  // get the selected port and appropriate data stream
  try {
   if (currPort_ == F7) port = new RCXF7Port();
   else if (currPort_ == LLC) port = new RCXPort();
   else if (currPort_ == LNP) port = new RCXLNPPort();

   if (currMode_ == RECV) in = new DataInputStream(port.getInputStream());
   else
   if (currMode_ == SEND) out = new DataOutputStream(port.getOutputStream());
  }
  catch (IOException ex) {
   Sound.buzz();
   TextLCD.print(new char[] {'i','o'});
   System.exit(1);
  }

  try {
   if (currMode_ == SEND) {
    // send extra trigger data ahead, then start timing
    out.writeInt(0);
    out.flush();
    start_t = (int) System.currentTimeMillis();

    // send 20 even ints
    for (i=0; i<20; i++) {
     val=i*2;
     out.writeInt(val);
     out.flush();
     LCD.showNumber(val*100+i);
     Sound.beep();
    }
   }
   else if (currMode_ == RECV) {
    // wait for trigger data, then start timing
    in.readInt();
    start_t = (int) System.currentTimeMillis();

    for (i=0; i<20; i++) {
     val = in.readInt();
     LCD.showNumber(val*100+i);
     Sound.beep();
    }
   }
  }
  catch (IOException e) {
   Sound.buzz();
  }

  // get elapsed time
  end_t = (int) System.currentTimeMillis();
  total_t = (end_t-start_t)/1000;

  // show total seconds (floored) on lcd when done
  LCD.showNumber(total_t);
  Sound.twoBeeps();
}

/* Changes mode (PRGM) and port (VIEW) and starts test (RUN). */
public void buttonPressed(Button b) {
  if (b == Button.VIEW) {
   currPort_ = (short) (++currPort_ % 3);
   TextLCD.print(PORT_CHARS[currPort_]);
  }
  else if (b == Button.PRGM) {
   currMode_ = (short) (++currMode_ % 2);
   TextLCD.print(MODE_CHARS[currMode_]);
  }
  else if (b == Button.RUN) {
   TextLCD.print(MODE_CHARS[RUN]);
   test();
  }
}

/* Not used. */
public void buttonReleased(Button b) {} // not needed

/* Start wrapper app (button listener). */
public static void main(String[] args) {
  new TestSpeed_RCX();
  // keep alive
  while (true) {
   try { Thread.sleep(5000); } catch (InterruptedException i) {}
  }
}

}


----------------------
Test results, PC side:
----------------------

Running PC with recv/lnp.
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38
---
Received 20 integers in 2.361 secs (=0.11805 secs/int)

Running PC with recv/llc.
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38
---
Received 20 integers in 5.701 secs (=0.28505 secs/int)

Running PC with recv/f7.
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38
---
Received 20 integers in 9.761 secs (=0.48804998 secs/int)

Running PC with send/f7.
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
---
Sent 20 integers in 49.86 secs (=2.493 secs/int)

Running PC with send/lnp.
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
---
Sent 20 integers in 0.0040 secs (=2.0000001E-4 secs/int)

Running PC with send/llc.
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39
---
Sent 20 integers in 23.27 secs (=1.1635001 secs/int)



Message has 1 Reply:
  Re: RCX <-> PC communication, more details
 
(...) Great, I just had too much time at hand, so I could already test the hypothesis above. Great, to be able to post a followup to my own message within half an hour... Ok, here it comes: The PC __IS__ swamping the RCX when using the LNP protocol. (...) (22 years ago, 16-Sep-02, to lugnet.robotics.rcx.java)

3 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR