Re: RS232

From: ZooT aLLures ([email protected])
Date: Wed Apr 03 2002 - 10:09:03 CEST


('binary' encoding is not supported, stored as-is) 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.
>
>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.
>
>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
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [email protected]
>For additional commands, e-mail: [email protected]

------------------------------------------------------------
Visit the world's greatest site at http://www.farts.com and listen to the fart
of the day. Also, get your very own farts.com E-mail account. FREE!!!!!

---------------------------------------------------------------------
Express yourself with a super cool email address from BigMailBox.com.
Hundreds of choices. It's free!
http://www.bigmailbox.com
---------------------------------------------------------------------

---------------------------------------------------------------------
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