1

I am trying to make a very simple BUTTON (simple wire RED/YELLOW only). Now if the Button is pressed (RED touch YELLOW) i want to receive input signal in my Java application (that button was pressed).

In which ports of RS233(DB9) i should patch the RED/YELLOW wire? So that any button pressed i get in my application input signals?

Thanks

YumYumYum
  • 139
  • 1
  • 10
  • I don't understand, perhaps you have some misspelled words, but I'm not sure about that either. – kenny Sep 15 '11 at 22:31
  • @kenny: s/READ/RED – YumYumYum Sep 15 '11 at 22:36
  • @Dean: Java source i have no issue. But my problem is in the RS323 connected to DB9 which is 9 pins. Which of the 9 pins should be connected with RED/YELLOW? So that when R and Y touch it send signal? – YumYumYum Sep 15 '11 at 22:37
  • @Dean - "have you tried googling" is an awful comment. Especially for RS-232 where the connectors are not part of any spec. – DanBeale Sep 17 '11 at 15:28
  • @Dean, RTFM and google it please answers are not acceptable. The goal of Stack exchange is to be the result when someone does google it. – Kortuk Sep 19 '11 at 19:58

3 Answers3

4

You could link the TX and RX pins through the button, then have your software "poll" the button state by sending a character out of the serial port and seeing if it gets that character returned to it through the serial port.

Majenko
  • 55,955
  • 9
  • 105
  • 187
  • In that case i do not need to use RS-485? e.g: http://www.usconverters.com/ – YumYumYum Sep 15 '11 at 22:55
  • 2
    @89899.3K, most of what you are asking is software. How to check if the wire is connected could be polling it on a scheduled interval. The RS-485, I have no idea why you would bring that up when the question does not mention it and the answer also did not. The case that RS-232 is a communication protocol and not a input monitoring protocol is another one. have you looked into GPIO? That stands for general purpose input/output. I have seen programmers use GPIO for simple digital input and output, which a switch would be. – Kortuk Sep 16 '11 at 02:01
2

If you connect one side to RTS (pin 4) via a large resistance (e.g. 47k or 100k) and to RX (pin 3), and the other side to +9V, you'd probably get a "break" signal when the button is pressed, which can be detected in software.

Unfortunately, there's no pin on the RS-232 connector which normally has a valid positive RS-232 voltage. You could use software to send a break condition, and use TX (pin 2) for the second terminal of the button.

Ben Voigt
  • 2,743
  • 1
  • 22
  • 34
  • You mean i should use RS-485 and connect those wire there? e.g: buy those? http://www.usconverters.com/ – YumYumYum Sep 15 '11 at 22:53
  • 1
    @89899.3K: No, I don't see how RS-485 would help. Then you'd need to switch two lines at once, which would be harder. – Ben Voigt Sep 15 '11 at 23:10
2

At best this is going to be a kludge. RS-232 is for serial communication, not for digital input lines. However, if you want a single input line that can be read by the software then the modem line intended to tell the computer there is a incoming call could work. Depending on what access your software has to the serial port, is should be able to read that line. There are also lines for ring detect and a general ready line. I vaguely remember names of some of these lines are DSR, DCD. A detailed RS-232 reference should be easy to find out there.

Not all low level drivers make all lines available to the software. Wanting this in Java may add another compilcation since not only does the operating system have to allow app access to these lines, the JVM then has to let them thru to the Java app.

If you want to sense a button press, use a mouse or other input device intended for the purpose.

Added:

As I said, trying to detect a single voltage change with RS-232 is a kludge. What I neglected to mention is a simple way to do it within the RS-232 spec so the normal software interface will do what you want.

The simplest way is for a small microcontroller to detect the button closure and then emit a character to the serial port. This has the added benefit of allowing the micro to perform debouncing, which is something you should think about. If this is a one-off then get a small micro with a UART. Otherwise, you can use the smallest possible micro to clock out the character in firmare. This is really not hard, especially if you make the baud rate low enough. I once sent 9600 baud from a PIC 16 running from a 160 kHz crystal. You can easily do this with a PIC 10F200 running from its internal 4 MHz oscillator.

One problem is that the micro will be running at logic levels, whereas RS-232 requires the input signal to swing at least from -5V to +5V, preferably a bit more. The completely right way is to add a RS-232 interface chip like a MAX232 or similar. However, many PC COM ports work with only 0 to +5 input voltage swing. In that case, the micro can drive the PC's receive line directly. Keep in mind that in this configuration, the signal needs to be inverted from what normal micro UARTs put out. Line idle must be low, whereas the built-in UART will produce line idle high.

Olin Lathrop
  • 310,974
  • 36
  • 428
  • 915
  • "If you want to sense a button press" - Yes that is exactly i am trying to do. Can i use this RS-485 then? e.g: http://www.usconverters.com/index.php?main_page=product_info&cPath=75&products_id=233 – YumYumYum Sep 15 '11 at 23:40
  • @89899.3K, RS-485 is a more advanced communication protocol then 232, it is not going to be any better at reading the short of two conductors. Have you thought about using something like a microcontroller to monitor the switch and then send information over USB/RS232/RS485/Ethernet/wifi/SATA? – Kortuk Sep 16 '11 at 02:03
  • @Kortuk: yes i used Crestron/Extron for that. But want to retire on those they are expensive + again other requires involved. So i am expecting to do it with RAW rs232 or rs485 – YumYumYum Sep 16 '11 at 09:07