How to use Serial port to read data?
807597Aug 17 2003 — edited Jan 16 2008Hi 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.