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. serial port

serial port

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
4 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.
  • M Offline
    M Offline
    macmac38
    wrote on last edited by
    #1

    Hello, i like to read in a data string from my serial port. The string has the format like: [123.233, -4.344, 45.678]. I want to readout this string and transfer the three values into float x,y,z variables for further processing. The code below is a part of my old code which works with only a "1" character input. What i have to change? char cReceivedChar[1]; cReceivedChar[0] = '\0'; DWORD dwBytesRead; if (port.Read(cReceivedChar, 1 , overlapped, &dwBytesRead)) // 1 is number of bytes read from port, how to make this variable? { CString nx = cReceivedChar[1]; SetDlgItemText(IDC_SHIFT_X,("%c", nx)); } Thanks, Mark

    J 1 Reply Last reply
    0
    • M macmac38

      Hello, i like to read in a data string from my serial port. The string has the format like: [123.233, -4.344, 45.678]. I want to readout this string and transfer the three values into float x,y,z variables for further processing. The code below is a part of my old code which works with only a "1" character input. What i have to change? char cReceivedChar[1]; cReceivedChar[0] = '\0'; DWORD dwBytesRead; if (port.Read(cReceivedChar, 1 , overlapped, &dwBytesRead)) // 1 is number of bytes read from port, how to make this variable? { CString nx = cReceivedChar[1]; SetDlgItemText(IDC_SHIFT_X,("%c", nx)); } Thanks, Mark

      J Offline
      J Offline
      jmkhael
      wrote on last edited by
      #2

      why not simply CString nx ; while (port.Read(cReceivedChar, 1 , overlapped, &dwBytesRead)) // 1 is number of bytes read from port, how to make this variable? { nx += cReceivedChar[1]; } AfxMessageBox(nx); Papa while (TRUE) Papa.WillLove ( Bebe ) ;

      M 1 Reply Last reply
      0
      • J jmkhael

        why not simply CString nx ; while (port.Read(cReceivedChar, 1 , overlapped, &dwBytesRead)) // 1 is number of bytes read from port, how to make this variable? { nx += cReceivedChar[1]; } AfxMessageBox(nx); Papa while (TRUE) Papa.WillLove ( Bebe ) ;

        M Offline
        M Offline
        macmac38
        wrote on last edited by
        #3

        Hmm, the output now is like: ||||||||| and how can i extract the three values? Thanks, Mark

        J 1 Reply Last reply
        0
        • M macmac38

          Hmm, the output now is like: ||||||||| and how can i extract the three values? Thanks, Mark

          J Offline
          J Offline
          jmkhael
          wrote on last edited by
          #4

          Check the string tokenizer classes on CP The main idea, let the comma be your separator and take the values between and convert them to float or double using atof Remeber to clean the string on each new triplet received, i mean each time you receive (x, y, z) clean your string, of course after doing the processing Papa while (TRUE) Papa.WillLove ( Bebe ) ;

          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