Problem sending data over serial port
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!
·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
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:
Also, Integer.toString(count) must be replaced by the Format class I think. Take a look at Javelin classes on Yahoo Groups.
Regards,
JM
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