[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&#39;ve exploited this from DOS, but &quot; statserial&nbsp;&nbsp;/dev/ttyS0 &quot;? 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> &lt;<a href="mailto:rn214@hermes.cam.ac.uk">rn214@hermes.cam.ac.uk</a>&gt; 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&#39;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&#39;s<br> also reasonable electrically &quot;tough&quot;, being designed to work with large<br>
 voltage-swings, and long cables.<br> <br> statserial&nbsp;&nbsp;/dev/ttyS0&nbsp;&nbsp;&nbsp;&nbsp;gives the following listing, for a<br> non-connected port:<br> <br> -------------------<br> Device: /dev/ttyS0<br> <br> Signal&nbsp;&nbsp;Pin&nbsp;&n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<br> <br> <br> Normal data flows through the TxD and RxD lines, which we don&#39;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.&nbsp;&nbsp;The circuit really is this simple:<br>
 <br>&nbsp;&nbsp; [. .]<br>&nbsp;&nbsp; [. 9] -----------------------O--/ O----|<br>&nbsp;&nbsp; [. .]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|<br>&nbsp;&nbsp; [. 4] ---------------------------------|<br>&nbsp;&nbsp; [. .]<br> <br>&nbsp;&nbsp; Female&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch<br>&nbsp;&nbsp; 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&#39;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.&nbsp;&nbsp;Here&#39;s a kludge that works, and prints<br> either 0 or 1.<br>
&nbsp;&nbsp;statserial -n /dev/ttyS0&nbsp;&nbsp;| cat -vT | \<br>&nbsp;&nbsp;grep &quot;Ring Indicator&quot; | 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&nbsp;&nbsp;to&nbsp;&nbsp;+/- 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--