Results 1 to 6 of 6

Thread: MSComm DCD line change counter problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    5

    MSComm DCD line change counter problem

    Hello!
    I am working on a little program that counts changes in the serial port CD line.
    I have connected pin 4 (DTR) and pin 1 (DCD) to a button and I am trying to make a program that counts how many times button is pressed. Here is the code:
    Code:
    Private Sub Form_Load()
    With MSComm1
        .CommPort = 1
        .Settings = "9600,n,8,1"
        .SThreshold = 1
        .RThreshold = 1
        .Handshaking = comXOnXoff
        .PortOpen = True
      End With
    End Sub
    Private Sub MSComm1_OnComm()
      Select Case MSComm1.CommEvent
    Case comEvCD
         If MSComm1.CDHolding = True Then
    Label1.Caption = Val(Label1.Caption) + 1
    End If
    End Select
    End Sub
    When button is pressed the label1 should show +1, but the problem is that the label1 sometimes show +2 or even +3 after button is pressed only once. I am very new to vb programing so I was wondering if someone could please tell me if this is possible, and if it is some code would be very helpful. Thank You in advance!

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: MSComm DCD line change counter problem

    Switch contacts bounce. Consider the information at http://all-electric.com/schematic/debounce.htm

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    5

    Re: MSComm DCD line change counter problem

    Thank You Mate!!

    That helped!
    I just need a little bit more of Your knowledge. Can You please write me the code to do the same thing with ringing indicator (pin 9)? There is no RIHolding property.

    Best regards

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    5

    Re: MSComm DCD line change counter problem

    Does anybody knows? I found this site:
    http://www.danielandrade.net/2005/11...inamp-control/

    This guy used four buttons to control winamp. (dcd, dsr, cts and ri)
    The first three have the holding property, but I don't know what to do with ringing indicator?
    Some code would be very helpful. Thank You!

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2011
    Posts
    5

    Re: MSComm DCD line change counter problem

    Anybody?

  6. #6
    Fanatic Member
    Join Date
    Sep 2009
    Location
    Lakewood, Colorado
    Posts
    621

    Re: MSComm DCD line change counter problem

    MSComm does not expose Ring Indicate state (because it was designed to work with a modem, where RI is transient, thus the only indication is via CommEvent = comRingEvent). The only way to read the RI state is via the UART Modem Status Register. You can download IOOcx from my homepage to do this. However, note, that this works only with built-in serial ports, where there is a physical UART.

    If you are using a USB serial adapter, then there is no practical way to get the RI status, AFAIK. This "issue" is caused by the way that the serial port device drivers are written, and is historical in nature.

    Dick (www.hardandsoftware.net)
    Last edited by DickGrier; Sep 6th, 2011 at 12:41 PM. Reason: add link
    Richard Grier, Consultant, Hard & Software
    Microsoft MVP (Visual Basic)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width