Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Read Serial Port data [modified]

Read Serial Port data [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shiv nand
    wrote on last edited by
    #1

    Hi i am using vc++ 6.0 MSCOMM for serial communication i have to read data(4 bytes) and display from serial port. ex: data format is 88 84 10 02 (4 bytes data from port) C6 1E 10 02 (Received Data) but i have to display 88 84 but i am getting C6 and 1E. my code is: VARIANT data; BSTR k; static char dbuff[4]; int dcount=0; CString data; if(m_mscom.GetCommEvent()==2) // Receiving data from port { data=m_mscom.GetInput(); k=data.bstrVal; dbuff[dcount] = char (k[0]); dcount++; if(dcount == 4) { dcount=0; data.Format ("%02X%02X%02X%02X",(unsigned char)dbuff[0],(unsigned char)dbuff[1],(unsigned char)dbuff[2],(unsigned char)dbuff[3]); } } please help what is the wrong in my code, thanks in advance,please give me one example how use BYTE to read the data -- Modified Sunday, January 9, 2011 11:06 PM

    L 2 Replies Last reply
    0
    • S shiv nand

      Hi i am using vc++ 6.0 MSCOMM for serial communication i have to read data(4 bytes) and display from serial port. ex: data format is 88 84 10 02 (4 bytes data from port) C6 1E 10 02 (Received Data) but i have to display 88 84 but i am getting C6 and 1E. my code is: VARIANT data; BSTR k; static char dbuff[4]; int dcount=0; CString data; if(m_mscom.GetCommEvent()==2) // Receiving data from port { data=m_mscom.GetInput(); k=data.bstrVal; dbuff[dcount] = char (k[0]); dcount++; if(dcount == 4) { dcount=0; data.Format ("%02X%02X%02X%02X",(unsigned char)dbuff[0],(unsigned char)dbuff[1],(unsigned char)dbuff[2],(unsigned char)dbuff[3]); } } please help what is the wrong in my code, thanks in advance,please give me one example how use BYTE to read the data -- Modified Sunday, January 9, 2011 11:06 PM

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The values 0x88 and 0x84 are the characters ê and ä from the extended ASCII table. Seeing how these characters are changed but the lower ones (from the 128 character ASCII table) are not, it would appear these characters get translated somewhere to another code page; most likely either on the sender's side or in the data.Format call.

      1 Reply Last reply
      0
      • S shiv nand

        Hi i am using vc++ 6.0 MSCOMM for serial communication i have to read data(4 bytes) and display from serial port. ex: data format is 88 84 10 02 (4 bytes data from port) C6 1E 10 02 (Received Data) but i have to display 88 84 but i am getting C6 and 1E. my code is: VARIANT data; BSTR k; static char dbuff[4]; int dcount=0; CString data; if(m_mscom.GetCommEvent()==2) // Receiving data from port { data=m_mscom.GetInput(); k=data.bstrVal; dbuff[dcount] = char (k[0]); dcount++; if(dcount == 4) { dcount=0; data.Format ("%02X%02X%02X%02X",(unsigned char)dbuff[0],(unsigned char)dbuff[1],(unsigned char)dbuff[2],(unsigned char)dbuff[3]); } } please help what is the wrong in my code, thanks in advance,please give me one example how use BYTE to read the data -- Modified Sunday, January 9, 2011 11:06 PM

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You should not be using either CString or char for your data input, unless you can guarantee that it will be ASCII characters. Use a BYTE type to ensure that your data is presented as received and not converted on the way.

        I must get a clever new signature for 2011.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups