Reading from serial port problem

Hello,

I've got an application that simply reads the data from the serial port. It goes something like this:

Windows: Send string "int"
Microcontroller: receives "int", and sends back an int in 2 char bytes.
Windows: Receives bytes, but they're wrong!

In hyperterminal, if I simulate what gets sent, I receive the correct bytes.
Ive tried all read timeouts set to 1000, and Ive tried it with MAXWORD and 0, 0.

I dont know what could be going wrong in my app.
Please advise.

Cheers,
Tom
Could you be interpretting the bytes sent back with the wrong endianness? Also, make sure you receive the bytes in an unsigned char.
Hey, I'll update like this:
To test, I am sending "int", and receiving a character array which describes the number. Ie:

Windows: send "int"
microcontroller: receive "int", clear receive buffer, calculate value (=900), send value as string "900"
Windows: receives "int900"

Why does it have "int" before 900???
Additionally, I am not reading 4 bytes with the read operation to get that output - i have to read 7 bytes.
Other wise the receiving end is a combination of "int" and "900", like for example "t9nt", "900t", "nt9i", etc.

Weird, no?

Cheers,
Tom
Why does it have "int" before 900???

I have no idea!
:D
Darn!

Anyone else have any clues?
Well looks like Im the loser here.
I have a line "#define ECHO" in my mcu. So when it received "int", it sent back "int" immediately, followed by "900".

I just put a nice little // in front of that line!!

Solved :)

Cheers
Topic archived. No new replies allowed.