Serial Port Setup

Kevin Brown plug-discuss@lists.PLUG.phoenix.az.us
Wed, 21 Nov 2001 16:02:22 -0700


> > > I am trying to set up a serial port to
> > > read data from a weather station.  I
> > > have some C code that will set up the
> > > allow the port to listen, but I can't
> > > find any information on how to get
> > > the code "into" dev/ttyS0 or ttyS1.
> > > Do I compile it into that directory
> > > with the name ttyS1 and replace it,
> > > or something else?
> >
> > Well, first off, you have to realize that all of the files in the /dev
> > directory correspond directly to each device installed in your system. If
> > you want to send data to a device, you have to open() it like a file, and
> > write() to it. The same procedure goes for reading: open() it and then
> > read() from it.
> >
> > What do you mean "get the code 'into' dev/ttyS0 or ttyS1"? Do you mean
> > upload the actual program into the device?
> 
> Sorry for the vague language.  I understand that the
> serial port interface is a file (ttyS0, etc.), and I
> know which device I'm dealing with (ttyS1).  What
> I don't get is how to change the serial interface
> to a driver for a particular device, in this case a
> weather station.
> 
> I have the code that interfaces with the port, but I
> don't know what file to compile into.  Does it get
> compiled into a file with name 'ttyS1', replacing
> the existing 'ttyS1'?  Again, sorry for the clumsy
> language, this is new territory for me.

Your code will be compiled into an executable, the name of it doesn't really
matter just put it in a place like /usr/bin.  Inside your code you have it
perform an open operation on the /dev/ttys0 or s1 file to perform reads and
writes to it.  Those reads and writes get transmitted to the device on that
serial port.