Check for status of Serial ports in any language?
Is there any way to do something like the folowing in ANY language?
if 'pin 1 and pin 2' are connected: do command elif 'pin 1 and pin 3' are connected: do other command etc. The reason is I have a box with 4 buttons connected to a serial port that I used to controll winamp when I was running XP before I made my remote. It would be usefull to have buttons that could flick through windows in ratpoison or something like that. |
http://www.tldp.org/HOWTO/Coffee-3.html
http://www.tldp.org/HOWTO/Coffee-2.html those will probably give you some idea on this. |
Reading/writing pins directly
Is there some electronic circuit on you 4-button-device that makes it
talk the RS232 protocol? If not, then I suppose you are trying to read the status of 4 pins on the serialport directly. As far as I know there are only 2 pins on the serial port you can write to directly (RTS & DTR), and only 2 other pins you can read directly (DSR & CTS). For reading, there may be 3; If the DCD-pin also works. Not sure about this. So reading 4 may not be possible without RS232 circuitry on your 4-button-device. I recently got into this because I wanted to do the opposite (writing directly to some pins on the serial post): I wanted to switch 3 LED's independently through software without an external power supply. USB is obviously the best way to do this, but it involves too much electronics for my purpose; I was looking for a solution as cheap as possible. (If somebody has some info about how to do this with USB, I would be very interested though, especially a electronic diagram...) Anyways, I managed to switch on only 2 LED's through the serial port using the experimental program below. It needs only little changes to read the DSR and CTS lines. Code:
#include <stdio.h> man termios IO-port programming mini-HOWTO Serial programming HOWTO man ioctl man ioctl_list http://www.easysw.com/~mike/serial/serial.html (recommended) If you manage to read (or better for me: write) to/from more than 2 pins directly, I would appreciate it very much if you tell me by posting here or by e-mail: heiky_at_freeshell.org TIA and good luck. |
hko: how about using the parallel port, in basic output mode it has has 5 input pins(10-13, 15) and 8 output pins(2-9) which can be read/wriiten by two 8 bit registers(forgotten io address but you can get it from cat /proc/ioports) i doubt the parallel port driver lets you set/get these registers directly but if it doesnt you can write a kernel module and call inportb() and outportb() as necessary.
|
kev82: Thanks for thinking along with me. But I want to use the serial port because I want no external power supply and because people tend to have the serial port unused, while often having a printer attached to the parallel port.
It is impossible, or at least difficult and "dangerous", to drive LED's from the parallel port without an external power supply. The serial port can supply more current than the parallel port. Also, when you take too much current from the parallel port it easily breaks! This would leave me with a broken IO-card, or worse, a broken motherboard when the parallel port is integrated with the motherboard. |
No, there's no circutry, pressing the buttons simply shorts two of the pins. I'll post a circuit diagram in a moment, showing which buttons are connected to which pins.
I know it's possible because there's a winamp plugin called ComCtrl that works with the drvice I have. I may write to the author of it asking for the source. _____________ S | | | | E \ \ \ \ R __ | | | | I _____ | | | A ________ | | L ___________ | This is the circuit diagram, I don't have the names of the pins that they are connected to yet. Anyway, thanks for a very comprehensive reply Hko!! |
I found the circuit diagram by googling for "ComCtrl" at:
http://diba.hotbox.ru/comctrl/tutorial1/index.html and at: http://www.mattsclearpcs.com/com/com.html I looked at it, and it's indeed possible to read 4 pins like this. I figured out the names of the pin-names thanks to de doc I recommended. It does not help me to switch more than 2 LED's however :-( I'm still convinced that's not possible without additional circuitry and/or external power-supply. By using parts of my code and change it, it's not too difficult to read the 4 pins independently in Linux. If you need more help, just say so, and I'll make a basic program for this. I think I'm going to make the thing myself as well. (don't know when). Thanks too you as well. |
I'm going to try and create the program myself as an exercise, I'm just starting to learn how to program and there's nothing better to aid learning than a good project.
However I would like it if you could PM me the code when you're done for comparison. I have a tendancy to do things very inneficiently at the moment as I am a very poor programer. Thanks |
OK.
("PM" means Private Message, I suppose?) |
Yep
|
Its' finished. I've made a program that handles the 4 buttons. It does not do anything useful (yet). It just prints what happens when the buttons are pressed and released.
You can get it here: http://www.xs4all.nl/~heiky/ |
Downloading source now, I'm off to college then I'll try it out later.
Cheers. |
All times are GMT -5. The time now is 10:35 PM. |