|
-
September 1st, 2011, 05:13 AM
#1
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!
-
September 1st, 2011, 07:33 AM
#2
Re: MSComm DCD line change counter problem
The answer is quite easy to give: Your button is "bouncing" as we say.
It has a mechanical contact. When contacts are closing they produce a series of open-close-open-close intervals within the first miliseconds before they completely close.
Programmers live in the world of very short time periods, because electronics detect these very short puls trains. The MSComm detects not all but some of these, producing multiple events.
What you can do is "debounce" the button.
With the first event you start a timer of say 100ms and do not react on further comEvCD events while the timer is running.
In fact after the first pule has detected, you wait a period of 100 (or better 200) ms, letting the contacts time to close.
Another way would be to connect a capacitor of about 5-10uF parallel to the switch to debounce it electrically.
Last edited by WoF; September 1st, 2011 at 07:36 AM.
-
September 2nd, 2011, 07:40 AM
#3
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
-
September 2nd, 2011, 10:00 AM
#4
Re: MSComm DCD line change counter problem
If memory serves a ring condition triggers the receive event with the word RING
Always use [code][/code] tags when posting code.
-
September 2nd, 2011, 01:05 PM
#5
Re: MSComm DCD line change counter problem
 Originally Posted by DataMiser
If memory serves a ring condition triggers the receive event with the word RING
I'm afraid the RING is sent by the modem as character sequence when it detects a ring event. So unless MSComm generates another one on its own I doubt that helps...
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
September 2nd, 2011, 03:39 PM
#6
Re: MSComm DCD line change counter problem
I don't understand what you actually want.
The Ring is no hardware line you can activate with a pushbutton...
-
September 2nd, 2011, 03:57 PM
#7
Re: MSComm DCD line change counter problem
 Originally Posted by Eri523
I'm afraid the RING is sent by the modem as character sequence when it detects a ring event. So unless MSComm generates another one on its own I doubt that helps...
It has been a while, makes sense though as there would be no ring unless connected to a phone line via a modem.
Always use [code][/code] tags when posting code.
-
September 2nd, 2011, 06:44 PM
#8
Re: MSComm DCD line change counter problem
 Originally Posted by WoF
The Ring is no hardware line you can activate with a pushbutton...
Really? AFAIK it is. I had to look that up though, since I wasn't sure whether it might have been dropped in the transistion to the now common DE-9 connector but it seems to still be there on pin 9. (See http://en.wikipedia.org/wiki/Serial_port#Pinouts)
Last edited by Eri523; September 2nd, 2011 at 06:46 PM.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
September 3rd, 2011, 05:22 AM
#9
Re: MSComm DCD line change counter problem
I found this site:
http://www.danielandrade.net/2005/11...inamp-control/
This guy used four pins to control winamp, DCD, DSR, CTS and RI.
DCD, DSR, CTS have the holding property, but I don't know what to do with RI.
-
September 5th, 2011, 03:50 AM
#10
Re: MSComm DCD line change counter problem
Anybody?
Some code please.
-
September 5th, 2011, 07:16 AM
#11
Re: MSComm DCD line change counter problem
Have you tried this?
Code:
Case comEvRing ' Change in the Ring Indicator.
Always use [code][/code] tags when posting code.
-
September 6th, 2011, 05:20 PM
#12
Re: MSComm DCD line change counter problem
Well, yes Eri, you are right. the RING is a hardware line, being able to be activated with a pushbutton.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|