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?
Printable View
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?
Looks like the data got byte got rearranged. Does this occur on any data?
Kuphryn
This does not appear to be a problem, but normal endian swapping.
See Q102025
Hope this helps,
- Nigel
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:
or reverst the order of the bytes in the command.Code:char Data[] = {0x0D, 0x0A};
WriteFile(hComm, Data, 2, &dwWritten, &osWrite);
Thank you all,
My program run on pentinum4 2.4
to NigelQ:
where can i find the "Q102025",sorry , i'm new here
Go to msdn.microsoft.com and search for that keyword.
Regards,
- Nigel