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. How to produce a +5V TTL signal on COM port?

How to produce a +5V TTL signal on COM port?

Scheduled Pinned Locked Moved C / C++ / MFC
c++comtutorialquestion
11 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
    pavanbabut
    wrote on last edited by
    #1

    Hi, I am wondering if there is any way to produce a +5V clean TTL signal through COM/RS-232 serial port in C++. I just need to produce a clean +ve spike over the serial port. thanks, -Pavan.

    J M 2 Replies Last reply
    0
    • P pavanbabut

      Hi, I am wondering if there is any way to produce a +5V clean TTL signal through COM/RS-232 serial port in C++. I just need to produce a clean +ve spike over the serial port. thanks, -Pavan.

      J Offline
      J Offline
      James R Twine
      wrote on last edited by
      #2

      You mean other than putting a power regulator/converter to translate +12 to +5?  I have never tried to pull constant power from a COM port and I do not know how much current it can source.    A good project site can be found at: http://www.epanorama.net/links/project_interfacing.html[^].    Peace!

      -=- James
      Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
      Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
      See DeleteFXPFiles

      P 1 Reply Last reply
      0
      • J James R Twine

        You mean other than putting a power regulator/converter to translate +12 to +5?  I have never tried to pull constant power from a COM port and I do not know how much current it can source.    A good project site can be found at: http://www.epanorama.net/links/project_interfacing.html[^].    Peace!

        -=- James
        Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        See DeleteFXPFiles

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

        To be clear, I just need to produce a signal which will have a spike (think of it as a trigger) whenever I like. This is fed to another signal recorder which keeps looking at this signal for any trigger (spike) and records it. -Pavan.

        1 Reply Last reply
        0
        • P pavanbabut

          Hi, I am wondering if there is any way to produce a +5V clean TTL signal through COM/RS-232 serial port in C++. I just need to produce a clean +ve spike over the serial port. thanks, -Pavan.

          M Offline
          M Offline
          malaugh
          wrote on last edited by
          #4

          The RS-232 port has +12v or -12v logic levels. The parallel port has 5v logic levels.

          P 1 Reply Last reply
          0
          • M malaugh

            The RS-232 port has +12v or -12v logic levels. The parallel port has 5v logic levels.

            P Offline
            P Offline
            pavanbabut
            wrote on last edited by
            #5

            Ok, how can I produce a signal of +12v spike using for example this[^] library?? -Pavan.

            J M 2 Replies Last reply
            0
            • P pavanbabut

              Ok, how can I produce a signal of +12v spike using for example this[^] library?? -Pavan.

              J Offline
              J Offline
              jeron1
              wrote on last edited by
              #6

              You can try the EscapeCommFunction() and set/clear the DTR or RTS line.

              1 Reply Last reply
              0
              • P pavanbabut

                Ok, how can I produce a signal of +12v spike using for example this[^] library?? -Pavan.

                M Offline
                M Offline
                malaugh
                wrote on last edited by
                #7

                Have not tried it, but you should be able to open the commport with Handle = CreateFile("Com1",....); then set and clear the DTR line with GetCommState(Handle, &Dcb); Dcb.fDtrControl = DTR_CONTROL_DISABLE; SetCommState(Handle, &Dcb); Dcb.fDtrControl = DTR_CONTROL_ENABLE; SetCommState(Handle, &Dcb); You should be able to use simlar code to toggle the RTS bit

                P 1 Reply Last reply
                0
                • M malaugh

                  Have not tried it, but you should be able to open the commport with Handle = CreateFile("Com1",....); then set and clear the DTR line with GetCommState(Handle, &Dcb); Dcb.fDtrControl = DTR_CONTROL_DISABLE; SetCommState(Handle, &Dcb); Dcb.fDtrControl = DTR_CONTROL_ENABLE; SetCommState(Handle, &Dcb); You should be able to use simlar code to toggle the RTS bit

                  P Offline
                  P Offline
                  pavanbabut
                  wrote on last edited by
                  #8

                  I have tried enabling and disabling DTR and also RTS bit, but couldnt see any spike signal on the Oscilloscope?? I have connected pin 4 and pin 5(ground) for DTR bit to the scope and 7,5 for RTS bit. I didn't see any change in the signal (stays flat at zero all the time). -Pavan

                  J 1 Reply Last reply
                  0
                  • P pavanbabut

                    I have tried enabling and disabling DTR and also RTS bit, but couldnt see any spike signal on the Oscilloscope?? I have connected pin 4 and pin 5(ground) for DTR bit to the scope and 7,5 for RTS bit. I didn't see any change in the signal (stays flat at zero all the time). -Pavan

                    J Offline
                    J Offline
                    jeron1
                    wrote on last edited by
                    #9

                    Can you post some code for the things you have tried?

                    P 1 Reply Last reply
                    0
                    • J jeron1

                      Can you post some code for the things you have tried?

                      P Offline
                      P Offline
                      pavanbabut
                      wrote on last edited by
                      #10

                      Ok, I am getting it. Just played around with the output pins using a LED. The signal goes from -11.6v to +11.6v. Inorder to get a TTL signal, it seems we need to use a voltage converter MAX-232(source:- codeguru forums). Do you know any other way to produce a TTL type signal (0-5v) other than using that converter? I am not sure we can produce without using that, but in case if have any idea lemme know. Thanks for the info, -P.

                      J 1 Reply Last reply
                      0
                      • P pavanbabut

                        Ok, I am getting it. Just played around with the output pins using a LED. The signal goes from -11.6v to +11.6v. Inorder to get a TTL signal, it seems we need to use a voltage converter MAX-232(source:- codeguru forums). Do you know any other way to produce a TTL type signal (0-5v) other than using that converter? I am not sure we can produce without using that, but in case if have any idea lemme know. Thanks for the info, -P.

                        J Offline
                        J Offline
                        jeron1
                        wrote on last edited by
                        #11

                        You can try an NPN transistor... try 10k going into the base, then put a Schottky (like a 1N5817) with the cathode directly on the base and anode connected to ground. Then connect a 4.7k from collector to 5v supplied by you. The RS232 ground would have to tie to your logic ground. The 5v signal should be present on the collector of the transistor.

                        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