Reputation: 11
I need to control another circuit through the serial port. (I have heard that pin 4 and pin 7 are used for that purpose. If these pins are incorrect, please tell me what pins are used for such purposes
My requirement is to set those pins to high or low and read their levels(high or low) through a VB6 program.
Any ideas on how to accomplish the task?
Upvotes: 1
Views: 5528
Reputation: 796
There's good high-level advice in other answers, but from a practical POV it's pretty simple. There are two control inputs (DSR and CTS) and two control outputs (DTR and RTS). DTR is on pin 4 (9-pin version) and RTS is on pin 7. DSR / CTS are pins 6 and 8.
Place a Comm Port object on a VB form, and set .CommPort
to the number of your port. For pure logic control purposes it doesn't matter what .Settings
(baudrate etc) you use because you won't be sending and receiving any serial data, so just accept the defaults.
Set .PortOpen = True
, then change the DTR and RTS outputs by setting .DTREnable
/ .RTSEnable
to true or false as required. You should set these False at design time to avoid false triggering. Be aware that these lines may be toggled by the system when the PC reboots.
You can poll the .CTSHolding
and .DSRHolding
properties to detect changes on those inputs, or react to the .OnComm
event, which will get signaled when there's a change in either one. You still have to sort out which one caused the event, but that's just a Select Case.
Upvotes: 2
Reputation: 30398
Richard Grier's Visual Basic Programmer's Guide to Serial Communications is a good book that covers VB6 (and VB.Net): it's available from his website, about $40 US plus shipping.
It looks like he still hangs out on the VB6 newsgroup, so that's a good place to ask about serial programming.
Upvotes: 0
Reputation: 35088
You don't have to worry about the individual pins. Most operating systems expose system calls to manipulate the pins for you, and some languages (including VB6) provide ways to use those system calls. A quick Google search turned up a tutorial that includes some details on the pins, if you're interested. However, this one looks a little easier to follow, at least in my opinion.
Upvotes: 1