I am an amateur programmer programming for the Lego NXT robot using Lejos. I say this because some of the methods/classes I am using may be unique to Lejos. I have two programs interacting. The first is on a W7 PC. It runs from the command line in a console. It is called PC_BT_Connect. The second program (BTReceiveTest) is a blue tooth listener running on the robot, which also runs java. I begin by starting the listnener on the robot. Then I start the command line program which seeks out and connects successfully. I enter characters a line at a time and send them via the bluetooth connector. The robot receives them and prints the line to its screen. Then it turns the string around and sends it back to the PC where it is output to the console. This all works fine, but I am picking up a random first character that gets posted to the PC console on the return message. Can you help me find out where this is coming from?
I've never used Lego, but from a quick glance at the NXTComm docs (I assume I'm looking at the right one), it doesn't appear to require a DataInputStream; and since you're only sending text, I'm wondering why you chose it.
If it were me, I think I'd want to use a BufferedReader, possibly with a specific Charset like UTF-8. That way, you don't have to write your own readline() method, because BufferedReader already has one, and BOMs (if sent/received) would be handled internally.
However, as I say, I've never used Lego, so there may be other things going on that I don't understand.
Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here
Joined: Jan 04, 2013
Stephan, thanks for pointing out the fact that I had the streams defined in the wrong place. Winston, I had to go back and relearn input and output streams and stream readers. The leading character did not disappear until I eliminated all of the Data input/output streams. Thanks for helping me clean up my code. I post the updated code and output below for your review and comments.
the code from the W7 PC side:
the code for the NXT robot side:
This is the output on the windows console:
Thanks again. --John
subject: Unexpected leading characters in buffered reader