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. Managed C++/CLI
  4. Using serial ports in vs on xp

Using serial ports in vs on xp

Scheduled Pinned Locked Moved Managed C++/CLI
c++visual-studiocomtutorialquestion
5 Posts 3 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
    McFly555
    wrote on last edited by
    #1

    Can anyone tell me how to output data and recieve from a com port on xp/nt in vs2005 managed C++ ? I have done Parallel i/o before but only on win 9x and never serial. Thx...

    2 1 Reply Last reply
    0
    • M McFly555

      Can anyone tell me how to output data and recieve from a com port on xp/nt in vs2005 managed C++ ? I have done Parallel i/o before but only on win 9x and never serial. Thx...

      2 Offline
      2 Offline
      2bee
      wrote on last edited by
      #2

      Hi, if you are using .Net 2 then System::IO::Ports::SerialPort should be the way to go. However, i found this new serial port class quite unreliable (in terms of switching RTS) and used therefore recently the one from windows.h. for example: HANDLE _ComPort = CreateFile( ptrComName,....); // create a port and use WriteFile(_ComPort, ptrTxFrame, pTxFrameLength,&ulBytesWritten, 0); ReadFile(_ComPort, ptrRxFrame, 256, &ulBytesWritten, NULL); to read and write, but with this approach you'll always have to pinpoint your buffers. pin_ptr ptrTxFrame = &pTxFrame[0]; best regards Tobias

      M 1 Reply Last reply
      0
      • 2 2bee

        Hi, if you are using .Net 2 then System::IO::Ports::SerialPort should be the way to go. However, i found this new serial port class quite unreliable (in terms of switching RTS) and used therefore recently the one from windows.h. for example: HANDLE _ComPort = CreateFile( ptrComName,....); // create a port and use WriteFile(_ComPort, ptrTxFrame, pTxFrameLength,&ulBytesWritten, 0); ReadFile(_ComPort, ptrRxFrame, 256, &ulBytesWritten, NULL); to read and write, but with this approach you'll always have to pinpoint your buffers. pin_ptr ptrTxFrame = &pTxFrame[0]; best regards Tobias

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

        Thx Bee.. I think that was just what I needed. I wonder tho, about the reliability. I don't need rts or dts.. just to have them both stay high. I am wondering if switching is a problem. Can you elaborate a bit on that part? If I just set it high and forget it, will it stay? I am hoping the problem you are talking about is the api not seeing the change state. So if I set it then it will stay, not wanting to write a watchdog for it. Thx for the reply..

        2 1 Reply Last reply
        0
        • M McFly555

          Thx Bee.. I think that was just what I needed. I wonder tho, about the reliability. I don't need rts or dts.. just to have them both stay high. I am wondering if switching is a problem. Can you elaborate a bit on that part? If I just set it high and forget it, will it stay? I am hoping the problem you are talking about is the api not seeing the change state. So if I set it then it will stay, not wanting to write a watchdog for it. Thx for the reply..

          2 Offline
          2 Offline
          2bee
          wrote on last edited by
          #4

          Right, maybe it did sound a little negative. The reason for my statement was that my application really depends on a very accurate switching time between Request to Send enabled/disabled. For some reason this switching time differs for each switch, 5-15 ms while using the .Net class. Thus I need a constant switching time, which must be less than 10 ms, i'll sometimes run into trouble. With the windows.h method I have never discovered this problem. It displays all the time a continuous 5 ms switch time on my oscilloscope. Probably there is a way to close out this problem but by the time I faced this problem, it was quite critical to go ahead with my project. Therefore I decided to go for the unmanaged option for the time being. However apart from this odd behaviour this new class is quite comfortable and very straight forward. I'll maybe give it another try after finishing my project. best regards Tobias

          M 1 Reply Last reply
          0
          • 2 2bee

            Right, maybe it did sound a little negative. The reason for my statement was that my application really depends on a very accurate switching time between Request to Send enabled/disabled. For some reason this switching time differs for each switch, 5-15 ms while using the .Net class. Thus I need a constant switching time, which must be less than 10 ms, i'll sometimes run into trouble. With the windows.h method I have never discovered this problem. It displays all the time a continuous 5 ms switch time on my oscilloscope. Probably there is a way to close out this problem but by the time I faced this problem, it was quite critical to go ahead with my project. Therefore I decided to go for the unmanaged option for the time being. However apart from this odd behaviour this new class is quite comfortable and very straight forward. I'll maybe give it another try after finishing my project. best regards Tobias

            M Offline
            M Offline
            Member_3130247
            wrote on last edited by
            #5

            Hi I too have been looking for a way to access the comm ports using managed code. I'm pretty new to Visual C++ so I need a little more information regarding how to setup and access a com port connected to a USB-Serial adapter. My comm port shows up as COM7 in windows. I need baby steps for opening, configuring and sending and receiving data. I only need to send about 5 or 6 chars but can possibly receive 10 or up to 512 chars from the serial device I'm interfacing with. All the code I've come across on the web doesn't seem to work with Visual C++ 2005 expess Edition.:confused:

            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