by Theo Verelst

http://195.241.128.75/Bwise/parallel1.jpg

The title should have mentioned that in this case I make the software run on a windows machine, though I understand the driver isn't necessary on linux, so that should be fairly easy. I just don't have access to a linux machine with useable parallel port.

A LED (Light Emitting Diode) is one of those small, (almost?) everlasting lights, usually in red green or blue, though nowadays you can buy them in any electronics store (there are over 230 in the small country holland) in blue, yellow, and orange too, and even in white and 'high brightness' version. They used to come in 3 mm or 5 mm diameter, but you also have jumbos, rectangular and many other shapes, lately especially very tiny SMD (surface mounted device) kinds, which you can find on computer boards.

This page describes the use of a LED on a printer port, to indicate something for instance while the PC screen is turned off or in screen save mode, like wether you server is still running, or wether some process is finished. Your electronics store will be happy to sell you a led, some wire (to place it away from the printer port connector) a few resistors, and a (push button) switch, and of course the printer port parallel connector plug (male), which is fairly standard. All in all, probably less then 10 (or even 5) dollars/euros.

Yet the advantages are considerable. First however consider that connecting wires/parts to you wonderfull, expensive computer may damage it permanently when you err, and in certain ways which you may not be aware of, so be carefull, of have someone knowledgeable do the electronics work. Especially, apart from of course connecting nothing which produces electricity to the printer port, such as a mains connector.., you should be aware of static electricity sources as a possible wrecker of your computer circuits. Normally, when using standard connectors, your fingers, your wollen sweater (..) or some other ungrounded equipment will not touch the internal pins of for instance the printer connector. When you do, there is a chance of doing damage to the printer port circuitry (which isn't that expensive) or worse to the further internals of you computer. When you make sure you have grounded the computer, and preferably by touching a metal enclose of it, also yourself, the risc of touching any pin (still don't wear clothes which make you draw sparks when you touch metal) is minimal, so you can touch the led and switch without risc.

... (I'll put in some pictures and diagrams, hang on)

You'll have to install the driver file (on NT/2000/XP) from the parallel port page, and load the dll:

 load lpttcl

Assuming we have the led connected up, via its current limiting resistor, we can drive it via the tcl commands:

 set output_bit 1        # the bit line (number from lest significat = 0) you put the led on
 prt_wrctrl 0            # hopefully put the right printer port in output mode
 prt_wrdata [expr 1 << output_bit]

or

 prt_wrdata 0

instead of the expr you can also simply use 255 (all bits 1)

To read the state of our switch, we read the status byte:

 puts [prt_rdstat]

which should print a different value when you press or release the switch. The difference of the two values is the value of the bit you connected to. You can also make an 'if' with simply one of the two values as condition.

To get a continuous readout of the switch, you can do something likt this:

 entry .e -textvar e
 pack .e
 proc af {set e [pr_rdstat] ; after 100 af}
 af

when you're done:

 rename af {}

Notice that when you feed back the state of the switch to the state of the LED, you can test wether the program which is supposed to do that (for instance by a repeated after command every 10th of a second) is still running, without having the need for an active screen.