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. Get Number of Serail Port in Computer

Get Number of Serail Port in Computer

Scheduled Pinned Locked Moved C / C++ / MFC
question
8 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.
  • M Offline
    M Offline
    MANISH RASTOGI
    wrote on last edited by
    #1

    Hi, How can I know the number of serial ports on my computer using code? Thanks,

    H K 2 Replies Last reply
    0
    • M MANISH RASTOGI

      Hi, How can I know the number of serial ports on my computer using code? Thanks,

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      Is Another serial port enumerator[^] helpful? ;)

      M 1 Reply Last reply
      0
      • H Hamid Taebi

        Is Another serial port enumerator[^] helpful? ;)

        M Offline
        M Offline
        MANISH RASTOGI
        wrote on last edited by
        #3

        Thanks Hamid

        H 1 Reply Last reply
        0
        • M MANISH RASTOGI

          Thanks Hamid

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          You're welcome. :)

          1 Reply Last reply
          0
          • M MANISH RASTOGI

            Hi, How can I know the number of serial ports on my computer using code? Thanks,

            K Offline
            K Offline
            kapardhi
            wrote on last edited by
            #5

            You may try this ! #define MAX_AVAIL_COM_PORTS 250 int i = 0; char chTemp[3]; CString strCOMPort; HANDLE hndCurrCOMPortObj; for (i = 0; i < MAX_AVAIL_COM_PORTS; i ++) { itoa (i + 1, chTemp, 10); strCOMPort = "COM"; strCOMPort += chTemp; // Create handle for selected COM port and check its Avilability hndCurrCOMPortObj = CreateFile (strCOMPort,GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); if (INVALID_HANDLE_VALUE == hndCurrCOMPortObj) { strCOMPort += strCOMPort + " port not available !!"; AfxMessageBox (strCOMPort); } else { strCOMPort += " port Available !!"; AfxMessageBox (strCOMPort); CloseHandle (hndCurrCOMPortObj); } }

            CPalliniC 1 Reply Last reply
            0
            • K kapardhi

              You may try this ! #define MAX_AVAIL_COM_PORTS 250 int i = 0; char chTemp[3]; CString strCOMPort; HANDLE hndCurrCOMPortObj; for (i = 0; i < MAX_AVAIL_COM_PORTS; i ++) { itoa (i + 1, chTemp, 10); strCOMPort = "COM"; strCOMPort += chTemp; // Create handle for selected COM port and check its Avilability hndCurrCOMPortObj = CreateFile (strCOMPort,GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); if (INVALID_HANDLE_VALUE == hndCurrCOMPortObj) { strCOMPort += strCOMPort + " port not available !!"; AfxMessageBox (strCOMPort); } else { strCOMPort += " port Available !!"; AfxMessageBox (strCOMPort); CloseHandle (hndCurrCOMPortObj); } }

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

              It won't work for ports having number >= 10. :)

              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.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              In testa che avete, signor di Ceprano?

              K 1 Reply Last reply
              0
              • CPalliniC CPallini

                It won't work for ports having number >= 10. :)

                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.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                K Offline
                K Offline
                kapardhi
                wrote on last edited by
                #7

                Thanks ! i didn't knew this !! but can u plz tell me the reason why this doesn't work ? and can you give a solution to it, bcoz i need the requirement must be fullfilled in a small code rather that importing those classes !!

                CPalliniC 1 Reply Last reply
                0
                • K kapardhi

                  Thanks ! i didn't knew this !! but can u plz tell me the reason why this doesn't work ? and can you give a solution to it, bcoz i need the requirement must be fullfilled in a small code rather that importing those classes !!

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

                  kapardhi wrote:

                  i didn't knew this !!

                  I suspected so. :rolleyes:

                  kapardhi wrote:

                  but can u plz tell me the reason why this doesn't work ?

                  Because you must use UNC [^] names for serial ports with number >= 10, e.g. port 12 UNC is \\.\COM12 (you may use always UNC names). :)

                  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.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  In testa che avete, signor di Ceprano?

                  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