• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unreadable string from port. Please help.

 
Agniva Sengupta
Greenhorn
Posts: 16
Java Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using RXTXcomm.jar to communicate and read data from a digital compass (OS5000 - US). The compass is connected to COM-2.


When the port COM 2 is read using Microsoft Hyperterminal, I get data in readable string format.

Example : $OHPR,130.3,-17.9,173.0,36.3,0.0000,201.85,185.69,-65.13,44.93,0.989,-0.305,0.11
9,-0.933,91.43,91.43,0.00,6300*29 (this is an acceptable format).

However, when I connect to the same port using Java (via RXTXcomm.jar) , I get all gibberish output.

Example : È­NŒHŽJNlʈ , Šˆ.­NŒHŽJNLʈÈL .... etc. (unacceptable)

What is happening? Is this a string format related issue? Please help.

++++++++++++++++++++++++++++++++++++++++++++++++

The piece of code which I use to read this data is :


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A possibility could be of the Charset used to define the String.

Try finding out the Charset used by HyperTerminal and use it to configure your String object.
 
Agniva Sengupta
Greenhorn
Posts: 16
Java Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Madhan Sundararajan Devaki wrote:A possibility could be of the Charset used to define the String.

Try finding out the Charset used by HyperTerminal and use it to configure your String object.


Hi Madhan, just resolved this issue by changing the Baud rate in serialPort.setSerialPortParams (...) to 19200.

Thanks anyways... much appreciated !
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags next time.


Available Doesn't Do What You Think It Does


1) You may have read less bytes than readBuffer.length. The exact number is stored in numBytes.
2) I think that the inner String has an encoding problem; the bytes may have a different encoding than the default.
3) Why do you create a String using the just created String?

I'd change this block like this:

I'll move this thread to our I/O forum, as I think that's a better place.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!