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. Data not received properly using COM Port [modified]

Data not received properly using COM Port [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
com
9 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.
  • A Offline
    A Offline
    Ayesha Farheen
    wrote on last edited by
    #1

    Hi, Iam sending data to ComPort and using RS-232 cable Iam trying to receive the data at the other end. I set the properties also(BaudRate,Stop Bits,Parity etc..)both at sender and receiver. Sending End: char dataToSend[100]; dataToSend = "asdfsdf ...."; result = WriteFile(handlePort,dataToSend,99,&length,NULL); Receiving End: char dataReceived[100]; result = ReadFile(handlePort,dataReceived,99,&length,NULL); cout << "Data Received = " << dataReceived<

    D C 2 Replies Last reply
    0
    • A Ayesha Farheen

      Hi, Iam sending data to ComPort and using RS-232 cable Iam trying to receive the data at the other end. I set the properties also(BaudRate,Stop Bits,Parity etc..)both at sender and receiver. Sending End: char dataToSend[100]; dataToSend = "asdfsdf ...."; result = WriteFile(handlePort,dataToSend,99,&length,NULL); Receiving End: char dataReceived[100]; result = ReadFile(handlePort,dataReceived,99,&length,NULL); cout << "Data Received = " << dataReceived<

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Ayesha Farheen wrote:

      result = ReadFile(handlePort,dataReceived,99,&length,NULL);

      What is the value of result? If it is FALSE, what is the return value of GetLastError()? What is the value of length?


      "The largest fire starts but with the smallest spark." - David Crow

      "Judge not by the eye but by the heart." - Native American Proverb

      A 1 Reply Last reply
      0
      • D David Crow

        Ayesha Farheen wrote:

        result = ReadFile(handlePort,dataReceived,99,&length,NULL);

        What is the value of result? If it is FALSE, what is the return value of GetLastError()? What is the value of length?


        "The largest fire starts but with the smallest spark." - David Crow

        "Judge not by the eye but by the heart." - Native American Proverb

        A Offline
        A Offline
        Ayesha Farheen
        wrote on last edited by
        #3

        At both sending and receiving ends , its returning 1 (TRUE). Ayesha

        E 1 Reply Last reply
        0
        • A Ayesha Farheen

          At both sending and receiving ends , its returning 1 (TRUE). Ayesha

          E Offline
          E Offline
          earl
          wrote on last edited by
          #4

          And length? What happens if you flush the buffer?

          A 1 Reply Last reply
          0
          • E earl

            And length? What happens if you flush the buffer?

            A Offline
            A Offline
            Ayesha Farheen
            wrote on last edited by
            #5

            Before sending the data or receiving it , Iam flushing the buffer using following method. int nReturnValue = PurgeComm(handlePort_,PURGE_TXCLEAR | PURGE_RXCLEAR); And the return value is non-zero, i.e flushing succeded. I checked both, with and without PurgeComm(). But still its not working.i.e Output is same for both. And the length received is coming as 0. I didnt understand one thing, Iam sending the data only ones, but why its receiving it those many times and why data is not coming? Thank You. Ayesha -- modified at 2:54 Tuesday 11th July, 2006

            E 1 Reply Last reply
            0
            • A Ayesha Farheen

              Hi, Iam sending data to ComPort and using RS-232 cable Iam trying to receive the data at the other end. I set the properties also(BaudRate,Stop Bits,Parity etc..)both at sender and receiver. Sending End: char dataToSend[100]; dataToSend = "asdfsdf ...."; result = WriteFile(handlePort,dataToSend,99,&length,NULL); Receiving End: char dataReceived[100]; result = ReadFile(handlePort,dataReceived,99,&length,NULL); cout << "Data Received = " << dataReceived<

              C Offline
              C Offline
              Cool Ju
              wrote on last edited by
              #6

              Ayesha wrote: result = WriteFile(handlePort,parameterNCheckSumData,99,&length,NULL); What is parameterNCheckSumData? Should'nt it be dataToSend. Adios, Cool Ju :cool: Dream Ur Destiny

              A 1 Reply Last reply
              0
              • C Cool Ju

                Ayesha wrote: result = WriteFile(handlePort,parameterNCheckSumData,99,&length,NULL); What is parameterNCheckSumData? Should'nt it be dataToSend. Adios, Cool Ju :cool: Dream Ur Destiny

                A Offline
                A Offline
                Ayesha Farheen
                wrote on last edited by
                #7

                Yes , that is dataToSend its not parameterNCheckSumData. But thats just a char buffer name. I want to know why data is not being received properly. Thanku You. Ayesha

                C 1 Reply Last reply
                0
                • A Ayesha Farheen

                  Yes , that is dataToSend its not parameterNCheckSumData. But thats just a char buffer name. I want to know why data is not being received properly. Thanku You. Ayesha

                  C Offline
                  C Offline
                  Cool Ju
                  wrote on last edited by
                  #8

                  Hi, What type of I/O are you performing Overlapped or Non-overlapped? Have you set timeouts? If not, Try setting timeouts. If possible post some code. Adios, Cool Ju :cool: Dream Ur Destiny

                  1 Reply Last reply
                  0
                  • A Ayesha Farheen

                    Before sending the data or receiving it , Iam flushing the buffer using following method. int nReturnValue = PurgeComm(handlePort_,PURGE_TXCLEAR | PURGE_RXCLEAR); And the return value is non-zero, i.e flushing succeded. I checked both, with and without PurgeComm(). But still its not working.i.e Output is same for both. And the length received is coming as 0. I didnt understand one thing, Iam sending the data only ones, but why its receiving it those many times and why data is not coming? Thank You. Ayesha -- modified at 2:54 Tuesday 11th July, 2006

                    E Offline
                    E Offline
                    earl
                    wrote on last edited by
                    #9

                    Flush the buffer after sending the data using FlushFileBuffers. This ensures that nothing gets stuck in a buffer waiting to send. If you are sending the data only once but the remote end is receiving it many times, make sure you have your line enders right -- it could be that the remote end is getting confused. Try 13 10, just 10, and just 13 -- I can never remember which of those are the usual line enders. earl

                    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