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
helpquestion
7 Posts 4 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.
  • P Offline
    P Offline
    Paddy
    wrote on last edited by
    #1

    Hi hope someone can help me out here. I have a program that recieves data from the serial port of the PC and saves it into a file using: byte rec; : : : for(i=0;i<512;i++) { ReadFile(handlePort, &rec, 1, (LPDWORD)&bytes, NULL); fprintf(out, "%C", rec); } The problem is that it wont save the hex values 0x11 and 0x13 to the file when they are received from the serial port, I'm pretty sure it is because they are control characters, maybe? Also every so often it saves 0x0D to the file! Any ideas how I can get around this problem? Thanks in advance, Paddy

    S 1 Reply Last reply
    0
    • P Paddy

      Hi hope someone can help me out here. I have a program that recieves data from the serial port of the PC and saves it into a file using: byte rec; : : : for(i=0;i<512;i++) { ReadFile(handlePort, &rec, 1, (LPDWORD)&bytes, NULL); fprintf(out, "%C", rec); } The problem is that it wont save the hex values 0x11 and 0x13 to the file when they are received from the serial port, I'm pretty sure it is because they are control characters, maybe? Also every so often it saves 0x0D to the file! Any ideas how I can get around this problem? Thanks in advance, Paddy

      S Offline
      S Offline
      Sean Cundiff
      wrote on last edited by
      #2

      Check out your fopen statement. I bet it looks like: fopen("file name", "w"); try this instead: fopen("file name", "wb"); -Sean ---- Shag a Lizard

      P D 2 Replies Last reply
      0
      • S Sean Cundiff

        Check out your fopen statement. I bet it looks like: fopen("file name", "w"); try this instead: fopen("file name", "wb"); -Sean ---- Shag a Lizard

        P Offline
        P Offline
        Paddy
        wrote on last edited by
        #3

        Thanks you were right! I changed it and it has *nearly* solved the problem, it got rid of the random 0x0D in the output file but it still won't write 0x11 and 0x13 to the file. Maybe it is that it isn't reading these values from the port? Any ideas? Thanks

        J 1 Reply Last reply
        0
        • P Paddy

          Thanks you were right! I changed it and it has *nearly* solved the problem, it got rid of the random 0x0D in the output file but it still won't write 0x11 and 0x13 to the file. Maybe it is that it isn't reading these values from the port? Any ideas? Thanks

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

          Have you tried CFile::SetMode(hFile, O_BINARY) ?

          P 1 Reply Last reply
          0
          • S Sean Cundiff

            Check out your fopen statement. I bet it looks like: fopen("file name", "w"); try this instead: fopen("file name", "wb"); -Sean ---- Shag a Lizard

            D Offline
            D Offline
            Dr Kuulun
            wrote on last edited by
            #5

            hi, use the activex control mscomm! this will solve all your problems. markus Dr-Kuulun

            P 1 Reply Last reply
            0
            • J JohnnyG

              Have you tried CFile::SetMode(hFile, O_BINARY) ?

              P Offline
              P Offline
              Paddy
              wrote on last edited by
              #6

              Thanks for the help but I'm actually using win32, non MFC Paddy

              1 Reply Last reply
              0
              • D Dr Kuulun

                hi, use the activex control mscomm! this will solve all your problems. markus Dr-Kuulun

                P Offline
                P Offline
                Paddy
                wrote on last edited by
                #7

                Thanks for the help. For some reason I don't actually have that control in my visual studio. Think it is only with the older versions? Paddy

                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