CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2004
    Posts
    43

    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?

  2. #2
    Join Date
    Feb 2002
    Posts
    5,757
    Looks like the data got byte got rearranged. Does this occur on any data?

    Kuphryn

  3. #3
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    2,147
    This does not appear to be a problem, but normal endian swapping.

    See Q102025

    Hope this helps,

    - Nigel

  4. #4
    Join Date
    Aug 2001
    Location
    Texas
    Posts
    645
    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.

  5. #5
    Join Date
    Mar 2004
    Posts
    43
    Thank you all,
    My program run on pentinum4 2.4

    to NigelQ:
    where can i find the "Q102025",sorry , i'm new here

  6. #6
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    2,147
    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
  •  





Click Here to Expand Forum to Full Width

Featured