From: Kautzmann Gerd ([email protected])
Date: Fri Apr 05 2002 - 11:17:02 CEST
>
> Wouldn't a very good way to learn serial port programming be
> to "use the force--view the source" and merely download and
> examine the source code to one or a few of the various serial
> terminal packages available for linux?
> I mean why not use the open source standard to ones advantage
> when attempting to reconfigure the wheel for a special purpose?
>
> >Reply-To: [email protected]
> >Date: Wed, 27 Mar 2002 15:31:11 +0100
> > Michele Andreoli <[email protected]> [email protected] Re: RS232
> >On Wed, Mar 27, 2002 at 02:46:27PM +0100, Kautzmann Gerd wrote:
> >
> >> Are there any resources or programms that could show me
> how to programm for
> >> a RS232 Interface ( not programming a driver, just using a
> driver ) in 'C'
> >> under (mu) LINUX ?
> >
> >
> >The subject is covered in the howto called SerialProgramming
> or PortIOProgramming.
> >
> >Anyway, to exchange characters via serial port in Linux is very
> >simple to do.
> >
> >Method 1)
> >-----------
> >
> >It is only matter to open the special device /dev/ttyS0 (COM1)
> >or /dev/ttyS1 (COM2):
> >
> > int fd;
> > fd = open("/dev/ttyS0",O_RDWR)
> >
> >Only to program the parallel port is more easy that that
> >
> >
> >You can explore the blocking and not-blocking IO with the
> parametri O_BLOCK, or
> >similar.
> >The was a lot of ioctl() able to set parity, echo features, etc.
> >
> >After that, you read character with read(fd, buffer, n) and
> write with
> >write(fd,buffer,n).
> >
> >In the mulinux.tgz there is a sources/ directory. You can explore the
> >file miterm.c, a standalone application able to talk with modems.
> >I think, a good starting point.
> >
> >Method 2)
> >-------------
> >
> >As alternative, you can load the PERL addon and use perl. Very easy
> >to use.
> >
> >Open the serial line:
> >
> > sysopen(fd,"/dev/ttyS0",2);ù
> >
> >After that, you can write with:
> >
> > syswrite(fd,string,length_len);
> >
> >and read with:
> >
> > sysread(fd, string, n)
> >
> >
> >Both methods do not requires special libraries or special
> include files,
> >so the muLinux environment suffices.
I think this will be good enough for programming the serial device.
I never saw a programm with so much parameters like 'setserial' I
believe one of the settings could be the right one.
> >Method 3)
> >-----------
> >
> >A further method, that skip the kernel driver, is to face
> directly with
> >IO ports, memory mapped. This is specially useful for
> parallel port, because
> >doesn't requires synchonization:
> >
> > #include <stdio.h>
> > #include <unistd.h>
> > #include <asm/io.h>
> >
> >As first stage you must gain privilegs with
> > iopl(3);
> >
> >After that, you can read a byte from the port with
> > port=0x378 ( parallel port)
> > c=inb(port)
> >
> >and write a byte with:
> >
> > outb(byte,port);
> >
> >Method 4)
> >------------
> >You can access the IO port using the /dev/port special
> device. It is a kernel
> >facility. If you read the n-th byte in this special file,
> you are really
> >reading the n-th cell in the IO memory mapped area.
> >You can get a byte using the muLinux "poke" command.
> >Example: poke /dev/port 10 read the byte 10.
> >
> >
> >
> >I hope this useful for you.
This will be usefull too .... setting the paralell port is still
the easiest nway to get some digital I/Os for controlling.
thank you Gerd
> >Michele
> >
> >--
> >I keep trying to locate a meeting of Quantum Physicists. But
> >everytime they set a meeting time, the location changes. And
> >vice versa -- Anonymous
nice signature ....
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
This archive was generated by hypermail 2.1.6 : Sat Feb 08 2003 - 15:27:21 CET