can visual basic control serial or usb port power?

Electronics Computer Programming Q&A
Post Reply
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

can visual basic control serial or usb port power?

Post by Mike »

I would like to build a 5V output from serial port adapter to control a relay. Is there a way I can write a program in visual basic to control the power to the seial or usb port? Either port would work, but I would prefer the USB becuase there is two voltages, 5 and 12V that can control 2 relays, right?<p>Thanks for the help, Mike
hp
Posts: 245
Joined: Sat Aug 09, 2003 1:01 am
Location: Friendswood, TX
Contact:

Re: can visual basic control serial or usb port power?

Post by hp »

I believe it would be easier to use the parallel port for controling relays.<p>The following links contain some good info on vb parallel port programming:<p>http://www.logix4u.net/
http://www.lvr.com/parport.htm<p>http://www.logix4u.net/parallelport1.htm
http://www.logix4u.net/paralleltest.gif <<test schematic<p>-----------------------------------------------<p>Just remember, if you want to use the parallel port to control relays: Make sure you use buffer transistors or some sort of high current driver like the ULN2803 chip.<p>Hope this helps (even though it doesnt answer your usb question),
Harrison<p>[ November 16, 2003: Message edited by: hp ]<p>[ November 16, 2003: Message edited by: hp ]</p>
dyarker
Posts: 1917
Joined: Fri Aug 22, 2003 1:01 am
Location: Izmir, Turkiye; from Rochester, NY
Contact:

Re: can visual basic control serial or usb port power?

Post by dyarker »

No, you can't control power to serial or USB ports. hp's suggestion is better if you're using DOS, Win 3.x, Win 95, Win 98 or Win ME. It will NOT work for Win NT, Win 2000 or Win XP.<p>For two relays on any version of windows use the DTR (data terminal ready) and RTS (request to send) lines of the serial port. These can be controlled by a program.<p>DTR and RTS don't have enough current capability to drive the relays, buffers are needed.
Dale Y
hp
Posts: 245
Joined: Sat Aug 09, 2003 1:01 am
Location: Friendswood, TX
Contact:

Re: can visual basic control serial or usb port power?

Post by hp »

Mr. Dale Y,<p>According to the webpage http://www.logix4u.net/inpout32.htm you can have full port access in windows 2000 and XP. The dll uses a win 2k / XP system driver to access the parallel port. If win 2k or XP is not detected then the dll goes along and accesses the port directly without using a windows driver.<p>So I believe the dll should work with all windows versions. I used it before with windows 2k and it worked fine for me.<p>Harrison
dyarker
Posts: 1917
Joined: Fri Aug 22, 2003 1:01 am
Location: Izmir, Turkiye; from Rochester, NY
Contact:

Re: can visual basic control serial or usb port power?

Post by dyarker »

A ring0 DLL, that would be very useful. Thanx<p>mikea1962375,
I believe you're using Win XP, so you'll need the DLL referenced in the link in hp's second post to make a parallel port interface.<p>C U L-
Dale Y
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

Re: can visual basic control serial or usb port power?

Post by Mike »

Is there any way to accomplish this with usb? I have a windows 2000 machine with usb only, then sometimes I would like to use it on a windows 98 machine. I guess I could use serial port, though, and how would I go about connecting all the parts? And, also, are you sure that the serial port can't deliver enough power? I would think it would run a 80ma relay, or not?<p>And how would I use visual basic to control them? Or, instead of relays, can I use an optocoupler? Since it uses an led, it should only draw a couple of ma, right?<p>Thanks, Mike
Tommy volts
Posts: 149
Joined: Tue Oct 29, 2002 1:01 am
Location: Arizona
Contact:

Re: can visual basic control serial or usb port power?

Post by Tommy volts »

It is a little expensive, but the link below will take you to a real neat USB interface module with tutorial on programming it VB, C++ etc. If I had the $$ I would go for it.<p>
USB Interface
dyarker
Posts: 1917
Joined: Fri Aug 22, 2003 1:01 am
Location: Izmir, Turkiye; from Rochester, NY
Contact:

Re: can visual basic control serial or usb port power?

Post by dyarker »

For USB, look in Nuts & Volts (probably in later half) for a company selling USB to parallel converter circuit boards. Put that circuit board in a plastic box with a buffer chip with your relay(s). Power it with a 9VDC or 12VDC wall wart and a regulator in the box. You can have 8 relays, or 4 inputs and 4 relays, whatever combo you want. Make sure to get a converter board that comes with the USB driver and sample code.<p>They also have USB to serial converters. These are useful for hooking up external MODEMs, GPS units, robots with serial ports, etc., to computers with only USB ports.<p>RS-232 (serial) ports are protected against shorted outputs by resistors inside the driver chip. Probably like 250 Ohms to 1.5KOhms 'cause the receiver chips have 3KOhms to 7KOhms input resistance. 12V / 500 Ohms = 24mA. Also, RS-232 is polar (+12V space to -12V mark). Opto isolators are a good idea. Put a signal diode in parallel with the LED with reverse polarity. With a darlington opto isolator the tranfer ratio will be high enough to drive the relay.<p>Use the opto to directly control the load? Yeah, if the load is low voltage DC, low current like a small relay or a few LEDs. For AC, high voltage (AC or DC), or high(er) current; use a relay.<p>The USB to parallel method is better.<p>How in Visual BASIC? I don't know. In about '97 I bought VB 5 (not the Pro version) because I wanted a newer compiler that would do GUI design better. The project at the time was working with an Access database. That VB 5 did absolutely no database, had to have VB 5 Pro. I've still got it, and looked in Help (for this reply) for communications, serial, port, etc.; nothing. What good is a Windows program with pretty controls if it can't communicate or read a database? I felt cheated, and wouldn't upgrade to VB Pro even if I had the money. Finished the project, sort of, with VBA; and switched back to PowerBASIC when their 32 bit compilers came out. Don't get me wrong, I like Windows, Word is almost as good as WordPerfect, Excel is better than Lotus 123 ever was, and Access is a good single user (another long story) database. But never again a Microsoft compiler.<p>Cheers & C U L -<p>[ November 18, 2003: Message edited by: Dale Y ]</p>
Dale Y
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

