[TriLUG] C linux programming question

Ed Hill ed at eh3.com
Sat May 24 11:29:16 EDT 2003


On Fri, 2003-05-23 at 18:57, Greg Brown wrote:
> Hey all.  Is it possible, using C, to monitor voltage on one pin of a 
> serial port when voltage is supplied from an outside source or do I 
> have to knuckle under and learn some assembly for this task? 


Hi Greg,

Yes.  But according to the RS-232 standard you can only monitor in the
sense of a binary "high" or "low" as defined by:

  +3 -- +12 VDC is "high"
  < +3 -- > -3 VDC is *undefined* (!!!)
  -3 -- -12 VDC is "low"

and anything outside the interval [-12,+12] or [-15,+15] (depending upon
the individual hardware) is out of range and risks damage.  And note
that many implementations lump the "undefined region" into the "low"
range so that may do what you want.


>  What I'm 
> after here is with an embedded linux machine mounted in a car and I 
> want to have power supplied by an always-on supply in the car.  I'd 
> also like to have a pin on a serial port connected to a "only on when 
> running" wire (somehow).  So when the voltage drops to zero on the 
> "only on when running" pin the embedded device will shut itself down 
> automatically (the device would be turned on manually via an "on" 
> button).

Well, car voltages (+12 or -12 VDC) are perfect.  And you may want to
use a relay with some extra wiring so that the device gets +12 in the
"high" and -12 in the "low" state.  Otherwise, you're fine.


> Is this theoretically possible using C?

Absolutely, see the attached which is C++ but could just as easily be
C.  And good pin-layout diagrams are available at:  

  http://www.connectworld.net/rs232.html

and numerous other places on the web.

Good luck!

Ed


-- 
Edward H. Hill III, PhD 
Post-Doctoral Researcher
Division of ESE, Colorado School of Mines, Golden, CO 80401
Email: ed at eh3.com  ehill at mines.edu
Phone: 303-273-3483
URLs:  http://cesep.mines.edu/people/hill.htm  http://eh3.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_dtr2.cpp
Type: text/x-c++
Size: 1530 bytes
Desc: not available
URL: <http://www.trilug.org/pipermail/trilug/attachments/20030524/e118c3ab/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://www.trilug.org/pipermail/trilug/attachments/20030524/e118c3ab/attachment.pgp>


More information about the TriLUG mailing list