[ltp] Serial port switch
Chris. Aubrey-Smith
linux-thinkpad@linux-thinkpad.org
Wed, 12 Mar 2008 21:05:34 +0000
------=_Part_7184_32908505.1205355934319
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Of interest? Definitely. I've exploited this from DOS, but "
statserial /dev/ttyS0 "? Which distro are you using?
CAS
On 12/03/2008, Richard Neill <rn214@hermes.cam.ac.uk> wrote:
>
> Dear All,
>
> Just thought the following might be useful to someone wanting to do some
> really trivial hardware hacking. I'm using it to connect a reed-switch
> to an old ThinkPad, to make a networked burglar alarm.
>
> The old-fashioned Serial port (or a USB-serial adaptor) has a couple of
> status lines which are really easy to monitor and interface with. It's
> also reasonable electrically "tough", being designed to work with large
> voltage-swings, and long cables.
>
> statserial /dev/ttyS0 gives the following listing, for a
> non-connected port:
>
> -------------------
> Device: /dev/ttyS0
>
> Signal Pin Pin Direction Status Full
> Name (25) (9) (computer) Name
> ----- --- --- --------- ------ -----
> FG 1 - - - Frame Ground
> TxD 2 3 out - Transmit Data
> RxD 3 2 in - Receive Data
> RTS 4 7 out 1 Request To Send
> CTS 5 8 in 0 Clear To Send
> DSR 6 6 in 0 Data Set Ready
> GND 7 5 - - Signal Ground
> DCD 8 1 in 0 Data Carrier Detect
> DTR 20 4 out 1 Data Terminal Ready
> RI 22 9 in 0 Ring Indicator
> --------------------
>
>
> Normal data flows through the TxD and RxD lines, which we don't use
> here. However, the status lines are essentially logic levels(*).
>
> So, if we connect a switch between pin 4 (RTS,out,logic 1), and pin 9
> (RI,in,floats at 0), then we can very easily read the state of the
> switch. The circuit really is this simple:
>
> [. .]
> [. 9] -----------------------O--/ O----|
> [. .] |
> [. 4] ---------------------------------|
> [. .]
>
> Female switch
> DB9 connector
>
> When the switch is closed, RI == 1; when it is open, RI == 0.
>
> This makes it really easy to hook up a switch to a laptop, and monitor
> all sorts of things. I'm using it to monitor something else, with a reed
> switch, and a piece of thread connected to the magnet.
>
> In practice, we have up to 4 inputs and 1 outputs available, as well as
> a small amount of unregulated power.
>
> [For more advanced or faster I/O, try the parallel port, or an
> FTDI-USB245M USB device, which is about $15]
>
> Scripting statserial is a bit of a pain, since it sends ANSI-escape
> characters to the terminal. Here's a kludge that works, and prints
> either 0 or 1.
> statserial -n /dev/ttyS0 | cat -vT | \
> grep "Ring Indicator" | cut -b 29
>
>
> Hope this is of interest.
>
> Richard
>
>
> (*)Serial ports use reverse logic: 1 = negative, 0 = positive. Also, the
> voltage swing can be anything in the range +/-5V to +/- 30V.
>
> --
> The linux-thinkpad mailing list home page is at:
> http://mailman.linux-thinkpad.org/mailman/listinfo/linux-thinkpad
>
------=_Part_7184_32908505.1205355934319
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Of interest? Definitely. I've exploited this from DOS, but " statserial /dev/ttyS0 "? Which distro are you using?<br><br>CAS<br><br><div><span class="gmail_quote">On 12/03/2008, <b class="gmail_sendername">Richard Neill</b> <<a href="mailto:rn214@hermes.cam.ac.uk">rn214@hermes.cam.ac.uk</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Dear All,<br> <br> Just thought the following might be useful to someone wanting to do some<br> really trivial hardware hacking. I'm using it to connect a reed-switch<br> to an old ThinkPad, to make a networked burglar alarm.<br>
<br> The old-fashioned Serial port (or a USB-serial adaptor) has a couple of<br> status lines which are really easy to monitor and interface with. It's<br> also reasonable electrically "tough", being designed to work with large<br>
voltage-swings, and long cables.<br> <br> statserial /dev/ttyS0 gives the following listing, for a<br> non-connected port:<br> <br> -------------------<br> Device: /dev/ttyS0<br> <br> Signal Pin Pin Direction Status Full<br>
Name (25) (9) (computer) Name<br> ----- --- --- --------- ------ -----<br> FG 1 - - - Frame Ground<br> TxD 2 3 out - Transmit Data<br> RxD 3 2 in - Receive Data<br>
RTS 4 7 out 1 Request To Send<br> CTS 5 8 in 0 Clear To Send<br> DSR 6 6 in 0 Data Set Ready<br> GND 7 5 - - Signal Ground<br>
DCD 8 1 in 0 Data Carrier Detect<br> DTR 20 4 out 1 Data Terminal Ready<br> RI 22 9 in 0 Ring Indicator<br> --------------------<br> <br> <br> Normal data flows through the TxD and RxD lines, which we don't use<br>
here. However, the status lines are essentially logic levels(*).<br> <br> So, if we connect a switch between pin 4 (RTS,out,logic 1), and pin 9<br> (RI,in,floats at 0), then we can very easily read the state of the<br> switch. The circuit really is this simple:<br>
<br> [. .]<br> [. 9] -----------------------O--/ O----|<br> [. .] |<br> [. 4] ---------------------------------|<br> [. .]<br> <br> Female switch<br> DB9 connector<br>
<br> When the switch is closed, RI == 1; when it is open, RI == 0.<br> <br> This makes it really easy to hook up a switch to a laptop, and monitor<br> all sorts of things. I'm using it to monitor something else, with a reed<br>
switch, and a piece of thread connected to the magnet.<br> <br> In practice, we have up to 4 inputs and 1 outputs available, as well as<br> a small amount of unregulated power.<br> <br> [For more advanced or faster I/O, try the parallel port, or an<br>
FTDI-USB245M USB device, which is about $15]<br> <br> Scripting statserial is a bit of a pain, since it sends ANSI-escape<br> characters to the terminal. Here's a kludge that works, and prints<br> either 0 or 1.<br>
statserial -n /dev/ttyS0 | cat -vT | \<br> grep "Ring Indicator" | cut -b 29<br> <br> <br> Hope this is of interest.<br> <br> Richard<br> <br> <br> (*)Serial ports use reverse logic: 1 = negative, 0 = positive. Also, the<br>
voltage swing can be anything in the range +/-5V to +/- 30V.<br> <br>--<br> The linux-thinkpad mailing list home page is at:<br> <a href="http://mailman.linux-thinkpad.org/mailman/listinfo/linux-thinkpad">http://mailman.linux-thinkpad.org/mailman/listinfo/linux-thinkpad</a><br>
</blockquote></div><br>
------=_Part_7184_32908505.1205355934319--