• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unexpected leading characters in buffered reader

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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?



This is the robot listener:



This is the output:



--John
 
Saloon Keeper
Posts: 15486
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you constantly opening a new DataInputStream on btc?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Hagan wrote:...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 honestly don't know, but I wonder if it might be a byte order mark.

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.

Winston
 
John Hagan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic