Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use Serial port to read data?

807597Aug 17 2003 — edited Jan 16 2008
Hi everyone. I'm current doing my project using a microcontroller and java communication API. I made some bytes of data from the microcontroller ($0~$FF, ie. 0~255) and these data are then sent to the PC (windows) via the serial port (COM2).

My problem is that the java program does not read the values properly. I current using the SimpleRead.java provided by the Java Communication API 2.0. When I sent data value 25 (continuously) to the serial port, the java program actually reads as "28, 254, 0, 28, 254, 0 ...". When I change the values sent to the serial port, the java program always shows some incorrect numbers.

The number format sent from the microcontroller is as follows: a leading zero (the starting bit), 8 bits of data of integer value(sending the least significant digit first),and an ending one (the stop bit). No parity bit is used. The Baud rate in both the microcontroller and my java program is set to 9600.

Could someone please tell me how to solve this problem.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 13 2008
Added on Aug 17 2003
19 comments
1,249 views