views:

62

answers:

4

Can anyone point me in the right direction as to what is all involved in developing an interface that will use the COM port to switch a set of dry contacts on and off?

I have an application that I am developing at present that needs to control an external switch that uses wires. The COM port should switch between a short and an open.

Can someone tell me what is all involved in this? My software will be running the XP OS.

A: 

There are a variety of approaches, none of them is pure software. Stack Overflow isn't a good place to ask for help until you have the hardware designed.

  • Use the COM port control signals such as RTS, which can be independently set using e.g. SetCommState

or

  • Use the serial port to communicate with a microcontroller, which can directly control dozens of GPIO pins according to the commands you send it and the program you put inside it.

Another alternative, not using a COM port, would be to use a digital output peripheral. USB is probably the most common interface used to talk to interfact peripherals these days.

Ben Voigt
Ben, I do not have to design any hardware. Think of it as my application turning on a light switch. I am using a web development platform so I'm not really sure about SetCommState or even the microcontroller. Where can I find someone that I can hire to do this for me?
John
What is this switch controlling? You call it a light switch, and there is no way your serial port can operate with the voltage or power requirements of a light bulb so you do need some additional hardware.
Ben Voigt
Ben, if I can get the com port or any other port on the computer to switch, I can handle all power requirement from there. You're right though, the power requirements are 110 VAC but I plan to use another AC rated relay to handle that once the port switches from on to off. Basically, the low voltage relay will trip the AC relay. I'm controlling a door strike.
John
I'm a little puzzled because on the one hand you say you will take care of all the power circuitry but on the other hand you sound like a web developer with no experience with electronics. Anyway, you should expect the COM port to produce signals of +/- 3-18V which is suitable for controlling the gate of a FET as long as the power rails are at least +/- 18V, you can easily find a FET capable of supplying enough current for the control side of a solenoid coil. With a series resistor and some protection diodes you could operate with a small single-rail power system.
Ben Voigt
The important thing if you're going to use the COM port to control the analog circuit directly with no intermediate microcontroller is to use the control pins (generally used for flow control), since software can set them to either state and leave them there. The TX pin will only emit a short pulse and then return to the idle condition.
Ben Voigt
Ben, thanks for sticking with me on this. I actually have over 20 years experience with low voltage electronics. I do not however have any experience with building circuit boards or anything like that if that's what you are referring to. I've been developing for about 10 years now. Where I am getting hung up is how to interface the SetCommState() function with my web application code. I have a class that will return true or false and with that, I need to operate a door strike. Is this even possible?
John
Ok, just to confirm, the door strike is connected to the COM port on the web server, not the browser, correct? Unfortunately the .NET SerialPort class doesn't give you direct control over the control pins, it only lets you enable or disable handshaking, so you'll have to use the Win32 API. Use CreateFile to get a file handle to the COM port (store it in a `SafeHandleZeroOrMinusOneIsInvalid` variable) and then use `SetCommState` passing a `DCB` with `RTS_CONTROL_DISABLE`/`RTS_CONTROL_ENABLE` depending on your boolean.
Ben Voigt
Check out pinvoke.net for examples calling all kinds of different Win32 API functions from .NET, e.g. http://www.pinvoke.net/default.aspx/kernel32.createfile and http://www.pinvoke.net/default.aspx/kernel32.setcommstate
Ben Voigt
Ben, you are correct. I wanted to connect the door strike to the com port. I'm sorry but I should have mentioned that I'm not using .NET but PHP. Would you know if what I am trying to do can be done using PHP?
John
@John, why did you add c#, c, c++, and vbscript tags if you're using PHP?
bdonlan
Because I'm not sure what language has the capability of controlling the rs232 port.
John
Well I don't know much php, but I found this that may help you: http://www.communitymx.com/content/article.cfm?cid=8658A
Ben Voigt
Note that I can't vouch for the quality of that relay board, but it looks like it provides the same features as the NI one at 1/4 the price.
Ben Voigt
Ben, thanks for the link and staying with me. I'll have a look now.
John
Ben, that last link you provided was exactly what I was looking for. Thank you! I've looked for a while and never stumbled across it. Thanks again!
John
A: 

if this is not a hobby project I would advise you to buy a cheap controller instead

the reason for this is that with a controller you can offload your PC and have some of the program logic in the controller instead of in your windows program. In addition you will not need to do any serial communication but instead can connect to it via TCP/IP.

Anders K.
Anders, Can you tell me where to get one of these controllers? Which one would I need to get? Sorry, but I don't program in vb or c so I'm a little lost here.
John
For example, here is a suitable controller (this is what I was calling a digital output peripheral): http://sine.ni.com/nips/cds/view/p/lang/en/nid/202028
Ben Voigt
@John, i worked mainly with ABB's controllers but since I don't know how many ports you need etc if you instead search the web after "cheap plc i/o port controller" you should come up with a whole bunch of viable alternatives. The convenient way is to use OPC (opcfoundation.org) to connect to the PLC via for instance C# using the OPCDA (interface).
Anders K.
Thanks for this link, Ben. I'm going there now to look it over.
John
Ben, there is no price for that unit. Any idea how much it runs?
John
Anders, thanks for the search terms. I've never sone anything like this before so it's out of my league. Does it matter that my program is web based? Can I still use this method?
John
When I click on the pricing tab it says $429 (in the USA). National Instruments is somewhat of a name brand so you most likely can find something equivalent elsewhere for less, however the really price conscious way to go is more along the lines you were originally thinking.
Ben Voigt
Thanks Ben. I couldn't get a price to come up when I went there. $400+ dollars isn't really an option right now. So you think the best way to go about this is to use SetCommState instead of buying a controller?
John
A: 

Wouldn't a parallel port be easier?

Chris
Sure, I only need a set of dry contacts that will switch between an open or closed circuit. Is the parallel port easier to use?
John
A: 

Not much is involved if you use a small micro-controller module or the like. For Windows (assuming .Net) you can use the SerialPort class provided in System.IO.Ports. In most cases you use a mini ASCII protocol of your own design. i.e. Your Windows app sends single characters that are processed in the micro via a switch statement with each character interpreted as ON or OFF for a given output based on defined constants...simple. You just a device you can talk RS232 with...

There are literally hundreds of devices with the handful of I/O and serial ports you need...picking one is another question all together. You'll want to start with a development kit or a pre-built solution. Here is an incredibly short and incomplete list of options for a start...by price, lowest first..

  • For low cost Parallax is a good place for a start. One of the Basic Stamp controllers should meet your needs if you are up for some boarding...If not you might look at the Stamp PLC or one of the multiple starter/dev kits.
  • The PIC controllers from Microchip are insanely popular. CCS has a great compiler for the PIC with loads of sample code and a good selection of devkits.
  • Rabbit makes some more advanced boards that might be worth a look if WiFi, USB, Ethernet etc. are in your future.

I'd suggest starting with a Parallax product and go from there.

Rusty
Hi Rusty, thanks for the help and the links. This looks a really good start
John