|
-
May 13th, 2004, 09:29 AM
#1
Serial Communications problems
i use the following code to send a word to com1,
WORD wCommand=0x0D0A;
WriteFile(hComm,&wCommand,sizeof(WORD), &dwWritten, &osWrite);
at the com2,i receive the data,but the order changes to 0A0D,why?
How should i do to solve this problem?
-
May 13th, 2004, 09:47 AM
#2
Looks like the data got byte got rearranged. Does this occur on any data?
Kuphryn
-
May 13th, 2004, 09:48 AM
#3
This does not appear to be a problem, but normal endian swapping.
See Q102025
Hope this helps,
- Nigel
-
May 13th, 2004, 10:17 AM
#4
What type of processor is on the sending side?
What type of process is on the receiving side?
When you say you received 0A0D - which byte was received first?
The data you sent was 0x0D0A. This sends the 0x0A first (low
byte first), followed by the 0x0D (high byte second).
You may be confused by the way that you are displaying the data
received.
If you want to send the 0x0D first, then use a char array:
Code:
char Data[] = {0x0D, 0x0A};
WriteFile(hComm, Data, 2, &dwWritten, &osWrite);
or reverst the order of the bytes in the command.
-
May 13th, 2004, 06:01 PM
#5
Thank you all,
My program run on pentinum4 2.4
to NigelQ:
where can i find the "Q102025",sorry , i'm new here
-
May 17th, 2004, 10:47 AM
#6
Go to msdn.microsoft.com and search for that keyword.
Regards,
- Nigel
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|