|
-
Sep 1st, 2011, 04:58 AM
#1
Thread Starter
New Member
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!
-
Sep 1st, 2011, 05:26 AM
#2
Re: MSComm DCD line change counter problem
Switch contacts bounce. Consider the information at http://all-electric.com/schematic/debounce.htm
-
Sep 2nd, 2011, 07:42 AM
#3
Thread Starter
New Member
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
-
Sep 5th, 2011, 04:08 AM
#4
Thread Starter
New Member
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!
-
Sep 6th, 2011, 04:49 AM
#5
Thread Starter
New Member
Re: MSComm DCD line change counter problem
-
Sep 6th, 2011, 12:39 PM
#6
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|