Simple PC Serial Port Help

Please point me toward any applicable FAQs or other groups if I am breaking protocol or in the wrong place, thanks. :)

That said, I am trying to find some information on building a very simple circuit that combines a momentary contact switch and my PC's serial port. I have a very basic understanding of electronics, generally speaking, but I am definitely a "software guy." ;) Once connected, I'd like to be able to open the serial port and query (or receive) the current state of the switch. The rest of my project can be handled in software (for now) so I'd like to keep everything on the hardware side as simple as possible.

Googling, I find a good number of circuits involving using the PC serial port to control the state of LEDs/relays/etc. but not much in the way of simple receiving of data. I'm not opposed to using the parallel port, I'd just prefer to use serial for this project, unless there is a significant advantage (lower cost, simpler design). I'm also not against using a USB port, but I am assuming that involves more complexity on the hardware side as well as the software side.

Anyway, thanks for any links or information you can provide. I'd be glad to provide the final design and example C code for my project when I get it going, if that is useful to anyone. :)

oz

Reply to
ozraven
Loading thread data ...

Hi, Oz. The serial port is the easiest place to accomplish your task, and s.e.b. is the right place to ask (There are no questions too simple or basic for s.e.b. -- just no homework problems unless you've at least made a good effort, please ;-)

Having said that, your best bet would be to use a SPDT switch, with the common going to one of the inputs (like RxD), and the N.O. and N.C. contacts going to two outputs (say, TxD and CTS). Make one output high and the other low. Then, when you switch, the logic state at the input will change. Try to use a switch rated for dry contact (

Reply to
Chris

Build a loopback tester with the switch in the loop. If you transmit some data, and you receive the same data back, your switch is closed.

formatting link

HTH

Reply to
Randy Day

put the switch between the DTR and DSR pins... you should be able to tell the state of the switch by turning DTR on and reading DSR.

in linux you open the port and use an IOCTL, to get the DSR state, in DOS it's a BIOS call, or you can just read the io port, dunno about windows.

--
Bye.
   Jasen
 Click to see the full signature
Reply to
jasen

In addition to all the good info from the other responses, one general source of port info is Lakeview Research at

formatting link

I personally have always preferred the parallel port, but that is no longer easy to use on any system later than Win9x, without a special Ring 0 driver. I expect that even the serial port's days are numbered as well. Ahh, progress!!!!

Best regards,

Bob Masta dqatechATdaqartaDOTcom D A Q A R T A Data AcQuisition And Real-Time Analysis

formatting link
Home of DaqGen, the FREEWARE signal generator

Reply to
Bob Masta

Forgot to provide the link:

formatting link

"Serial Port Complete" by Jan Axelson of LVR is a great resource on hacking the serial port. It has a CD which includes numerous programming examples in many languages, as well as the Windows files you'll need. You can purchase the book from the website or many hobbyist resources such as Jameco. It's also available at many libraries.

Good luck Chris

Reply to
Chris

...

...

I'd do almost this, except I wouldn't use TxD and RxD - they go through the UART and are expected to be a serial data stream, with start bits and all that.

Just use, lessee...

formatting link

So, you'd use your control register to output, say, a high on DTR, and a low on RTS, and come in on your choice of DSR or CTS:

Then, you just poll the status byte when you want to check the switch.

(on that webpage, the computer's on the left, so you really should look at a mirror image of the ASCII art above.)

Have Fun! Rich

Reply to
Rich Grise

Yup. Sorry, Rich -- I first did this more than a quarter century ago with a footswitch on a tank Kaypro II with Z80 assembler -- I forgot the details. Ah, the joys of that monster 9" green screen!

formatting link

You're right, the OP should use control signals, they're immediately addressable from most UARTs including the PC. As I remember, I'd also have occasional problems with resistive switch contacts. Much better to just assert a "1" on one output control bit, and a "0" on the other, and use a SPDT switch to signal.

Cheers Chris

Reply to
Chris

schreef in bericht news: snipped-for-privacy@m73g2000cwd.googlegroups.com...

You need some basic understanding of the serial port. All you need for that you can find in

formatting link
chapters on RS-232 interfacing. You need to know which (two) lines are meant to transmit and receive data and what modem controll- and sense lines you have available. The original use of the latter lines is not important, but you must distingguish inputs from outputs.

Next, you did not tell what OS you're using. In plain old DOS, you can access the UART directly. In W95, W98 and WME you can do so as well. For WNT, W2000 and WXP you'd better find a driver or use a language that supports serial data communication. For Linux, you need to handle the TTY controls. Some others told you already how you can connect the switch. Beware! An open input line has no defined logical value so make sure it is connected to either a high- or a low output line.

Now you need to decide what you really want to achive. So do you want to look at the switch after asking the user a question or do you decide for yourself when you want to read out the switch or do you want to catch every change the switch makes? The first two cases are simple. You poll whenever you need to. I'd go for the single pole, single throw switch that can (dis)connect TxD and RxD. Send a byte, for instance 0x55, and check whether the byte has been received or not. If you want to catch every change, you need to poll continuously or use an interrupt. I'd go for the interrupt, but being a programmer, you will know what to do.

petrus bitbyter

Reply to
petrus bitbyter

For the serial port, connect the tx to the rx thru the switch. Then send some bytes and if the switch is closed, the bytes will be received. For the parallel port, below is a simple setup.

formatting link

Reply to
Si Ballenger

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.