Re: can visual basic control serial or usb port power?

Post by Mike »

I have VB5 pro, and it really is worth the money if you use databases a lot. It is so simple to integrate databases into applications. <p>So, to connect the optoisolator, I just connect it to the DTS or RTS output of the serial port and to the ground, then use VB5 to control the port?
wd5gnr
Posts: 104
Joined: Wed Dec 19, 2001 1:01 am
Contact:

Re: can visual basic control serial or usb port power?

Post by wd5gnr »

One thing you could consider (although it might be a little overkill) is a GP-3 (see http://www.al-williams.com/gp3.htm). This board can control several digital outputs, has digital inputs, analog input, PWM, etc. You can connect to it with an ActiveX control from VB, VB.net, VBA, C++, etc. This along with a USB to serial adapter would give you a lot of control options from a VB program.
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

Re: can visual basic control serial or usb port power?

Post by Mike »

I decided that I would never use it with the laptop, so I will stick to the serial port. All I need is for it to pull down a relay on press of one button, and release it when the release button is pressed in the program.
dyarker
Posts: 1917
Joined: Fri Aug 22, 2003 1:01 am
Location: Izmir, Turkiye; from Rochester, NY
Contact:

Re: can visual basic control serial or usb port power?

Post by dyarker »

Yes. DTR pin to resistor (try 470 Ohms, 1/4W), other end of resistor to optoisolator LED's cathode, also to LED cathode connect a signal diode's anode, LED anode and signal diode cathode to RS-232 ground (pin 7 on 25 pin connectors, pin 5 ?? on 9 pin connectors).<p>Repeat for RTS.<p>The signal diodes are needed because LEDs have a very low reverse breakdown voltage, 4 or 5 volts.<p>The expected behavior is:<p>1. Optoisolators off when computer is off. (because there is no voltage to drive LEDs.)<p>2. Optoisolators off when computer is on, but no program is accessing the port. (default state for serial port pins is "false".)<p>3. Optoisolators on/off controlled by program.<p>(( If the optoisolators are on when no program is accessing the port; then either I mis-remembered that +12V is false, or you reversed the cathodes and anodes. Either way, the fix is to swap the cathodes and anodes. ))<p>To separate hardware trouble shooting from software trouble shooting, use Hyperterminal. Set Hyperterminal to "direct connection" on the serial port. The DTR opto should turn on. The DTR opto should turn off when Hyperterminal is closed. RTS probably can't be tested with Hyperterminal because there is no DSR (Data Set Ready) input.<p>If you find that DTR works in your VB5 program but RTS doesn't, then connect -12V through a 1K Ohm resistor to the DSR pin. That may fool VB into thinking there is a device connected to the port, and that requesting to send makes sense.<p>***** Just remembered... the TX pin can be used for a third optoisolator or the -12V for DSR. Idle TX is -12V, "Break" is +12V. ******<p>Have fun ...<p>[ November 20, 2003: Message edited by: Dale Y ]</p>
Dale Y
Tommy volts
Posts: 149
Joined: Tue Oct 29, 2002 1:01 am
Location: Arizona
Contact:

Re: can visual basic control serial or usb port power?

Post by Tommy volts »

Mike,<p>I built a very simple I/O with relay driven off the serial port. I used Qbasic to run the system but I'm sure you could easily convert to VB. <p>The circuit is very simple and is based on a Ray Green article in N&V several years ago. The total cost of the project is around $10 including relay.<p>Later I corresponded (over this forum) with another gentlemen who after some modifications to my program was able use the same circuit to log data into a table.<p>If you are interested I can dig up the article date for your reference.
Mike
Posts: 1813
Joined: Thu Mar 06, 2003 1:01 am
Location: Illinois
Contact:

Re: can visual basic control serial or usb port power?

Post by Mike »

Yes, I am interested, if you can find it. <p>Thank you!<p>-Mike
Tommy volts
Posts: 149
Joined: Tue Oct 29, 2002 1:01 am
Location: Arizona
Contact:

Re: can visual basic control serial or usb port power?

Post by Tommy volts »

Mike,<p>The first article is in the N&V Nov 2001 Vol 22 No. 11 page 73, Ray Green. this has everything you need to build a serial port I/O with relay.<p>The second article is also helpful. It is in the N&V Aug 2002.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests