Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I read the serial port "other" pins with VB6?

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
Is there a way I can read the state of the other serial port pins (such as RTS etc) using Vb6?
I have changed my motherboard to a new one that doesn't have a parallel port or serial port, having to use USB adapters for my onld gear.

I have one gadjet that gives a single contact closure and I used to use the parallel port to read this by interrogating the status of &h378. But this is not used by a USB adapter, treating the printer LPT1 like a LAN printer instead.

A USB I/O adapter costs around A$150 but a USB-RS232 only A$30
If I could get access to the pins I could use this instead.
Any help would be appreciated.
I can't use an old joystick fire button or keyboard because a long wire is involved and they use pulses.
 
If all you want to do is to read the status of a contact, you can do this without using the flow control signals.

Just connect your contact switch to Rx/Tx lines (pins 2 and 3) and loopback the data using MSComm control. If the contact is closed, the data is echoed back to the sender.

See the following example.
Place an MSComm control and a Timer control on your form and set its interval to 100. Insert the following code.
___
[tt]
Option Explicit
Dim Status As Boolean
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.PortOpen = True
End Sub

Private Sub Timer1_Timer()
Dim CurrentStatus As Boolean
CurrentStatus = MSComm1.InBufferCount
If Status <> CurrentStatus Then
Status = CurrentStatus
Call StatusChanged
End If
MSComm1.InBufferCount = 0
MSComm1.Output = "X"
End Sub

Sub StatusChanged()
Debug.Print Time; IIf(Status, "Close", "Open")
End Sub[/tt]
___

Test the program by inserting/removing a jumper between pins 2 and 3 of the serial port.
 
Thanks - Very clever! I hadn't though of that.
It is a longish unshielded pair of wires and might get false "openings" because of noise.
I was hoping to use a 0.1uf capacitor across the input so that only true DC would be detected.
Using the loopback method you suggest I will try using the MScomm.Event status to detect an input to the DSR pin instead.
 
The reviews for that card don't look too good!
My problem is that I dont really want to use the standard parallel protocol to communicate with a printer.

I just want to read whether a single slow moving DC input is hi or low - like the CD or DSR pin of a RS232 port.

Modems do it all the time so it must be easy - but how?
 
Thanks but, unless I am mistaken, this seems to be a sales site advertising software for sale such as debugging tools etc and not suitable for inclusion in an application?
 
Well, it said "open source" and "freeware" so it doesn't look like they're interested in selling it. If it's freeware, why can't you include it in an application, so long as you credit the source?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top