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

Communication with serial port

Scheduled Pinned Locked Moved C / C++ / MFC
9 Posts 5 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.
  • T Offline
    T Offline
    tina newcoder
    wrote on last edited by
    #1

    Hi friends, troubling you yet again... I want to communicate with serial port (COM1). I want to send/receive some data through it. I have read earlier post, & also found a project on serial port. But i m not able to understand anything of that. :sigh: I simply want to brief steps about:suss: ->opening a port ->reading a port ->write a port Thanking you in advance :)

    CPalliniC S B 3 Replies Last reply
    0
    • T tina newcoder

      Hi friends, troubling you yet again... I want to communicate with serial port (COM1). I want to send/receive some data through it. I have read earlier post, & also found a project on serial port. But i m not able to understand anything of that. :sigh: I simply want to brief steps about:suss: ->opening a port ->reading a port ->write a port Thanking you in advance :)

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      tina- wrote:

      ->opening a port

      CreateFile or (CreateFileEx) function, if you have a look at MSDN configuration sample [^], you can easily figure out the usage.

      tina- wrote:

      ->reading a port ->write a port

      ReadFile and WriteFile: the usage in not-overlapped mode is not such difficult, but perhaps you need to go multithreading. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      [my articles]

      In testa che avete, signor di Ceprano?

      T 1 Reply Last reply
      0
      • CPalliniC CPallini

        tina- wrote:

        ->opening a port

        CreateFile or (CreateFileEx) function, if you have a look at MSDN configuration sample [^], you can easily figure out the usage.

        tina- wrote:

        ->reading a port ->write a port

        ReadFile and WriteFile: the usage in not-overlapped mode is not such difficult, but perhaps you need to go multithreading. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        [my articles]

        T Offline
        T Offline
        tina newcoder
        wrote on last edited by
        #3

        CPallini wrote:

        CreateFile or (CreateFileEx)

        thanx friend. the project i downloaded (abt serial comm) used CreateFile, but wat do u think will be the first parameter (lpFileName)? :confused: will it be COM1

        CPalliniC 1 Reply Last reply
        0
        • T tina newcoder

          CPallini wrote:

          CreateFile or (CreateFileEx)

          thanx friend. the project i downloaded (abt serial comm) used CreateFile, but wat do u think will be the first parameter (lpFileName)? :confused: will it be COM1

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          It must be _T("COM1") for serial port 1. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          [my articles]

          In testa che avete, signor di Ceprano?

          T 1 Reply Last reply
          0
          • CPalliniC CPallini

            It must be _T("COM1") for serial port 1. :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            [my articles]

            T Offline
            T Offline
            tina newcoder
            wrote on last edited by
            #5

            How can we know if a data has been received at the serial port ? is it required to check the port continuously, using ReadFile(), & if it return anything than 0, then we conclude that a data is received ?

            CPalliniC C 2 Replies Last reply
            0
            • T tina newcoder

              How can we know if a data has been received at the serial port ? is it required to check the port continuously, using ReadFile(), & if it return anything than 0, then we conclude that a data is received ?

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              Yes, if you use not-overlapped I/O. This way the application probably needs an additional thread always waiting for incoming data on the serial line. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              [my articles]

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              • T tina newcoder

                How can we know if a data has been received at the serial port ? is it required to check the port continuously, using ReadFile(), & if it return anything than 0, then we conclude that a data is received ?

                C Offline
                C Offline
                Cedric Moonen
                wrote on last edited by
                #7

                It depends of the timeouts you specified on the comm port. Basically, you can configure your COM port so that it never waits for data (ReadFile returns immediately) or that it blocks forever until some characters have been received, or something in the middle. Check the SetCommTimeouts[^] function. Anyway working with the serial port is not something easy for a beginner. So expect some frustration because nothing works as expected. But we're to help if needed ;) .

                Cédric Moonen Software developer
                Charting control [v1.2]

                modified on Monday, January 21, 2008 2:37:11 AM

                1 Reply Last reply
                0
                • T tina newcoder

                  Hi friends, troubling you yet again... I want to communicate with serial port (COM1). I want to send/receive some data through it. I have read earlier post, & also found a project on serial port. But i m not able to understand anything of that. :sigh: I simply want to brief steps about:suss: ->opening a port ->reading a port ->write a port Thanking you in advance :)

                  S Offline
                  S Offline
                  SandipG
                  wrote on last edited by
                  #8

                  Try using CMSCommCtrl class . for this you have to add MSCOMM32.ocx control activex control to your project.

                  1 Reply Last reply
                  0
                  • T tina newcoder

                    Hi friends, troubling you yet again... I want to communicate with serial port (COM1). I want to send/receive some data through it. I have read earlier post, & also found a project on serial port. But i m not able to understand anything of that. :sigh: I simply want to brief steps about:suss: ->opening a port ->reading a port ->write a port Thanking you in advance :)

                    B Offline
                    B Offline
                    beko
                    wrote on last edited by
                    #9

                    Check Ramon Klein's very nice implementation, he should have an article here on CP and his web page for updated source code.

                    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