From: Tom Walsh (tom@cyberiansoftware.com)
Date: Sat Sep 22 2001 - 02:05:33 EDT
li_jia99@mails.tsinghua.edu.cn wrote:
>
> I set the termois.c_lflag=0 and don't change anything in c_cc[].
> and now ucsimm can receive date by serial port:)
>
> but the pc receive some date during runing my program such as
> "/sbin/agetty ""successfully"
> even the whole file of /etc/issue
> why does this information accur?
>
I am not sure what it is that you are asking... But, let me assume that
you are unfamiliar with programming the serial options under linux, I am
also not too familiar with this topic! This is a function that I use to
open serial ports, and configure them to do what I want. Look closely
and you will see that I use a memset() call to clear the memory of the
termios structure, I don't assume that the memory has been initialized.
This is just the way I work, I never assume anything...
This function opens the serial device as: 2400,n,8,1 in RAW mode (no
processing of ^C, LF, BREAK, etc).
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <limits.h>
#include "timeclock.h"
extern char * SerialPortName;
static struct termios SerialOptions, OldSerialOptions;
static FILE * SerialPort;
static int SerialPortNo;
static char Line [MAXLINE+1];
static int LineIdx = 0;
int OpenSerialPort (void)
{
if ((SerialPort = fopen (SerialPortName, "r+")) == NULL) {
fprintf (stderr, "Failed to open %s\n", SerialPortName);
return 0;
}
SerialPortNo = fileno (SerialPort);
tcgetattr (SerialPortNo, &OldSerialOptions);
tcgetattr (SerialPortNo, &SerialOptions);
memset (&SerialOptions, 0, sizeof (SerialOptions));
/* set to 8n1 */
SerialOptions.c_cflag |= (CS8 | CREAD | CLOCAL);
SerialOptions.c_iflag |= (IGNPAR | IGNBRK | IGNCR);
SerialOptions.c_oflag = 0;
/* set baudrate. */
SerialOptions.c_ispeed = B2400;
SerialOptions.c_ospeed = B2400;
cfsetispeed (&SerialOptions, B2400);
cfsetospeed (&SerialOptions, B2400);
/* turn off CANONICAL mode */
SerialOptions.c_lflag = 0;
/* access single char at a time */
SerialOptions.c_cc[VTIME] = 0;
SerialOptions.c_cc[VMIN] = 0;
tcsetattr (SerialPortNo, TCSANOW, &SerialOptions);
/* set the queue variables. */
LineIdx = 0;
return 1;
}
I hope this helps. BTW, the documentation on how to use the serial
ports is badly out of date and does not provide much help in the way of
examples. But... If you have done programming of the serial ports
under something like MSDOS, then you just have to imagine the changing
of the I/O registers of the UART that you did under MSDOS is going to be
done by the tcsetattr() call. Just keep in mind that you have to pass
all those serial options in the termios structure.
TomW
--
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net, http://cyberiansoftware.com
"Windows? No thanks, I have work to do..."
----------------------------------------------------
This message resent by the uclinux-dev@uclinux.org list server http://www.uClinux.org/
This archive was generated by hypermail 2.1.4 : Thu Sep 19 2002 - 13:20:13 EDT