Can anyone point me in the right direction as to what is all involved in developing an interface that will use the COM p开发者_StackOverflowort 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.
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.
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.
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.
You probably just need to build something like this:
Relay Circuit
Then you just toggle DTR or RTS (whichever you hook it to on the comm port) to activate the relay. That's just one design example. There are others, but that's actually pretty simple...
精彩评论