Shop OBEX P1 Docs P2 Docs Learn Events
Problem sending data over serial port — Parallax Forums

Problem sending data over serial port

AronAron Posts: 3
edited 2008-10-03 19:03 in General Discussion
I am having trouble outputting characters from my Javelin Stamp to my PC.··I set up a test where I'm using an infinite while loop and incrementing a counter.· I then convert the·counter variable from integer to a string using the·toString() method and·send it using the sendString() method of the Uart class.· At the top of the loop I use the CPU.delay(1000) command to wait 100ms for each iteration.· An example is below:

·while (true) {
··· CPU.delay(1000);
··· count++;
··· txUart.sendString(Integer.toString(count) + "/n/r");
}

My comm settings are 9600, 8, none, 1

Once the program runs, it outputs the numbers to my PC's terminal program.· The program proceeds along just fine until it has output 284 numbers, then it stops.· I've set the buffer of the terminal software to a large value.· When I press the board's reset button, characters start flowing again.· I've tried different baud rates to no avail.· Any ideas???

Thanks!

Comments

  • jmspaggijmspaggi Posts: 629
    edited 2008-10-03 17:37
    Hi Aron,

    txUart.sendString(Integer.toString(count) + "/n/r"); is creating a string at each iteration, so you will run out of memory shortly, maybe after 284 iterations.

    You will need to replace that by something like:

    txUart.sendString(Integer.toString(count));
    txUart.sendString("/n/r");
    
    



    Also, Integer.toString(count) must be replaced by the Format class I think. Take a look at Javelin classes on Yahoo Groups.

    Regards,

    JM
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-10-03 17:58
    Unfortunately, Integer.toString() also creates a new String on each pass.
    You must use StringBuffer.

    StringBuffer s = new StringBuffer(); //create an empty stringbuffer
    ·while (true) {
    ··· CPU.delay(1000);
    ··· s.clear();
    ··· s.append(count++);
    ··· txUart.sendString(s.toString());
    ··· txUart.sendString("/n/r");
    }

    That should do it.

    regards peter
  • AronAron Posts: 3
    edited 2008-10-03 19:03
    Appreciate the quick responses...Thanks!
Sign In or Register to comment.